mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-04 05:12:22 +00:00
Add all superusers to admin group
This commit is contained in:
parent
1d2b6f038a
commit
d9857839dc
1 changed files with 29 additions and 0 deletions
29
bookwyrm/migrations/0124_auto_20220106_1759.py
Normal file
29
bookwyrm/migrations/0124_auto_20220106_1759.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Generated by Django 3.2.10 on 2022-01-06 17:59
|
||||
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def get_admins(apps, schema_editor):
|
||||
"""add any superusers to the "admin" group"""
|
||||
|
||||
db_alias = schema_editor.connection.alias
|
||||
groups = apps.get_model("auth", "Group")
|
||||
group = groups.objects.using(db_alias).get(name="admin")
|
||||
|
||||
users = apps.get_model("bookwyrm", "User")
|
||||
admins = users.objects.using(db_alias).filter(is_superuser=True)
|
||||
|
||||
for admin in admins:
|
||||
admin.groups.add(group)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0123_alter_user_preferred_language"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(get_admins, reverse_code=migrations.RunPython.noop),
|
||||
]
|
Loading…
Reference in a new issue