Skip to content

Commit 4ceaa42

Browse files
committed
gets product support group
1 parent 5bb292d commit 4ceaa42

File tree

6 files changed

+62
-51
lines changed

6 files changed

+62
-51
lines changed

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

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,53 @@ class GroupAccessRights(BaseModel):
5454
)
5555

5656

57-
class GroupGet(OutputSchema):
58-
gid: GroupID = Field(..., description="the group ID")
59-
label: str = Field(..., description="the group name")
60-
description: str = Field(..., description="the group description")
61-
thumbnail: AnyUrl | None = Field(
62-
default=None, description="url to the group thumbnail"
63-
)
64-
access_rights: GroupAccessRights = Field(..., alias="accessRights")
57+
class BasicGroupGet(OutputSchema):
58+
gid: Annotated[GroupID, Field(description="the group's unique ID")]
59+
label: Annotated[str, Field(description="the group's display name")]
60+
description: str
61+
thumbnail: Annotated[
62+
AnyUrl | None, Field(description="a link to the group's thumbnail")
63+
] = None
64+
65+
@field_validator("thumbnail", mode="before")
66+
@classmethod
67+
def _sanitize_legacy_data(cls, v):
68+
if v:
69+
# Enforces null if thumbnail is not valid URL or empty
70+
with suppress(ValidationError):
71+
return TypeAdapter(AnyHttpUrl).validate_python(v)
72+
return None
73+
74+
@classmethod
75+
def _extract_basic_group_data(cls, group: Group) -> dict:
76+
"""Extract common group data for schema conversion"""
77+
return remap_keys(
78+
group.model_dump(
79+
include={
80+
"gid",
81+
"name",
82+
"description",
83+
"thumbnail",
84+
},
85+
exclude={
86+
"inclusion_rules", # deprecated
87+
},
88+
exclude_unset=True,
89+
by_alias=False,
90+
),
91+
rename={
92+
"name": "label",
93+
},
94+
)
95+
96+
@classmethod
97+
def from_domain_model(cls, group: Group) -> Self:
98+
# Adapts these domain models into this schema
99+
return cls.model_validate(cls._extract_basic_group_data(group))
100+
101+
102+
class GroupGet(BasicGroupGet):
103+
access_rights: Annotated[GroupAccessRights, Field(alias="accessRights")]
65104

