mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 07:41:14 +00:00
Manage subscribers group permissions
This commit is contained in:
parent
bea7741d35
commit
ab81f11199
@ -2,9 +2,12 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth.backends import ModelBackend
|
from django.contrib.auth.backends import ModelBackend
|
||||||
from django.contrib.auth.models import Permission
|
from django.contrib.auth.models import Permission
|
||||||
|
|
||||||
|
from core.models import Group
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from core.models import User
|
from core.models import User
|
||||||
|
|
||||||
@ -26,4 +29,9 @@ class SithModelBackend(ModelBackend):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def _get_group_permissions(self, user_obj: User):
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user