Skip to content

Commit 37d35db

Browse files
committed
@sanderegg review:drop organization and renames
1 parent b020206 commit 37d35db

File tree

9 files changed

+76
-70
lines changed

9 files changed

+76
-70
lines changed

packages/models-library/src/models_library/api_schemas_webserver/groups.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
AccessRightsDict,
2121
Group,
2222
GroupMember,
23-
OrganizationCreate,
24-
OrganizationUpdate,
23+
StandardGroupCreate,
24+
StandardGroupUpdate,
2525
)
2626
from ..users import UserID
2727
from ..utils.common_validators import create__check_only_one_is_set__root_validator
@@ -147,25 +147,25 @@ class GroupCreate(InputSchema):
147147
description: str
148148
thumbnail: AnyUrl | None = None
149149

150-
def to_model(self) -> OrganizationCreate:
150+
def to_model(self) -> StandardGroupCreate:
151151
data = _rename_keys(
152152
self.model_dump(mode="json", exclude_unset=True),
153153
name_map={"label": "name"},
154154
)
155-
return OrganizationCreate(**data)
155+
return StandardGroupCreate(**data)
156156

157157

158158
class GroupUpdate(InputSchema):
159159
label: str | None = None
160160
description: str | None = None
161161
thumbnail: AnyUrl | None = None
162162

163-
def to_model(self) -> OrganizationUpdate:
163+
def to_model(self) -> StandardGroupUpdate:
164164
data = _rename_keys(
165165
self.model_dump(mode="json", exclude_unset=True),
166166
name_map={"label": "name"},
167167
)
168-
return OrganizationUpdate(**data)
168+
return StandardGroupUpdate(**data)
169169

170170

171171
class MyGroupsGet(OutputSchema):

packages/models-library/src/models_library/groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ class GroupMember(BaseModel):
7878
model_config = ConfigDict(from_attributes=True)
7979

8080

81-
class OrganizationCreate(BaseModel):
81+
class StandardGroupCreate(BaseModel):
8282
name: str
8383
description: str | None = None
8484
thumbnail: str | None = None
8585

8686

87-
class OrganizationUpdate(BaseModel):
87+
class StandardGroupUpdate(BaseModel):
8888
name: str | None = None
8989
description: str | None = None
9090
thumbnail: str | None = None

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
from aiohttp import web
1717
from aiohttp.test_utils import TestClient
1818
from models_library.api_schemas_webserver.groups import GroupGet
19-
from models_library.groups import GroupsByTypeTuple, OrganizationCreate
19+
from models_library.groups import GroupsByTypeTuple, StandardGroupCreate
2020
from models_library.users import UserID
2121
from pytest_simcore.helpers.webserver_login import NewUser, UserInfoDict
2222
from simcore_service_webserver.groups._groups_api import (
2323
add_user_in_group,
2424
create_standard_group,
25-
delete_group,
25+
delete_standard_group,
2626
list_user_groups_with_read_access,
2727
)
2828

