generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to have additional organisations
This creates a `has_and_belongs_to_many` join table relationship between organisations and users, allowing a user to belong to `additional_organisations` and paves the way to allowing a user to set their `organisation` to be a `Current.user_organisation` and thus view data for that organisation instead of their own "real" organisation. This should change nothing about the existing functionality of the site and will be entirely invisible to end users. (The next phase will include front-end changes which *will* allow selected users to switch their current organisation.) Helper methods on the `User` model to navigate this relationship include `primary_organisation` (to retrieve the user's actual `organisation`, which is necessarily overwritten), `all_organisations` (the union of `primary_organisation` and `additional_organisations`) and `additional_organisations?` (to determine whether a user has a non-zero number of `additional_organisations`).
- Loading branch information
1 parent
2697408
commit a8fc68f
Showing
7 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Current < ActiveSupport::CurrentAttributes | ||
attribute :user_organisation | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
db/migrate/20241204220209_create_join_table_organisations_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CreateJoinTableOrganisationsUsers < ActiveRecord::Migration[6.1] | ||
def change | ||
create_join_table :organisations, :users, column_options: {type: :uuid} do |t| | ||
t.index [:organisation_id, :user_id] | ||
t.index [:user_id, :organisation_id] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
doc/architecture/decisions/0038-users-may-belong-to-multiple-organisations.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 38. Users may belong to multiple organisations | ||
|
||
Date: 2024-12-05 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
Some RODA users wish to have the ability to view reports, activities, etc from | ||
other organisations. Currently these users have to have their organisation | ||
changed for them so that they can do this, which requires manual intervention | ||
by an administrator. | ||
|
||
## Decision | ||
|
||
Much of the logic in RODA is predicated on the idea that one user belongs to | ||
one organisation; changing the relationship to one where a user has many | ||
organisations would require a very large engineering effort. | ||
|
||
We believe the easiest way to allow a RODA user belonging to one organisation | ||
to be able to view data belonging to other organisations is to to maintain | ||
its existing relationship where it belongs to one organisation, but to add | ||
an additional relationship where a user has and belongs to many organisations, | ||
which we are calling "additional organisations". This way, all the existing | ||
logic and tests still work, but we can augment the functionality to allow a | ||
user to switch their current organisation to be a different one from an | ||
"additional organisations" list (the contents of which would be set by an | ||
administrator for a given user). | ||
|
||
## Consequences | ||
|
||
It will be easier for users who need to see data from other organisations to be | ||
able to do this without requiring manual intervention. | ||
|
||
The relationship between a user and its organisation is critical functionality | ||
and so we must tread carefully. Our proposed solution does not require any | ||
changes to the existing policy logic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters