Skip to content

Commit aaf9c4a

Browse files
committed
gid
1 parent 98e846f commit aaf9c4a

File tree

6 files changed

+59
-38
lines changed

6 files changed

+59
-38
lines changed

packages/pytest-simcore/src/pytest_simcore/simcore_webserver_groups_fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ async def standard_groups_owner(
9393
await add_user_in_group(
9494
app=client.app,
9595
user_id=owner_user["id"],
96-
gid=sparc_group["gid"],
96+
group_id=sparc_group["gid"],
9797
new_user_id=logged_user["id"],
9898
)
9999

100100
# adds logged_user to team-black group
101101
await add_user_in_group(
102102
app=client.app,
103103
user_id=owner_user["id"],
104-
gid=team_black_group["gid"],
104+
group_id=team_black_group["gid"],
105105
new_user_email=logged_user["email"],
106106
)
107107

services/web/server/src/simcore_service_webserver/garbage_collector/_core_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def get_new_project_owner_gid(
7878
standard_groups = {} # groups of users, multiple users can be part of this
7979
primary_groups = {} # each individual user has a unique primary group
8080
for other_gid in other_users_access_rights:
81-
group: Group | None = await get_group_from_gid(app=app, gid=int(other_gid))
81+
group: Group | None = await get_group_from_gid(app=app, group_id=int(other_gid))
8282

8383
# only process for users and groups with write access right
8484
if group is None:

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#
2222

2323

24-
async def get_group_from_gid(app: web.Application, gid: GroupID) -> Group | None:
25-
group_db = await _groups_db.get_group_from_gid(app, gid=gid)
24+
async def get_group_from_gid(app: web.Application, group_id: GroupID) -> Group | None:
25+
group_db = await _groups_db.get_group_from_gid(app, group_id=group_id)
2626

2727
if group_db:
2828
return Group.model_construct(**group_db.model_dump())
@@ -119,7 +119,7 @@ async def get_organization(
119119
raises GroupNotFoundError
120120
raises UserInsufficientRightsError
121121
"""
122-
return await _groups_db.get_user_group(app, user_id=user_id, gid=group_id)
122+
return await _groups_db.get_user_group(app, user_id=user_id, group_9d=group_id)
123123

124124

125125
async def update_organization(
@@ -160,34 +160,37 @@ async def delete_organization(
160160

161161

162162
async def list_users_in_group(
163-
app: web.Application, user_id: UserID, gid: GroupID
163+
app: web.Application, user_id: UserID, group_id: GroupID
164164
) -> list[GroupMember]:
165-
return await _groups_db.list_users_in_group(app, user_id=user_id, group_id=gid)
165+
return await _groups_db.list_users_in_group(app, user_id=user_id, group_id=group_id)
166166

167167

168168
async def get_user_in_group(
169169
app: web.Application,
170170
user_id: UserID,
171-
gid: GroupID,
171+
group_id: GroupID,
172172
the_user_id_in_group: UserID,
173173
) -> GroupMember:
174174

175175
return await _groups_db.get_user_in_group(
176-
app, user_id=user_id, group_id=gid, the_user_id_in_group=the_user_id_in_group
176+
app,
177+
user_id=user_id,
178+
group_id=group_id,
179+
the_user_id_in_group=the_user_id_in_group,
177180
)
178181

179182

180183
async def update_user_in_group(
181184
app: web.Application,
182185
user_id: UserID,
183-
gid: GroupID,
186+
group_id: GroupID,
184187
the_user_id_in_group: UserID,
185188
access_rights: AccessRightsDict,
186189
) -> GroupMember:
187190
return await _groups_db.update_user_in_group(
188191
app,
189192
user_id=user_id,
190-
gid=gid,
193+
group_id=group_id,
191194
the_user_id_in_group=the_user_id_in_group,
192195
access_rights=access_rights,
193196
)
@@ -196,11 +199,14 @@ async def update_user_in_group(
196199
async def delete_user_in_group(
197200
app: web.Application,
198201
user_id: UserID,
199-
gid: GroupID,
202+
group_id: GroupID,
200203
the_user_id_in_group: UserID,
201204
) -> None:
202205
return await _groups_db.delete_user_from_group(
203-
app, user_id=user_id, gid=gid, the_user_id_in_group=the_user_id_in_group
206+
app,
207+
user_id=user_id,
208+
group_id=group_id,
209+
the_user_id_in_group=the_user_id_in_group,
204210
)
205211

206212

@@ -233,7 +239,7 @@ async def auto_add_user_to_product_group(
233239
async def add_user_in_group(
234240
app: web.Application,
235241
user_id: UserID,
236-
gid: GroupID,
242+
group_id: GroupID,
237243
*,
238244
new_user_id: UserID | None = None,
239245
new_user_email: EmailStr | None = None,
@@ -250,6 +256,7 @@ async def add_user_in_group(
250256
msg = "Invalid method call, missing user id or user email"
251257
raise GroupsError(msg=msg)
252258

259+
# FIXME: check privacy
253260
if new_user_email:
254261
user = await _groups_db.get_user_from_email(app, email=new_user_email)
255262
new_user_id = user.id
@@ -261,7 +268,7 @@ async def add_user_in_group(
261268
return await _groups_db.add_new_user_in_group(
262269
app,
263270
user_id=user_id,
264-
gid=gid,
271+
group_id=group_id,
265272
new_user_id=new_user_id,
266273
access_rights=access_rights,
267274
)

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

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ async def get_user_from_email(
121121
UserNotFoundError
122122
123123
"""
124+
# FIXME: check privacy
125+
124126
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
125127
result = await conn.stream(sa.select(users).where(users.c.email == email))
126128
user = await result.fetchone()
@@ -135,10 +137,13 @@ async def get_user_from_email(
135137

136138

137139
async def get_group_from_gid(
138-
app: web.Application, connection: AsyncConnection | None = None, *, gid: GroupID
140+
app: web.Application,
141+
connection: AsyncConnection | None = None,
142+
*,
143+
group_id: GroupID,
139144
) -> Group | None:
140145
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
141-
row = await conn.stream(groups.select().where(groups.c.gid == gid))
146+
row = await conn.stream(groups.select().where(groups.c.gid == group_id))
142147
result = await row.first()
143148
if result:
144149
return Group.model_validate(result)
@@ -219,7 +224,7 @@ async def get_user_group(
219224
connection: AsyncConnection | None = None,
220225
*,
221226
user_id: UserID,
222-
gid: GroupID,
227+
group_9d: GroupID,
223228
) -> tuple[Group, AccessRightsDict]:
224229
"""
225230
Gets group gid if user associated to it and has read access
@@ -229,9 +234,9 @@ async def get_user_group(
229234
"""
230235
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
231236
row = await _get_group_and_access_rights_or_raise(
232-
conn, user_id=user_id, gid=gid
237+
conn, user_id=user_id, gid=group_9d
233238
)
234-
_check_group_permissions(row, user_id, gid, "read")
239+
_check_group_permissions(row, user_id, group_9d, "read")
235240

236241
group, access_rights = _to_group_info_tuple(row)
237242
return group, access_rights
@@ -463,7 +468,7 @@ async def update_user_in_group(
463468
connection: AsyncConnection | None = None,
464469
*,
465470
user_id: UserID,
466-
gid: GroupID,
471+
group_id: GroupID,
467472
the_user_id_in_group: UserID,
468473
access_rights: AccessRightsDict,
469474
) -> GroupMember:
@@ -475,13 +480,16 @@ async def update_user_in_group(
475480

476481
# first check if the group exists
477482
group = await _get_group_and_access_rights_or_raise(
478-
conn, user_id=user_id, gid=gid
483+
conn, user_id=user_id, gid=group_id
479484
)
480-
_check_group_permissions(group, user_id, gid, "write")
485+
_check_group_permissions(group, user_id, group_id, "write")
481486

482487
# now check the user exists
483488
the_user = await _get_user_in_group(
484-
conn, caller_user_id=user_id, group_id=gid, user_id=the_user_id_in_group
489+
conn,
490+
caller_user_id=user_id,
491+
group_id=group_id,
492+
user_id=the_user_id_in_group,
485493
)
486494

487495
# modify the user access rights
@@ -493,7 +501,7 @@ async def update_user_in_group(
493501
.where(
494502
and_(
495503
user_to_groups.c.uid == the_user_id_in_group,
496-
user_to_groups.c.gid == gid,
504+
user_to_groups.c.gid == group_id,
497505
)
498506
)
499507
)
@@ -507,19 +515,22 @@ async def delete_user_from_group(
507515
connection: AsyncConnection | None = None,
508516
*,
509517
user_id: UserID,
510-
gid: GroupID,
518+
group_id: GroupID,
511519
the_user_id_in_group: UserID,
512520
) -> None:
513521
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
514522
# first check if the group exists
515523
group = await _get_group_and_access_rights_or_raise(
516-
conn, user_id=user_id, gid=gid
524+
conn, user_id=user_id, gid=group_id
517525
)
518-
_check_group_permissions(group, user_id, gid, "write")
526+
_check_group_permissions(group, user_id, group_id, "write")
519527

520528
# check the user exists
521529
await _get_user_in_group(
522-
conn, caller_user_id=user_id, group_id=gid, user_id=the_user_id_in_group
530+
conn,
531+
caller_user_id=user_id,
532+
group_id=group_id,
533+
user_id=the_user_id_in_group,
523534
)
524535

525536
# delete him/her
@@ -528,7 +539,7 @@ async def delete_user_from_group(
528539
user_to_groups.delete().where(
529540
and_(
530541
user_to_groups.c.uid == the_user_id_in_group,
531-
user_to_groups.c.gid == gid,
542+
user_to_groups.c.gid == group_id,
532543
)
533544
)
534545
)
@@ -562,7 +573,7 @@ async def add_new_user_in_group(
562573
connection: AsyncConnection | None = None,
563574
*,
564575
user_id: UserID,
565-
gid: GroupID,
576+
group_id: GroupID,
566577
new_user_id: UserID,
567578
access_rights: AccessRightsDict | None = None,
568579
) -> None:
@@ -572,17 +583,17 @@ async def add_new_user_in_group(
572583
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
573584
# first check if the group exists
574585
group = await _get_group_and_access_rights_or_raise(
575-
conn, user_id=user_id, gid=gid
586+
conn, user_id=user_id, gid=group_id
576587
)
577-
_check_group_permissions(group, user_id, gid, "write")
588+
_check_group_permissions(group, user_id, group_id, "write")
578589

579590
# now check the new user exists
580591
users_count = await conn.scalar(
581592
sa.select(sa.func.count()).where(users.c.id == new_user_id)
582593
)
583594
if not users_count:
584595
assert new_user_id is not None # nosec
585-
raise UserInGroupNotFoundError(uid=new_user_id, gid=gid)
596+
raise UserInGroupNotFoundError(uid=new_user_id, gid=group_id)
586597

587598
# add the new user to the group now
588599
user_access_rights = _DEFAULT_GROUP_READ_ACCESS_RIGHTS
@@ -598,7 +609,10 @@ async def add_new_user_in_group(
598609
)
599610
except UniqueViolation as exc:
600611
raise UserAlreadyInGroupError(
601-
uid=new_user_id, gid=gid, user_id=user_id, access_rights=access_rights
612+
uid=new_user_id,
613+
gid=group_id,
614+
user_id=user_id,
615+
access_rights=access_rights,
602616
) from exc
603617

604618

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ async def update_group_user(request: web.Request):
227227
user = await _groups_api.update_user_in_group(
228228
request.app,
229229
user_id=req_ctx.user_id,
230-
gid=path_params.gid,
230+
group_id=path_params.gid,
231231
the_user_id_in_group=path_params.uid,
232232
access_rights=update.access_rights.model_dump(mode="json"), # type: ignore[arg-type]
233233
)

services/web/server/src/simcore_service_webserver/projects/_nodes_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ async def get_project_services_access_for_gid(
559559

560560
# Get the group from the provided group ID
561561
_sharing_with_group: Group | None = await get_group_from_gid(
562-
app=request.app, gid=query_params.for_gid
562+
app=request.app, group_id=query_params.for_gid
563563
)
564564

565565
# Check if the group exists

0 commit comments

Comments
 (0)