Skip to content

Commit 68fc0fc

Browse files
committed
separate access rights in repo
1 parent 1e1c244 commit 68fc0fc

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

services/web/server/src/simcore_service_webserver/groups/_groups_repository.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,26 @@ async def delete_user_from_group(
679679
#
680680

681681

682+
async def check_group_write_access(
683+
app: web.Application,
684+
connection: AsyncConnection | None = None,
685+
*,
686+
caller_id: UserID,
687+
group_id: GroupID,
688+
) -> None:
689+
"""
690+
Checks if caller has write access to the group.
691+
692+
Raises:
693+
GroupNotFoundError: if group not found or caller has no access
694+
UserInsufficientRightsError: if caller has no write permission
695+
"""
696+
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
697+
await _get_group_and_access_rights_or_raise(
698+
conn, caller_id=caller_id, group_id=group_id, check_permission="write"
699+
)
700+
701+
682702
async def is_user_by_email_in_group(
683703
app: web.Application,
684704
connection: AsyncConnection | None = None,
@@ -701,22 +721,18 @@ async def add_new_user_in_group(
701721
app: web.Application,
702722
connection: AsyncConnection | None = None,
703723
*,
704-
caller_id: UserID,
705724
group_id: GroupID,
706725
# either user_id or user_name
707726
new_user_id: UserID | None = None,
708727
new_user_name: IDStr | None = None,
709728
access_rights: AccessRightsDict | None = None,
710729
) -> None:
711730
"""
712-
adds new_user (either by id or email) in group (with gid) owned by user_id
731+
adds new_user (either by id or email) in group (with gid)
732+
733+
Note: This function does not check permissions - caller must ensure permissions are checked separately
713734
"""
714735
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
715-
# first check if the group exists
716-
await _get_group_and_access_rights_or_raise(
717-
conn, caller_id=caller_id, group_id=group_id, check_permission="write"
718-
)
719-
720736
query = sa.select(users.c.id)
721737
if new_user_id is not None:
722738
query = query.where(users.c.id == new_user_id)
@@ -747,7 +763,6 @@ async def add_new_user_in_group(
747763
raise UserAlreadyInGroupError(
748764
uid=new_user_id,
749765
gid=group_id,
750-
user_id=caller_id,
751766
access_rights=access_rights,
752767
) from exc
753768

services/web/server/src/simcore_service_webserver/groups/_groups_service.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,18 @@ async def add_user_in_group(
297297
Raises:
298298
UserInGroupNotFoundError
299299
GroupsException
300+
GroupNotFoundError
301+
UserInsufficientRightsError
300302
"""
301303
if not _only_one_true(new_by_user_id, new_by_user_name, new_by_user_email):
302304
msg = "Invalid method call, required one of these: user id, username or user email, none provided"
303305
raise GroupsError(msg=msg)
304306

307+
# First check if caller has write access to the group
308+
await _groups_repository.check_group_write_access(
309+
app, caller_id=user_id, group_id=group_id
310+
)
311+
305312
# get target user to add to group
306313
if new_by_user_email:
307314
user = await _groups_repository.get_user_from_email(

0 commit comments

Comments
 (0)