mirror of
https://github.com/bratusev07/skb-market.git
synced 2026-12-05 05:09:44 +00:00
feat: auth, role and moderation logic added
This commit is contained in:
1 parent
1212dca845
commit
36b1341a10
14 files changed
+821
-175
No files matched your search
@@ -0,0 +1,22 @@
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
|
||||
def has_role(user, role_name):
|
||||
"""Проверяет, состоит ли пользователь в указанной группе."""
|
||||
if not user.is_authenticated:
|
||||
return False
|
||||
|
||||
return user.groups.filter(name=role_name).exists()
|
||||
|
||||
|
||||
def is_moderator(user):
|
||||
"""Проверяет, является ли пользователь модератором."""
|
||||
return has_role(user, "Moderator")
|
||||
|
||||
|
||||
def is_library_admin(user):
|
||||
"""Проверяет, является ли пользователь администратором библиотеки."""
|
||||
return user.is_superuser or has_role(user, "Administrator")
|
||||
|
||||
def can_manage_games(user):
|
||||
return is_moderator(user) or is_library_admin(user)
|
||||
Reference in new issue
Block a user