diff --git a/myproject/user_roles/services.py b/myproject/user_roles/services.py index 3f77b23..014a6ec 100644 --- a/myproject/user_roles/services.py +++ b/myproject/user_roles/services.py @@ -98,3 +98,25 @@ class RoleService: if not user_role: return False return user_role.code in role_codes + + @staticmethod + def can_modify_user_role(modifier_user, target_user_role): + """ + Проверяет, может ли пользователь изменить указанную роль. + + Args: + modifier_user: Пользователь, который хочет изменить роль + target_user_role: UserRole объект, который нужно изменить + + Returns: + tuple: (bool, str) - (можно ли изменить, причина отказа) + """ + # Защита от самоблокировки + if target_user_role.user == modifier_user: + return False, "Вы не можете изменить свою собственную роль" + + # Можно добавить другие проверки в будущем: + # - Запрет удаления последнего owner'а + # - Проверка иерархии ролей и т.д. + + return True, "" diff --git a/myproject/user_roles/templates/user_roles/user_role_list.html b/myproject/user_roles/templates/user_roles/user_role_list.html index 710f8c6..8ce4671 100644 --- a/myproject/user_roles/templates/user_roles/user_role_list.html +++ b/myproject/user_roles/templates/user_roles/user_role_list.html @@ -67,12 +67,18 @@ {% endif %}