Skip to content

Commit

Permalink
Alter signals to handle OAuth2 with groups and role mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Jun 2, 2020
1 parent 967ac5c commit 9c439d6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pydis_site/apps/home/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def mapping_model_deleted(self, sender: Type[RoleMapping], **kwargs) -> None:
social_account = SocialAccount.objects.get(user=user, provider=DiscordProvider.id)
discord_user = DiscordUser.objects.get(id=int(social_account.uid))

mappings = RoleMapping.objects.filter(role__in=discord_user.roles.all()).all()
mappings = RoleMapping.objects.filter(role__id__in=discord_user.roles).all()
is_staff = any(m.is_staff for m in mappings)

if user.is_staff != is_staff:
Expand Down Expand Up @@ -185,7 +185,7 @@ def mapping_model_updated(self, sender: Type[RoleMapping], **kwargs) -> None:
self.mapping_model_deleted(RoleMapping, instance=old_instance)

accounts = SocialAccount.objects.filter(
uid__in=(u.id for u in instance.role.user_set.all())
uid__in=(u.id for u in DiscordUser.objects.filter(roles__contains=[instance.role.id]))
)

for account in accounts:
Expand All @@ -198,7 +198,7 @@ def mapping_model_updated(self, sender: Type[RoleMapping], **kwargs) -> None:
discord_user = DiscordUser.objects.get(id=int(account.uid))

mappings = RoleMapping.objects.filter(
role__in=discord_user.roles.all()
role__id__in=discord_user.roles
).exclude(id=instance.id).all()
is_staff = any(m.is_staff for m in mappings)

Expand Down Expand Up @@ -289,9 +289,9 @@ def _apply_groups(
new_groups = []
is_staff = False

for role in user.roles.all():
for role in user.roles:
try:
mapping = mappings.get(role=role)
mapping = mappings.get(role__id=role)
except RoleMapping.DoesNotExist:
continue # No mapping exists

Expand Down

0 comments on commit 9c439d6

Please sign in to comment.