Skip to content

Commit 2e9d848

Browse files
committed
Avoid creating permissions in migration
1 parent ca7e1bb commit 2e9d848

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

ansible_base/rbac/management/create_types.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.db import DEFAULT_DB_ALIAS, connection, models
66

77
from ansible_base.rbac import permission_registry
8-
from ansible_base.rbac.remote import get_resource_prefix, get_local_resource_prefix, get_remote_standin_class
8+
from ansible_base.rbac.remote import get_local_resource_prefix, get_remote_standin_class, get_resource_prefix
99

1010
logger = logging.getLogger(__name__)
1111

@@ -69,9 +69,7 @@ def create_DAB_contenttypes(
6969
if not ct_data:
7070
return []
7171

72-
# To make usage earier in a transitional period, we will set the content type
73-
# of any new entries created here to the id of its corresponding ContentType
74-
# from the actual contenttypes app, allowing many filters to work
72+
# Create the items here
7573
cts = []
7674
for ct_item_data in ct_data:
7775
cts.append(dab_ct_cls.objects.create(**ct_item_data))

ansible_base/rbac/migrations/0005_remote_permissions_data.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
from django.db import migrations
44

55

6-
def create_types_and_permissions(apps, schema_editor):
6+
def create_types_if_needed(apps, schema_editor):
77
"""Before we can migrate to the new DABContentType, entries in that table must be created.
88
99
This method runs what is ordinarily the post_migrate logic, but in the migration case here.
10+
Only needed in the upgrade case, otherwise better to run at true post-migrate.
1011
"""
11-
from ansible_base.rbac.management import create_dab_permissions
12+
permission_cls = apps.get_model('dab_rbac', 'DABPermission')
13+
rd_cls = permission_cls = apps.get_model('dab_rbac', 'RoleDefinition')
14+
if permission_cls.objects.exists() or rd_cls.objects.exists():
15+
from ansible_base.rbac.management.create_types import create_DAB_contenttypes
1216

13-
create_dab_permissions(apps.get_app_config('dab_rbac'), apps=apps)
17+
create_DAB_contenttypes(apps=apps)
1418

1519

1620
def migrate_content_type(apps, schema_editor):
@@ -48,6 +52,6 @@ class Migration(migrations.Migration):
4852
]
4953

5054
operations = [
51-
migrations.RunPython(create_types_and_permissions, migrations.RunPython.noop),
55+
migrations.RunPython(create_types_if_needed, migrations.RunPython.noop),
5256
migrations.RunPython(migrate_content_type, migrations.RunPython.noop),
5357
]

0 commit comments

Comments
 (0)