Merge pull request #964 from ae-utbm/fix-backend

Fix custom auth backend
This commit is contained in:
thomas girod 2024-12-22 15:07:46 +01:00 committed by GitHub
commit 81773dc800
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,9 +29,14 @@ class SithModelBackend(ModelBackend):
"""
def _get_group_permissions(self, user_obj: User):
groups = user_obj.groups.all()
# union of querysets doesn't work if the queryset is ordered.
# The empty `order_by` here are actually there to *remove*
# any default ordering defined in managers or model Meta
groups = user_obj.groups.order_by()
if user_obj.is_subscribed:
groups = groups.union(
Group.objects.get(pk=settings.SITH_GROUP_SUBSCRIBERS_ID)
Group.objects.filter(pk=settings.SITH_GROUP_SUBSCRIBERS_ID).order_by()
)
return Permission.objects.filter(group__group__in=groups)
return Permission.objects.filter(
group__group__in=groups.values_list("pk", flat=True)
)