diff --git a/galaxy_ng/app/api/resource_api.py b/galaxy_ng/app/api/resource_api.py index 7a49cd54aa..0666872e5b 100644 --- a/galaxy_ng/app/api/resource_api.py +++ b/galaxy_ng/app/api/resource_api.py @@ -5,10 +5,45 @@ ) from ansible_base.resource_registry.shared_types import OrganizationType, TeamType, UserType + +from ansible_base.resource_registry.shared_types import UserType, TeamType from galaxy_ng.app import models +from ansible_base.resource_registry.utils.resource_type_processor import ResourceTypeProcessor + + +class UserMapper: + def __init__(self, **kwargs): + for k, v in kwargs.items(): + setattr(self, k, v) + + +class GalaxyUserProcessor(ResourceTypeProcessor): + def pre_serialize_additional(self): + teams = models.Team.objects.filter(group__pk__in=self.instance.groups.all()) + + user = UserMapper( + username=self.instance.username, + email=self.instance.email, + first_name=self.instance.first_name, + last_name=self.instance.last_name, + is_superuser=self.instance.is_superuser, + external_auth_provider=None, + external_auth_uid=None, + organizations=[], + teams=teams, + organizations_administered=[], + teams_administered=[], + ) + + return user + + class APIConfig(ServiceAPIConfig): + + custom_resource_processors = {"shared.user": GalaxyUserProcessor} + service_type = "galaxy" @@ -20,7 +55,7 @@ class APIConfig(ServiceAPIConfig): ), ResourceConfig( models.Team, - shared_resource=SharedResource(serializer=TeamType, is_provider=True), + shared_resource=SharedResource(serializer=TeamType, is_provider=False), name_field="name", ), ResourceConfig( diff --git a/galaxy_ng/app/models/organization.py b/galaxy_ng/app/models/organization.py index d127319889..502a1944b6 100644 --- a/galaxy_ng/app/models/organization.py +++ b/galaxy_ng/app/models/organization.py @@ -84,3 +84,8 @@ def _create_related_team(sender, instance, created, **kwargs): organization=Organization.objects.get_default(), group=instance, ) + + +@receiver(signal=signals.post_delete, sender=Team) +def _delete_group(sender, instance, **kwargs): + instance.group.delete() diff --git a/galaxy_ng/app/urls.py b/galaxy_ng/app/urls.py index 05dbdf94f0..b7ddb5d61d 100644 --- a/galaxy_ng/app/urls.py +++ b/galaxy_ng/app/urls.py @@ -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/":