Skip to content

Commit

Permalink
make the bootstrap script add team group permissions to the first non…
Browse files Browse the repository at this point in the history
…-readonly camp created
  • Loading branch information
tykling committed Sep 30, 2024
1 parent db42365 commit a36aa34
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/utils/management/commands/bootstrap_devsite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from camps.models import Permission as CampPermission
from django.contrib.contenttypes.models import ContentType

import logging
from django.contrib.auth.models import Permission
import random
import sys
from datetime import datetime
Expand Down Expand Up @@ -307,6 +311,7 @@ def create_camps(self):
"colour": "#73d7ee",
"read_only": False,
"light_text": False,
"add_permissions": True,
},
{
"year": 2025,
Expand Down Expand Up @@ -349,6 +354,7 @@ def create_camps(self):
tz.localize(datetime(year, 9, 5, 12, 0)),
),
colour=camp["colour"],
light_text=camp.get("light_text", True),
),
read_only,
),
Expand Down Expand Up @@ -2083,6 +2089,17 @@ def create_camp_revenues(self, camp):
self.output(f"Creating revenues for {camp}...")
RevenueFactory.create_batch(20, camp=camp)

def add_team_permissions(self, camp):
"""Assign member permissions to the team groups for this camp."""
self.output(f"Assigning permissions to team groups for {camp}...")
permission_content_type = ContentType.objects.get_for_model(CampPermission)
for team in camp.teams.all():
permission = Permission.objects.get(
content_type=permission_content_type,
codename=f"{team.slug}_team_member",
)
team.group.permissions.add(permission)

def output(self, message):
self.stdout.write(
"{}: {}".format(timezone.now().strftime("%Y-%m-%d %H:%M:%S"), message),
Expand Down Expand Up @@ -2128,6 +2145,7 @@ def handle(self, *args, **options):

self.create_epay_transactions()

permissions_added = False
for camp, read_only in camps:
year = camp.camp.lower.year

Expand All @@ -2154,6 +2172,10 @@ def handle(self, *args, **options):

teams = self.create_camp_teams(camp)

if not read_only and not permissions_added:
# add permissions for the first camp that is not read_only
self.add_team_permissions(camp)

self.create_camp_team_tasks(camp, teams)

team_memberships = self.create_camp_team_memberships(camp, teams, users)
Expand Down

0 comments on commit a36aa34

Please sign in to comment.