mirror of
https://github.com/ae-utbm/sith.git
synced 2026-12-05 07:12:48 +00:00
feat: Group.manageable_by
Permet de créer de rendre certains groupes attribuables par les membres d'autres groupes. Par exemple, si on donne au groupe "respo com" le droit de gérer le groupe "respo SAS", alors un respo com verra l'onglet des groupes sur le profil d'un utilisateur et sera en mesure d'attribuer le groupe "respo SAS" (et seulement celui-là)
This commit is contained in:
1 parent
be81c2e51e
commit
d7fa0b5ed6
6 files changed
+80
-13
No files matched your search
+23
-1
@@ -33,7 +33,7 @@ from typing import TYPE_CHECKING, Final, Self
|
||||
from uuid import uuid4
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AbstractUser, UserManager
|
||||
from django.contrib.auth.models import AbstractUser, GroupManager, UserManager
|
||||
from django.contrib.auth.models import AnonymousUser as AuthAnonymousUser
|
||||
from django.contrib.auth.models import Group as AuthGroup
|
||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||
@@ -65,6 +65,19 @@ if TYPE_CHECKING:
|
||||
from club.models import Club
|
||||
|
||||
|
||||
class GroupQuerySet(models.QuerySet):
|
||||
def manageable_by(self, user: User):
|
||||
"""Filter groups that are editable by this user in the sith UI."""
|
||||
if user.has_perm("core.change_group"):
|
||||
return self.filter(is_manually_manageable=True)
|
||||
return self.filter(
|
||||
is_manually_manageable=True, manageable_by__in=user.groups.all()
|
||||
)
|
||||
|
||||
|
||||
class CustomGroupManager(GroupManager.from_queryset(GroupQuerySet)): ...
|
||||
|
||||
|
||||
class Group(AuthGroup):
|
||||
"""Wrapper around django.auth.Group"""
|
||||
|
||||
@@ -74,6 +87,15 @@ class Group(AuthGroup):
|
||||
help_text=_("If False, this shouldn't be shown on group management pages"),
|
||||
)
|
||||
description = models.TextField(_("description"))
|
||||
manageable_by = models.ManyToManyField(
|
||||
"Group",
|
||||
verbose_name=_("manageable by"),
|
||||
help_text=_("Groups that are able to grant and remove this group."),
|
||||
related_name="managed_groups",
|
||||
blank=True,
|
||||
)
|
||||
|
||||
objects = CustomGroupManager()
|
||||
|
||||
def get_absolute_url(self) -> str:
|
||||
return reverse("core:group_list")
|
||||
|
||||
Reference in new issue
Block a user