From 95c794321d8f719b6f6ab196e370c52e912d235b Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Thu, 8 Aug 2024 04:27:50 +0000 Subject: [PATCH] refactor(migrations): centralize permissions helper --- .../core/migrations/0014_staff_group_view_permissions.py | 8 +------- .../0016_refactor_paymentprocessor_transitprocessor.py | 9 +-------- .../0017_refactor_authprovider_claimsprovider.py | 9 +-------- .../0021_rename_eligibilityverifier_enrollmentflow.py | 9 +-------- benefits/core/migrations/__init__.py | 8 ++++++++ 5 files changed, 12 insertions(+), 31 deletions(-) diff --git a/benefits/core/migrations/0014_staff_group_view_permissions.py b/benefits/core/migrations/0014_staff_group_view_permissions.py index 3841083724..b70c6e29ad 100644 --- a/benefits/core/migrations/0014_staff_group_view_permissions.py +++ b/benefits/core/migrations/0014_staff_group_view_permissions.py @@ -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): diff --git a/benefits/core/migrations/0016_refactor_paymentprocessor_transitprocessor.py b/benefits/core/migrations/0016_refactor_paymentprocessor_transitprocessor.py index 33426cbab5..57ea984f2b 100644 --- a/benefits/core/migrations/0016_refactor_paymentprocessor_transitprocessor.py +++ b/benefits/core/migrations/0016_refactor_paymentprocessor_transitprocessor.py @@ -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") diff --git a/benefits/core/migrations/0017_refactor_authprovider_claimsprovider.py b/benefits/core/migrations/0017_refactor_authprovider_claimsprovider.py index 7e8da3543e..d03c63f4f0 100644 --- a/benefits/core/migrations/0017_refactor_authprovider_claimsprovider.py +++ b/benefits/core/migrations/0017_refactor_authprovider_claimsprovider.py @@ -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") diff --git a/benefits/core/migrations/0021_rename_eligibilityverifier_enrollmentflow.py b/benefits/core/migrations/0021_rename_eligibilityverifier_enrollmentflow.py index 6f6b1408b7..d9b571dd38 100644 --- a/benefits/core/migrations/0021_rename_eligibilityverifier_enrollmentflow.py +++ b/benefits/core/migrations/0021_rename_eligibilityverifier_enrollmentflow.py @@ -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): diff --git a/benefits/core/migrations/__init__.py b/benefits/core/migrations/__init__.py index e69de29bb2..719d43b2b9 100644 --- a/benefits/core/migrations/__init__.py +++ b/benefits/core/migrations/__init__.py @@ -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