Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
newswangerd committed Mar 3, 2024
1 parent 67eab54 commit 1fc7afd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion galaxy_ng/app/api/resource_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,49 @@
ServiceAPIConfig,
SharedResource,
)

from ansible_base.resource_registry.models import Resource, service_id

from ansible_base.resource_registry.serializers import ValidateLocalUserSerializer

from ansible_base.resource_registry.shared_types import UserType, TeamType
from galaxy_ng.app import models


class APIConfig(ServiceAPIConfig):
service_type = "galaxy"

@staticmethod
def get_local_user_details(user) -> ValidateLocalUserSerializer:
user_resource = Resource.get_resource_for_object(user)
team_memberships = []

for group in user.groups.all():
resource = Resource.get_resource_for_object(group)

# Skip mappings that are owned by the local service.
if str(resource.service_id) != str(service_id()):
team_memberships.append(
{
"ansible_id": resource.ansible_id,
"membership_type": "member"
}
)

data = {
"username": user.username,
"email": user.email,
"first_name": user.first_name,
"last_name": user.last_name,
"is_superuser": user.is_superuser,
"service_id": user_resource.service_id,
"ansible_id": user_resource.ansible_id,
"organizations": [],
"teams": team_memberships
}

return ValidateLocalUserSerializer(data)


RESOURCE_LIST = (
ResourceConfig(
Expand All @@ -24,7 +60,7 @@ class APIConfig(ServiceAPIConfig):
models.auth.Group,
shared_resource=SharedResource(
serializer=TeamType,
is_provider=True
is_provider=False
),
name_field="name"
),
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
name="swagger-ui",
),
path("healthz", views.health_view),
path(f"{API_PATH_PREFIX}", include(resource_api_urls))
path(f"{API_PATH_PREFIX}/", include(resource_api_urls))
]

if settings.get("API_ROOT") != "/pulp/":
Expand Down

0 comments on commit 1fc7afd

Please sign in to comment.