-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RBAC] Rename managed role definitions, and move migration logic here (…
…#15087) * Rename managed role definitions, and move migration logic here * Fix naming capitalization
- Loading branch information
1 parent
431b4ce
commit ce7db57
Showing
8 changed files
with
189 additions
and
30 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
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
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
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,10 @@ | ||
import pytest | ||
from django.apps import apps | ||
|
||
from awx.main.migrations._dab_rbac import setup_managed_role_definitions | ||
|
||
|
||
@pytest.fixture | ||
def managed_roles(): | ||
"Run the migration script to pre-create managed role definitions" | ||
setup_managed_role_definitions(apps, None) |
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,45 @@ | ||
import pytest | ||
from django.apps import apps | ||
from django.test.utils import override_settings | ||
|
||
from awx.main.migrations._dab_rbac import setup_managed_role_definitions | ||
|
||
from ansible_base.rbac.models import RoleDefinition | ||
|
||
INVENTORY_OBJ_PERMISSIONS = ['view_inventory', 'adhoc_inventory', 'use_inventory', 'change_inventory', 'delete_inventory', 'update_inventory'] | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_managed_definitions_precreate(): | ||
with override_settings( | ||
ANSIBLE_BASE_ROLE_PRECREATE={ | ||
'object_admin': '{cls._meta.model_name}-admin', | ||
'org_admin': 'organization-admin', | ||
'org_children': 'organization-{cls._meta.model_name}-admin', | ||
'special': '{cls._meta.model_name}-{action}', | ||
} | ||
): | ||
setup_managed_role_definitions(apps, None) | ||
rd = RoleDefinition.objects.get(name='inventory-admin') | ||
assert rd.managed is True | ||
# add permissions do not go in the object-level admin | ||
assert set(rd.permissions.values_list('codename', flat=True)) == set(INVENTORY_OBJ_PERMISSIONS) | ||
|
||
# test org-level object admin permissions | ||
rd = RoleDefinition.objects.get(name='organization-inventory-admin') | ||
assert rd.managed is True | ||
assert set(rd.permissions.values_list('codename', flat=True)) == set(['add_inventory', 'view_organization'] + INVENTORY_OBJ_PERMISSIONS) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_managed_definitions_custom_obj_admin_name(): | ||
with override_settings( | ||
ANSIBLE_BASE_ROLE_PRECREATE={ | ||
'object_admin': 'foo-{cls._meta.model_name}-foo', | ||
} | ||
): | ||
setup_managed_role_definitions(apps, None) | ||
rd = RoleDefinition.objects.get(name='foo-inventory-foo') | ||
assert rd.managed is True | ||
# add permissions do not go in the object-level admin | ||
assert set(rd.permissions.values_list('codename', flat=True)) == set(INVENTORY_OBJ_PERMISSIONS) |
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
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
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