Skip to content

Commit

Permalink
feat(accounts): for incoming editor and new section, promote him to a…
Browse files Browse the repository at this point in the history
…dmin
  • Loading branch information
thejoeejoee committed Nov 15, 2023
1 parent c6d4953 commit 52660a4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fiesta/apps/esnaccounts/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def update_section_membership(
user_nationality = sa.extra_data.get("nationality")
# national_section = sa.extra_data.get("country")

section, _ = Section.objects.get_or_create(
section, is_section_new = Section.objects.get_or_create(
name=section_name,
defaults=dict(
code=section_code,
Expand All @@ -79,6 +79,9 @@ def update_section_membership(

SectionPluginsReconciler.reconcile(section)

already_has_admin_user = section.memberships.filter(role=SectionMembership.Role.ADMIN).exists()
promote_editor_to_admin = not already_has_admin_user or is_section_new

# role and activation only for first time
SectionMembership.objects.get_or_create(
user=user,
Expand All @@ -90,7 +93,7 @@ def update_section_membership(
state=SectionMembership.State.ACTIVE,
role=(
SectionMembership.Role.ADMIN
if cls.ADMIN_ROLE in roles
if cls.ADMIN_ROLE in roles or (promote_editor_to_admin and cls.EDITOR_ROLE in roles)
else (
SectionMembership.Role.EDITOR
if cls.EDITOR_ROLE in roles
Expand Down

0 comments on commit 52660a4

Please sign in to comment.