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

Fix a bug where saving a Group would throw a 500 error #500

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion website/users/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from users.models import GroupSettings
from users.services import update_staff_status
from django.contrib.auth.models import Group

User = get_user_model()

Expand All @@ -20,4 +21,9 @@ def after_user_groups_changed(sender, instance, **kwargs):
"""Update the is_staff value of the users when they are added to groups."""
action = kwargs.get("action")
if action == "post_add" or action == "post_remove":
update_staff_status(instance)
# This receiver gets triggered by both User and Group objects.
if isinstance(instance, User):
update_staff_status(instance)
elif isinstance(instance, Group):
for user in instance.user_set.all():
update_staff_status(user)