Skip to content

Commit

Permalink
refactor(migrations): centralize permissions helper
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Aug 12, 2024
1 parent 950f0ef commit 95c7943
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from django.contrib.auth.management import create_permissions
from django.db import migrations


def create_all_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None
from benefits.core.migrations import create_all_permissions


def add_view_permissions(apps, schema_editor):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# Generated by Django 5.0.7 on 2024-07-31 22:41

from django.contrib.auth.management import create_permissions
from django.db import migrations, models

from benefits.core.migrations import create_all_permissions
import benefits.core.models
import benefits.secrets


def create_all_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None


def update_permissions(apps, schema_editor):
Group = apps.get_model("auth", "Group")
staff_group = Group.objects.get(name="Cal-ITP")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# Generated by Django 5.0.7 on 2024-08-02 22:52

from django.contrib.auth.management import create_permissions
from django.db import migrations, models

from benefits.core.migrations import create_all_permissions
import benefits.core.models
import benefits.secrets


def create_all_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None


def update_permissions(apps, schema_editor):
# delete old permissions
Permission = apps.get_model("auth", "Permission")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Generated by Django 5.0.7 on 2024-08-07 21:22

from django.contrib.auth.management import create_permissions
import django.db.models.deletion
from django.db import migrations, models

import benefits.core.models
import benefits.secrets


def create_all_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None
from benefits.core.migrations import create_all_permissions


def update_permissions(apps, schema_editor):
Expand Down
8 changes: 8 additions & 0 deletions benefits/core/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib.auth.management import create_permissions


def create_all_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None

0 comments on commit 95c7943

Please sign in to comment.