Skip to content

Commit

Permalink
Create the Content Team group via a data migration
Browse files Browse the repository at this point in the history
* 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
smithellis committed Feb 20, 2025
1 parent c10de5d commit 210c1c2
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions kitsune/groups/migrations/0003_auto_20250218_1157.py
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),
]

0 comments on commit 210c1c2

Please sign in to comment.