66105
inclusion_rules: Annotated[
67106
dict[str, str],
@@ -77,24 +116,7 @@ def from_domain_model(cls, group: Group, access_rights: AccessRightsDict) -> Sel
77116
# Adapts these domain models into this schema
78117
return cls.model_validate(
79118
{
80-
**remap_keys(
81-
group.model_dump(
82-
include={
83-
"gid",
84-
"name",
85-
"description",
86-
"thumbnail",
87-
},
88-
exclude={
89-
"inclusion_rules", # deprecated
90-
},
91-
exclude_unset=True,
92-
by_alias=False,
93-
),
94-
rename={
95-
"name": "label",
96-
},
97-
),
119+
**cls._extract_basic_group_data(group),
98120
"access_rights": access_rights,
99121
}
100122
)
@@ -136,15 +158,6 @@ def _update_json_schema_extra(schema: JsonDict) -> None:
136158

137159
model_config = ConfigDict(json_schema_extra=_update_json_schema_extra)
138160

139-
@field_validator("thumbnail", mode="before")
140-
@classmethod
141-
def _sanitize_legacy_data(cls, v):
142-
if v:
143-
# Enforces null if thumbnail is not valid URL or empty
144-
with suppress(ValidationError):
145-
return TypeAdapter(AnyHttpUrl).validate_python(v)
146-
return None
147-
148161

149162
class GroupCreate(InputSchema):
150163
label: str
@@ -188,7 +201,7 @@ class MyGroupsGet(OutputSchema):
188201
all: GroupGet
189202
product: GroupGet | None = None
190203
support: Annotated[
191-
GroupGet | None,
204+
BasicGroupGet | None,
192205
Field(
193206
description="Group ID of the app support team or None if no support is defined for this product"
194207
),
@@ -235,7 +248,7 @@ class MyGroupsGet(OutputSchema):
235248
"gid": "2",
236249
"label": "Support Team",
237250
"description": "The support team of the application",
238-
"accessRights": {"read": False, "write": False, "delete": False},
251+
"thumbnail": "https://placekitten.com/15/15",
239252
},
240253
}
241254
}
@@ -246,7 +259,7 @@ def from_domain_model(
246259
cls,
247260
groups_by_type: GroupsByTypeTuple,
248261
my_product_group: tuple[Group, AccessRightsDict] | None,
249-
my_support_group: tuple[Group, AccessRightsDict] | None,
262+
my_support_group: Group | None,
250263
) -> Self:
251264
assert groups_by_type.primary # nosec
252265
assert groups_by_type.everyone # nosec
@@ -263,7 +276,7 @@ def from_domain_model(
263276
else None
264277
),
265278
support=(
266-
GroupGet.from_domain_model(*my_support_group)
279+
BasicGroupGet.from_domain_model(my_support_group)
267280
if my_support_group
268281
else None
269282
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def from_domain_model(
132132
my_groups_by_type: GroupsByTypeTuple,
133133
my_product_group: tuple[Group, AccessRightsDict] | None,
134134
my_preferences: AggregatedPreferences,
135-
my_support_group: tuple[Group, AccessRightsDict] | None,
135+
my_support_group: Group | None,
136136
) -> Self:
137137
data = remap_keys(
138138
my_profile.model_dump(

packages/models-library/tests/test_users.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def test_adapter_from_model_to_schema(
3030
read=False, write=False, delete=False
3131
)
3232

33-
my_support_group = groups[4], AccessRightsDict(
34-
read=False, write=False, delete=False
35-
)
33+
my_support_group = groups[4]
3634

3735
my_preferences = {"foo": Preference(default_value=3, value=1)}
3836

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def list_groups(request: web.Request):
5050
(
5151
groups_by_type,
5252
my_product_group,
53-
my_support_group,
53+
product_support_group,
5454
) = await _groups_service.get_user_profile_groups(
5555
request.app, user_id=req_ctx.user_id, product=product
5656
)
@@ -59,7 +59,7 @@ async def list_groups(request: web.Request):
5959
assert groups_by_type.everyone # nosec
6060

6161
my_groups = MyGroupsGet.from_domain_model(
62-
groups_by_type, my_product_group, my_support_group
62+
groups_by_type, my_product_group, product_support_group
6363
)
6464

6565
return envelope_json_response(my_groups)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async def get_user_profile_groups(
9191
product group, and support group.
9292
9393
Returns:
94-
Tuple of (groups_by_type, my_product_group, my_support_group)
94+
Tuple of (groups_by_type, my_product_group, product_support_group)
9595
"""
9696
groups_by_type = await list_user_groups_with_read_access(app, user_id=user_id)
9797

@@ -104,14 +104,14 @@ async def get_user_profile_groups(
104104
product_gid=product.group_id,
105105
)
106106

107-
my_support_group = None
107+
product_support_group = None
108108
if product.support_standard_group_id: # Support group is optional
109109
# NOTE: my_support_group can be part of groups_by_type.standard!
110-
my_support_group = await get_group_from_gid(
110+
product_support_group = await get_group_from_gid(
111111
app, product.support_standard_group_id
112112
)
113113

114-
return groups_by_type, my_product_group, my_support_group
114+
return groups_by_type, my_product_group, product_support_group
115115

116116

117117
#

services/web/server/src/simcore_service_webserver/users/_controller/rest/users_rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def get_my_profile(request: web.Request) -> web.Response:
5252
(
5353
groups_by_type,
5454
my_product_group,
55-
my_support_group,
55+
product_support_group,
5656
) = await groups_service.get_user_profile_groups(
5757
request.app, user_id=req_ctx.user_id, product=product
5858
)
@@ -65,7 +65,7 @@ async def get_my_profile(request: web.Request) -> web.Response:
6565
)
6666

6767
profile = MyProfileRestGet.from_domain_model(
68-
my_profile, groups_by_type, my_product_group, preferences, my_support_group
68+
my_profile, groups_by_type, my_product_group, preferences, product_support_group
6969
)
7070

7171
return envelope_json_response(profile)

0 commit comments

Comments
 (0)