Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize user v3 namespace owner lookups. #1901

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions galaxy_ng/app/utils/rbac.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from pulpcore.plugin.models.role import Role

from pulpcore.plugin.util import (
assign_role,
get_groups_with_perms_attached_roles,
get_users_with_perms_attached_roles,
get_objects_for_user,
remove_role
)

Expand Down Expand Up @@ -92,10 +95,12 @@ def get_v3_namespace_owners(namespace: Namespace) -> list:

def get_owned_v3_namespaces(user: User):

owned = []
for namespace in Namespace.objects.all():
owners = get_v3_namespace_owners(namespace)
if user in owners:
owned.append(namespace)
role_name = 'galaxy.collection_namespace_owner'
role = Role.objects.filter(name=role_name).first()
permission_codenames = role.permissions.values_list("codename", flat=True)

return owned
return get_objects_for_user(
user,
permission_codenames,
Namespace.objects.all()
)
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,9 @@ def test_social_user_sync_with_changed_login(ansible_config):
assert role_data['results'][0]['github_user'] == 'Wilk42'
assert role_data['results'][0]['github_repo'] == role['github_repo']
assert role_data['results'][0]['name'] == role['name']


@pytest.mark.skip(reason='this should be unit tested')
@pytest.mark.deployment_community
def test_rbac_utils_get_owned_v3_namespaces(ansible_config):
pass
Loading