Skip to content

Commit

Permalink
Update services.py
Browse files Browse the repository at this point in the history
add admin
  • Loading branch information
untitledds authored Dec 2, 2024
1 parent fc80d66 commit db543f6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions back/taiga_contrib_access_token_auth/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
FILTER_GROUPS = settings.FILTER_GROUPS
PROJECTS = settings.PROJECTS
DEFAULT_ROLE = settings.DEFAULT_ROLE
ADMIN_GROUP = settings.ADMIN_GROUP # Добавляем переменную окружения для группы администраторов

def determine_role_and_project(groups):
"""
Определяет роль и проект на основе групп пользователя.
"""
for group in groups:
parts = group.split(':')
if len(parts) == 2:
Expand Down Expand Up @@ -76,12 +80,21 @@ def access_token_register(
name=role
)

membership_model.objects.get_or_create(
# Проверка на наличие группы администраторов
is_admin = ADMIN_GROUP in groups

membership, created = membership_model.objects.get_or_create(
user=user,
project=project,
role=role
defaults={'role': role, 'is_admin': is_admin}
)
logger.info(f"Role assigned to user: {email}, role: {role}, project_id: {project.id}")

# Обновление статуса администратора, если пользователь ранее не был админом
if not created and is_admin and not membership.is_admin:
membership.is_admin = True
membership.save()

logger.info(f"Role assigned to user: {email}, role: {role}, project_id: {project.id}, is_admin: {is_admin}")

return user

Expand Down

0 comments on commit db543f6

Please sign in to comment.