From 361522dc54b4090bfdb079794adc86845740717f Mon Sep 17 00:00:00 2001 From: Arash Date: Wed, 22 Nov 2023 14:14:09 +0100 Subject: [PATCH] Fix group URLs in GroupsManager and schema Add name for group_users and group_roles endpoints --- client/src/api/schema/schema.ts | 16 ++++++++-------- lib/galaxy/managers/groups.py | 20 ++++++-------------- lib/galaxy/schema/groups.py | 4 ++-- lib/galaxy/webapps/galaxy/api/group_roles.py | 7 ++++++- lib/galaxy/webapps/galaxy/api/group_users.py | 7 ++++++- lib/galaxy/webapps/galaxy/api/groups.py | 1 + 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/client/src/api/schema/schema.ts b/client/src/api/schema/schema.ts index cdd8636a955f..15a0e8ddfb8b 100644 --- a/client/src/api/schema/schema.ts +++ b/client/src/api/schema/schema.ts @@ -389,13 +389,13 @@ export interface paths { }; "/api/groups/{group_id}": { /** Displays information about a group. */ - get: operations["show_api_groups__group_id__get"]; + get: operations["show_group_api_groups__group_id__get"]; /** Modifies a group. */ put: operations["update_api_groups__group_id__put"]; }; "/api/groups/{group_id}/roles": { /** Displays a collection (list) of groups. */ - get: operations["index_api_groups__group_id__roles_get"]; + get: operations["group_roles_api_groups__group_id__roles_get"]; }; "/api/groups/{group_id}/roles/{role_id}": { /** Displays information about a group role. */ @@ -430,7 +430,7 @@ export interface paths { * @description GET /api/groups/{encoded_group_id}/users * Displays a collection (list) of groups. */ - get: operations["index_api_groups__group_id__users_get"]; + get: operations["group_users_api_groups__group_id__users_get"]; }; "/api/groups/{group_id}/users/{user_id}": { /** @@ -4720,11 +4720,11 @@ export interface components { /** name of the group */ name: string; /** URL for the roles of the group */ - roles_url?: string[]; + roles_url?: string; /** URL for the group */ url: string; /** URL for the users of the group */ - users_url?: string[]; + users_url?: string; }; /** GroupRoleListResponse */ GroupRoleListResponse: components["schemas"]["GroupRoleResponse"][]; @@ -11650,7 +11650,7 @@ export interface operations { }; }; }; - show_api_groups__group_id__get: { + show_group_api_groups__group_id__get: { /** Displays information about a group. */ parameters: { /** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */ @@ -11707,7 +11707,7 @@ export interface operations { }; }; }; - index_api_groups__group_id__roles_get: { + group_roles_api_groups__group_id__roles_get: { /** Displays a collection (list) of groups. */ parameters: { /** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */ @@ -11919,7 +11919,7 @@ export interface operations { }; }; }; - index_api_groups__group_id__users_get: { + group_users_api_groups__group_id__users_get: { /** * Displays a collection (list) of groups. * @description GET /api/groups/{encoded_group_id}/users diff --git a/lib/galaxy/managers/groups.py b/lib/galaxy/managers/groups.py index 683d6ec4a8b4..a0950a4063b8 100644 --- a/lib/galaxy/managers/groups.py +++ b/lib/galaxy/managers/groups.py @@ -35,7 +35,7 @@ def index(self, trans: ProvidesAppContext): for group in get_not_deleted_groups(trans.sa_session): item = group.to_dict(value_mapper={"id": DecodedDatabaseIdField.encode}) encoded_id = DecodedDatabaseIdField.encode(group.id) - item["url"] = self._url_for(trans, "index", group_id=encoded_id) + item["url"] = self._url_for(trans, "show_group", group_id=encoded_id) rval.append(item) return rval @@ -61,7 +61,7 @@ def create(self, trans: ProvidesAppContext, payload: GroupCreatePayload): encoded_id = DecodedDatabaseIdField.encode(group.id) item = group.to_dict(view="element", value_mapper={"id": DecodedDatabaseIdField.encode}) - item["url"] = self._url_for(trans, "create", group_id=encoded_id) + item["url"] = self._url_for(trans, "show_group", group_id=encoded_id) return [item] def show(self, trans: ProvidesAppContext, group_id: int): @@ -71,17 +71,9 @@ def show(self, trans: ProvidesAppContext, group_id: int): encoded_id = DecodedDatabaseIdField.encode(group_id) group = self._get_group(trans.sa_session, group_id) item = group.to_dict(view="element", value_mapper={"id": DecodedDatabaseIdField.encode}) - item["url"] = self._url_for(trans, "show", group_id=encoded_id) - encoded_user_id = [DecodedDatabaseIdField.encode(gu.user.id) for gu in group.users] - encoded_role_id = [DecodedDatabaseIdField.encode(gr.role.id) for gr in group.roles] - item["users_url"] = [ - self._url_for(trans, "group_user", group_id=encoded_id, user_id=group_user) - for group_user in encoded_user_id - ] - item["roles_url"] = [ - self._url_for(trans, "group_role", group_id=encoded_id, role_id=group_role) - for group_role in encoded_role_id - ] + item["url"] = self._url_for(trans, "show_group", group_id=encoded_id) + item["users_url"] = self._url_for(trans, "group_users", group_id=encoded_id) + item["roles_url"] = self._url_for(trans, "group_roles", group_id=encoded_id) return item def update(self, trans: ProvidesAppContext, group_id: int, payload: GroupCreatePayload): @@ -107,7 +99,7 @@ def update(self, trans: ProvidesAppContext, group_id: int, payload: GroupCreateP encoded_id = DecodedDatabaseIdField.encode(group.id) item = group.to_dict(view="element", value_mapper={"id": DecodedDatabaseIdField.encode}) - item["url"] = self._url_for(trans, "update", group_id=encoded_id) + item["url"] = self._url_for(trans, "show_group", group_id=encoded_id) return item def _url_for(self, trans, name, **kwargs): diff --git a/lib/galaxy/schema/groups.py b/lib/galaxy/schema/groups.py index 4b0b26b3ed22..b6de76782b61 100644 --- a/lib/galaxy/schema/groups.py +++ b/lib/galaxy/schema/groups.py @@ -35,11 +35,11 @@ class GroupResponse(Model): Required, title="URL for the group", ) - roles_url: Optional[List[str]] = Field( + roles_url: Optional[str] = Field( None, title="URL for the roles of the group", ) - users_url: Optional[List[str]] = Field( + users_url: Optional[str] = Field( None, title="URL for the users of the group", ) diff --git a/lib/galaxy/webapps/galaxy/api/group_roles.py b/lib/galaxy/webapps/galaxy/api/group_roles.py index 21eca4638f02..7ebe74725798 100644 --- a/lib/galaxy/webapps/galaxy/api/group_roles.py +++ b/lib/galaxy/webapps/galaxy/api/group_roles.py @@ -39,7 +39,12 @@ def group_role_to_model(trans, group_id: int, role) -> GroupRoleResponse: class FastAPIGroupRoles: manager: GroupRolesManager = depends(GroupRolesManager) - @router.get("/api/groups/{group_id}/roles", require_admin=True, summary="Displays a collection (list) of groups.") + @router.get( + "/api/groups/{group_id}/roles", + require_admin=True, + summary="Displays a collection (list) of groups.", + name="group_roles", + ) def index( self, trans: ProvidesAppContext = DependsOnTrans, group_id: DecodedDatabaseIdField = GroupIDParam ) -> GroupRoleListResponse: diff --git a/lib/galaxy/webapps/galaxy/api/group_users.py b/lib/galaxy/webapps/galaxy/api/group_users.py index a3d9541e6e01..5fb77919771c 100644 --- a/lib/galaxy/webapps/galaxy/api/group_users.py +++ b/lib/galaxy/webapps/galaxy/api/group_users.py @@ -38,7 +38,12 @@ def group_user_to_model(trans, group_id, user) -> GroupUserResponse: class FastAPIGroupUsers: manager: GroupUsersManager = depends(GroupUsersManager) - @router.get("/api/groups/{group_id}/users", require_admin=True, summary="Displays a collection (list) of groups.") + @router.get( + "/api/groups/{group_id}/users", + require_admin=True, + summary="Displays a collection (list) of groups.", + name="group_users", + ) def index( self, trans: ProvidesAppContext = DependsOnTrans, group_id: DecodedDatabaseIdField = GroupIDParam ) -> GroupUserListResponse: diff --git a/lib/galaxy/webapps/galaxy/api/groups.py b/lib/galaxy/webapps/galaxy/api/groups.py index 56c92a29e267..2b4c7e1ca1d5 100644 --- a/lib/galaxy/webapps/galaxy/api/groups.py +++ b/lib/galaxy/webapps/galaxy/api/groups.py @@ -60,6 +60,7 @@ def create( "/api/groups/{group_id}", summary="Displays information about a group.", require_admin=True, + name="show_group", ) def show( self,