-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create cron job to give superuser to env-defined users (temporary pat…
…ch over broken platform-level team sync)
- Loading branch information
1 parent
109c44c
commit a51abb7
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.models import Group, Permission | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.core.management.base import BaseCommand | ||
|
||
from clubs.models import Club | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Give superuser to hard-coded user accounts affiliated with OSA." | ||
web_execute = True | ||
|
||
def handle(self, *args, **kwargs): | ||
User = get_user_model() | ||
content_type = ContentType.objects.get_for_model(Club) | ||
approve_perm = Permission.objects.get( | ||
codename="approve_club", content_type=content_type | ||
) | ||
pending_perm = Permission.objects.get( | ||
codename="see_pending_clubs", content_type=content_type | ||
) | ||
if not settings.OSA_KEYS: | ||
raise ValueError("OSA_KEYS not set in settings") | ||
if not (approvers := Group.objects.filter(name="Approvers").first()): | ||
raise ValueError("Approvers group not found") | ||
for key in settings.OSA_KEYS: | ||
if not key or not (user := User.objects.get(username=key)): | ||
continue | ||
user.is_superuser = True | ||
user.is_staff = True | ||
user.user_permissions.add(approve_perm) | ||
user.user_permissions.add(pending_perm) | ||
approvers.user_set.add(user) | ||
user.save() | ||
approvers.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters