From ab81f11199fc99a0a6ffa2e822c6c7a357ec4630 Mon Sep 17 00:00:00 2001 From: imperosol Date: Sat, 21 Dec 2024 18:52:16 +0100 Subject: [PATCH] Manage subscribers group permissions --- core/auth_backends.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/auth_backends.py b/core/auth_backends.py index ba763324..8a3087e6 100644 --- a/core/auth_backends.py +++ b/core/auth_backends.py @@ -2,9 +2,12 @@ from __future__ import annotations from typing import TYPE_CHECKING +from django.conf import settings from django.contrib.auth.backends import ModelBackend from django.contrib.auth.models import Permission +from core.models import Group + if TYPE_CHECKING: from core.models import User @@ -26,4 +29,9 @@ class SithModelBackend(ModelBackend): """ def _get_group_permissions(self, user_obj: User): - return Permission.objects.filter(group__group__users=user_obj) + groups = user_obj.groups.all() + if user_obj.is_subscribed: + groups = groups.union( + Group.objects.get(pk=settings.SITH_GROUP_SUBSCRIBERS_ID) + ) + return Permission.objects.filter(group__group__in=groups)