@@ -37,7 +37,7 @@ async def _create_organization(
3737
group, access_rights = await create_standard_group(
3838
app,
3939
user_id=user_id,
40-
create=OrganizationCreate.model_validate(new_group),
40+
create=StandardGroupCreate.model_validate(new_group),
4141
)
4242
return _groupget_model_dump(group=group, access_rights=access_rights)
4343

@@ -107,10 +107,10 @@ async def standard_groups_owner(
107107
yield owner_user
108108

109109
# clean groups
110-
await delete_group(
110+
await delete_standard_group(
111111
client.app, user_id=owner_user["id"], group_id=sparc_group["gid"]
112112
)
113-
await delete_group(
113+
await delete_standard_group(
114114
client.app, user_id=owner_user["id"], group_id=team_black_group["gid"]
115115
)
116116

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
Group,
77
GroupMember,
88
GroupsByTypeTuple,
9-
OrganizationCreate,
10-
OrganizationUpdate,
9+
StandardGroupCreate,
10+
StandardGroupUpdate,
1111
)
1212
from models_library.products import ProductName
1313
from models_library.users import GroupID, UserID
@@ -87,19 +87,20 @@ async def get_product_group_for_user(
8787

8888

8989
#
90-
# ORGANIZATIONS CRUD operations
90+
# CRUD operations on groups linked to a user
9191
#
9292

9393

9494
async def create_standard_group(
9595
app: web.Application,
9696
*,
9797
user_id: UserID,
98-
create: OrganizationCreate,
98+
create: StandardGroupCreate,
9999
) -> tuple[Group, AccessRightsDict]:
100-
"""
100+
"""NOTE: creation/update and deletion restricted to STANDARD groups
101+
101102
raises GroupNotFoundError
102-
raises UserInsufficientRightsError
103+
raises UserInsufficientRightsError: needs WRITE access
103104
"""
104105
return await _groups_db.create_standard_group(
105106
app,
@@ -108,65 +109,66 @@ async def create_standard_group(
108109
)
109110

110111

111-
async def get_organization(
112+
async def get_associated_group(
112113
app: web.Application,
113114
*,
114115
user_id: UserID,
115116
group_id: GroupID,
116117
) -> tuple[Group, AccessRightsDict]:
117118
"""
118-
Gets group gid if user associated to it and has read access
119119
120120
raises GroupNotFoundError
121-
raises UserInsufficientRightsError
121+
raises UserInsufficientRightsError: needs READ access
122122
"""
123-
return await _groups_db.get_user_group(app, user_id=user_id, group_9d=group_id)
123+
return await _groups_db.get_user_group(app, user_id=user_id, group_id=group_id)
124124

125125

126-
async def update_group(
126+
async def update_standard_group(
127127
app: web.Application,
128128
*,
129129
user_id: UserID,
130130
group_id: GroupID,
131-
update: OrganizationUpdate,
131+
update: StandardGroupUpdate,
132132
) -> tuple[Group, AccessRightsDict]:
133-
"""
133+
"""NOTE: creation/update and deletion restricted to STANDARD groups
134134
135135
raises GroupNotFoundError
136-
raises UserInsufficientRightsError
136+
raises UserInsufficientRightsError: needs WRITE access
137137
"""
138138

139-
return await _groups_db.update_user_group(
139+
return await _groups_db.update_standard_group(
140140
app,
141141
user_id=user_id,
142142
group_id=group_id,
143143
update=update,
144144
)
145145

146146

147-
async def delete_group(
147+
async def delete_standard_group(
148148
app: web.Application, *, user_id: UserID, group_id: GroupID
149149
) -> None:
150-
"""
150+
"""NOTE: creation/update and deletion restricted to STANDARD groups
151151
152152
raises GroupNotFoundError
153-
raises UserInsufficientRightsError
153+
raises UserInsufficientRightsError: needs DELETE access
154154
"""
155-
return await _groups_db.delete_user_group(app, user_id=user_id, group_id=group_id)
155+
return await _groups_db.delete_standard_group(
156+
app, user_id=user_id, group_id=group_id
157+
)
156158

157159

158160
#
159-
# ORGANIZATION MEMBERS
161+
# GROUP MEMBERS (= a user with some access-rights to a group)
160162
#
161163

162164

163-
async def list_users_in_group(
165+
async def list_group_members(
164166
app: web.Application, user_id: UserID, group_id: GroupID
165167
) -> list[GroupMember]:
166168
return await _groups_db.list_users_in_group(app, user_id=user_id, group_id=group_id)
167169

168170

169-
async def get_user_in_group(
171+
async def get_group_member(
170172
app: web.Application,
171173
user_id: UserID,
172174
group_id: GroupID,
@@ -181,7 +183,7 @@ async def get_user_in_group(
181183
)
182184

183185

184-
async def update_user_in_group(
186+
async def update_group_member(
185187
app: web.Application,
186188
user_id: UserID,
187189
group_id: GroupID,
@@ -197,7 +199,7 @@ async def update_user_in_group(
197199
)
198200

199201

200-
async def delete_user_in_group(
202+
async def delete_group_member(
201203
app: web.Application,
202204
user_id: UserID,
203205
group_id: GroupID,

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
GroupInfoTuple,
1111
GroupMember,
1212
GroupsByTypeTuple,
13-
OrganizationCreate,
14-
OrganizationUpdate,
13+
StandardGroupCreate,
14+
StandardGroupUpdate,
1515
)
1616
from models_library.users import GroupID, UserID
1717
from simcore_postgres_database.errors import UniqueViolation
@@ -208,7 +208,7 @@ async def get_user_group(
208208
connection: AsyncConnection | None = None,
209209
*,
210210
user_id: UserID,
211-
group_9d: GroupID,
211+
group_id: GroupID,
212212
) -> tuple[Group, AccessRightsDict]:
213213
"""
214214
Gets group gid if user associated to it and has read access
@@ -218,9 +218,9 @@ async def get_user_group(
218218
"""
219219
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
220220
row = await _get_group_and_access_rights_or_raise(
221-
conn, user_id=user_id, gid=group_9d
221+
conn, user_id=user_id, gid=group_id
222222
)
223-
_check_group_permissions(row, user_id, group_9d, "read")
223+
_check_group_permissions(row, user_id, group_id, "read")
224224

225225
group, access_rights = _to_group_info_tuple(row)
226226
return group, access_rights
@@ -245,15 +245,15 @@ async def get_product_group_for_user(
245245
return group, access_rights
246246

247247

248-
assert set(OrganizationCreate.model_fields).issubset({c.name for c in groups.columns})
248+
assert set(StandardGroupCreate.model_fields).issubset({c.name for c in groups.columns})
249249

250250

251251
async def create_standard_group(
252252
app: web.Application,
253253
connection: AsyncConnection | None = None,
254254
*,
255255
user_id: UserID,
256-
create: OrganizationCreate,
256+
create: StandardGroupCreate,
257257
) -> tuple[Group, AccessRightsDict]:
258258

259259
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
@@ -288,16 +288,16 @@ async def create_standard_group(
288288
return group, deepcopy(_DEFAULT_GROUP_OWNER_ACCESS_RIGHTS)
289289

290290

291-
assert set(OrganizationUpdate.model_fields).issubset({c.name for c in groups.columns})
291+
assert set(StandardGroupUpdate.model_fields).issubset({c.name for c in groups.columns})
292292

293293

294-
async def update_user_group(
294+
async def update_standard_group(
295295
app: web.Application,
296296
connection: AsyncConnection | None = None,
297297
*,
298298
user_id: UserID,
299299
group_id: GroupID,
300-
update: OrganizationUpdate,
300+
update: StandardGroupUpdate,
301301
) -> tuple[Group, AccessRightsDict]:
302302

303303
values = update.model_dump(mode="json", exclude_unset=True)
@@ -314,7 +314,7 @@ async def update_user_group(
314314
# pylint: disable=no-value-for-parameter
315315
groups.update()
316316
.values(**values)
317-
.where(groups.c.gid == row.gid)
317+
.where((groups.c.gid == row.gid) & (groups.c.type == GroupType.STANDARD))
318318
.returning(*_GROUP_COLUMNS)
319319
)
320320
row = await result.fetchone()
@@ -324,7 +324,7 @@ async def update_user_group(
324324
return group, access_rights
325325

326326

327-
async def delete_user_group(
327+
async def delete_standard_group(
328328
app: web.Application,
329329
connection: AsyncConnection | None = None,
330330
*,
@@ -339,7 +339,9 @@ async def delete_user_group(
339339

340340
await conn.execute(
341341
# pylint: disable=no-value-for-parameter
342-
groups.delete().where(groups.c.gid == group.gid)
342+
groups.delete().where(
343+
(groups.c.gid == group.gid) & (groups.c.type == GroupType.STANDARD)
344+
)
343345
)
344346

345347

0 commit comments

Comments
 (0)