Skip to content

Commit

Permalink
Need to fix the migrations, register orgs, finish tests. etc.
Browse files Browse the repository at this point in the history
No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner committed Aug 16, 2024
1 parent 6b8280f commit 6c59fba
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
22 changes: 21 additions & 1 deletion galaxy_ng/app/migrations/_dab_rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
logger = logging.getLogger(__name__)


PULP_TO_ROLEDEF = {
'galaxy.auditor': 'Platform Auditor',
}


ROLEDEF_TO_PULP = {
'Platform Auditor': 'galaxy.auditor',
}


def pulp_role_to_single_content_type_or_none(pulprole):
content_types = set(perm.content_type for perm in pulprole.permissions.all())
if len(list(content_types)) == 1:
return list(content_types)[0]
return None


def create_permissions_as_operation(apps, schema_editor):
# TODO: possibly create permissions for more apps here
for app_label in {'ansible', 'container', 'core', 'galaxy'}:
Expand Down Expand Up @@ -54,11 +71,14 @@ def copy_roles_to_role_definitions(apps, schema_editor):
dab_perms.append(dabperm)

if dab_perms:
roledef_name = PULP_TO_ROLEDEF.get(corerole.name, corerole.name)
content_type = pulp_role_to_single_content_type_or_none(corerole)
roledef, created = RoleDefinition.objects.get_or_create(
name=corerole.name,
name=roledef_name,
defaults={
'description': corerole.description or corerole.name,
'managed': corerole.locked,
'content_type': content_type,
}
)
if created:
Expand Down
1 change: 1 addition & 0 deletions galaxy_ng/app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
CollectionRemote,
ContainerRegistryRemote,
Namespace,
Organization,
Team,
parent_field_name=None
)
Expand Down
13 changes: 13 additions & 0 deletions galaxy_ng/app/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ def rbac_signal_in_progress():
return bool(rbac_state.dab_action or rbac_state.pulp_action)


def pulp_role_to_single_content_type_or_none(pulprole):
content_types = set(perm.content_type for perm in pulprole.permissions.all())
if len(list(content_types)) == 1:
return list(content_types)[0]
return None


def copy_permissions_role_to_role(roleA, roleB):
"""Make permissions on roleB match roleA
Expand Down Expand Up @@ -217,9 +224,15 @@ def copy_role_to_role_definition(sender, instance, created, **kwargs):
roledef_name = PULP_TO_ROLEDEF.get(instance.name, instance.name)
rd = RoleDefinition.objects.filter(name=roledef_name).first()
if not rd:
content_type = pulp_role_to_single_content_type_or_none(instance)
logger.info(
f'CREATE ROLEDEF name:{roledef_name}'
+ f' managed:{instance.locked} ctype:{content_type}'
)
RoleDefinition.objects.create(
name=roledef_name,
managed=instance.locked,
content_type=content_type,
description=instance.description or instance.name,
)
# TODO: other fields? like description
Expand Down
51 changes: 51 additions & 0 deletions galaxy_ng/tests/integration/dab/test_dab_rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,54 @@ def test_dab_team_platform_auditor_bidirectional_sync(
# ensure the role was removed
pulp_assignments = gc.get(f"pulp/api/v3/groups/{guid}/roles/")
assert pulp_assignments['count'] == 0


@pytest.mark.deployment_standalone
def test_dab_user_assignment_filtering_as_user(
settings,
galaxy_client,
random_namespace,
random_username,
):
if settings.get('ALLOW_LOCAL_RESOURCE_MANAGEMENT') is False:
pytest.skip("this test relies on local resource creation")

gc = galaxy_client("admin", ignore_cache=True)

# find the namespace owner roledef ...
roledef = gc.get(
'_ui/v2/role_definitions/?name=galaxy.collection_namespace_owner'
)['results'][0]

# make the user ...
user_data = gc.post(
"_ui/v2/users/",
body=json.dumps({
"username": random_username,
"password": "redhat1234",
"email": random_username + '@localhost'
})
)
uid = user_data['id']

# assign the user to the namespace ...
assignment = gc.post(
'_ui/v2/role_user_assignments/',
body=json.dumps({
'user': uid,
'role_definition': roledef['id'],
'object_id': str(random_namespace['id']),
})
)

# see if we can find the assignment through filtering as the user ...
auth = {'username': random_username, 'password': 'redhat1234'}
ugc = GalaxyClient(gc.galaxy_root, auth=auth)
queryparams = [
f"object_id={random_namespace['id']}",
f"object_id={random_namespace['id']}&content_type__model=namespace",
]
for qp in queryparams:
resp = ugc.get(f'_ui/v2/role_user_assignments/?{qp}')
assert resp['count'] == 1
assert resp['results'][0]['id'] == assignment['id']

0 comments on commit 6c59fba

Please sign in to comment.