Skip to content

Commit

Permalink
Fix group URLs in GroupsManager and schema
Browse files Browse the repository at this point in the history
Add name for group_users and group_roles endpoints
  • Loading branch information
arash77 committed Nov 22, 2023
1 parent 8e99cdd commit 361522d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
16 changes: 8 additions & 8 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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}": {
/**
Expand Down Expand Up @@ -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"][];
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand Down
20 changes: 6 additions & 14 deletions lib/galaxy/managers/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/schema/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
7 changes: 6 additions & 1 deletion lib/galaxy/webapps/galaxy/api/group_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion lib/galaxy/webapps/galaxy/api/group_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/webapps/galaxy/api/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 361522d

Please sign in to comment.