Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically update user permission groups to users when they are added as managers to orgs/facilities #425

Conversation

christophmeissner
Copy link
Contributor

Configuration

The names of the groups can be configured in the django settings module:

  • FACILITY_MANAGER_GROUPNAME for managing facilities (defaults to "Facility Manager")
  • ORGANIZATION_MANAGER_GROUPNAME for managing organizations (defaults to "Organization Manager")

Auto group assignment

Whenever a user becomes a manager (or admin) of a organization, they are now added to the organization manager permission group "Organization Manager" (when it exists in the DB). When the user is removed as manager (or admin) of an organization, and they are no longer an manager (or admin) of any other org, they are removed from the organization manager group.

Likewise, when a becomes a manager (or admin) of a facility, they are now added to the facility manager permission group "Facility Manager" (when it exists in the DB). When the user is removed as manager (or admin) of an facility, and they are no longer an manager (or admin) of any other facility, they are removed from the facility manager group.

Note: when a user becomes a manager of a organization or facility, they are assigned the is_staff user attribute to grant them access to django admin. However, when a user is removed from any of beforementioned groups, is_staff won't be changed, since it can not be known, if the user is granted this attribute because of any other reason.

When the respective groups do not exist, nothing is done (is_staff won't be changed, too).

Migration

  • A default set of 2 djago permission groups are created in a data migration: "Facility Manager" and "Organization Manager".
  • is_staff is not changed during the migration, this remains a manual step.

Memberships should not be allowed to have their user_account swapped. Delete the membership and create anotherone instead.
When manager groups don't exist, the signal does not fail in an exception, but propagates an error insted and skips assigning manager groups.
@pitpalme pitpalme merged commit 98372b8 into coders4help:develop Mar 13, 2022
@christophmeissner christophmeissner deleted the feature/update-groups-for-managers branch March 13, 2022 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants