-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the Content Team group via a data migration
* This data migration creates the Content Team group if it doesn't exist, and adds all wiki permisions to that group. * This does not create a GroupProfile (which would require a leader assignment in order to create).
- Loading branch information
1 parent
c10de5d
commit 210c1c2
Showing
1 changed file
with
55 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,55 @@ | ||
# Generated by Django 4.2.18 on 2025-02-18 11:57 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def create_content_team(apps, schema_editor): | ||
Group = apps.get_model('auth', 'Group') | ||
Permission = apps.get_model('auth', 'Permission') | ||
|
||
content_team, created = Group.objects.get_or_create(name="Staff Content Team") | ||
|
||
# Define the permissions we want | ||
permission_codenames = [ | ||
'wiki.archive_document', | ||
'wiki.change_document', | ||
'wiki.delete_document', | ||
'wiki.edit_needs_change', | ||
'wiki.add_revision', | ||
'wiki.change_revision', | ||
'wiki.delete_revision', | ||
'wiki.edit_keywords', | ||
'wiki.mark_ready_for_l10n', | ||
'wiki.review_revision', | ||
] | ||
|
||
# Get all the required permissions | ||
permissions = Permission.objects.filter( | ||
codename__in=[name.split('.')[-1] for name in permission_codenames], | ||
content_type__app_label='wiki' | ||
) | ||
|
||
content_team.permissions.add(*permissions) | ||
|
||
|
||
def reverse_content_team(apps, schema_editor): | ||
Group = apps.get_model('auth', 'Group') | ||
|
||
try: | ||
content_team = Group.objects.get(name="Staff Content Team") | ||
content_team.permissions.clear() | ||
content_team.delete() | ||
except Group.DoesNotExist: | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("groups", "0001_squashed_0002_auto_20200629_0826"), | ||
("wiki", "0018_alter_document_restrict_to_groups"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_content_team, reverse_content_team), | ||
] |