Skip to content

Commit

Permalink
Fix update group payload model
Browse files Browse the repository at this point in the history
All fields in the payload should be optional when updating.
  • Loading branch information
davelopez committed Jun 11, 2024
1 parent 7b17863 commit 488cfe5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/galaxy/managers/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
from galaxy.model.base import transaction
from galaxy.model.scoped_session import galaxy_scoped_session
from galaxy.schema.fields import Security
from galaxy.schema.groups import GroupCreatePayload
from galaxy.schema.groups import (
GroupCreatePayload,
GroupUpdatePayload,
)
from galaxy.structured_app import MinimalManagerApp


Expand Down Expand Up @@ -77,7 +80,7 @@ def show(self, trans: ProvidesAppContext, group_id: int):
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):
def update(self, trans: ProvidesAppContext, group_id: int, payload: GroupUpdatePayload):
"""
Modifies a group.
"""
Expand All @@ -87,9 +90,9 @@ def update(self, trans: ProvidesAppContext, group_id: int, payload: GroupCreateP
self._check_duplicated_group_name(sa_session, name)
group.name = name
sa_session.add(group)
user_ids = payload.user_ids
user_ids = payload.user_ids or []
users = get_users_by_ids(sa_session, user_ids)
role_ids = payload.role_ids
role_ids = payload.role_ids or []
roles = get_roles_by_ids(sa_session, role_ids)
self._app.security_agent.set_entity_group_associations(
groups=[group], roles=roles, users=users, delete_existing_assocs=False
Expand Down
6 changes: 6 additions & 0 deletions lib/galaxy/schema/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
from typing_extensions import Literal

from galaxy.schema import partial_model
from galaxy.schema.fields import (
DecodedDatabaseIdField,
EncodedDatabaseIdField,
Expand Down Expand Up @@ -69,3 +70,8 @@ class GroupCreatePayload(Model):
[],
title="role IDs",
)


@partial_model()
class GroupUpdatePayload(GroupCreatePayload):
pass
3 changes: 2 additions & 1 deletion lib/galaxy/webapps/galaxy/api/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
GroupCreatePayload,
GroupListResponse,
GroupResponse,
GroupUpdatePayload,
)
from galaxy.webapps.galaxy.api import (
depends,
Expand Down Expand Up @@ -80,8 +81,8 @@ def show(
def update(
self,
group_id: Annotated[DecodedDatabaseIdField, Path(...)],
payload: Annotated[GroupUpdatePayload, Body(...)],
trans: ProvidesAppContext = DependsOnTrans,
payload: GroupCreatePayload = Body(...),
) -> GroupResponse:
return self.manager.update(trans, group_id, payload)

Expand Down

0 comments on commit 488cfe5

Please sign in to comment.