Skip to content

Commit 5bb292d

Browse files
committed
only group
1 parent adbdb5f commit 5bb292d

File tree

2 files changed

+55
-19
lines changed

2 files changed

+55
-19
lines changed

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,12 @@ async def get_product_group_for_user(
7979
)
8080

8181

82-
async def get_support_group_for_user_or_none(
83-
app: web.Application, *, user_id: UserID, support_gid: GroupID
84-
) -> tuple[Group, AccessRightsDict] | None:
85-
"""
86-
Returns support's group if user belongs to it, otherwise it
87-
"""
88-
with suppress(GroupNotFoundError):
89-
return await _groups_repository.get_any_group_for_user(
90-
app, user_id=user_id, group_gid=support_gid
91-
)
92-
return None
93-
94-
9582
async def get_user_profile_groups(
9683
app: web.Application, *, user_id: UserID, product: Product
9784
) -> tuple[
9885
GroupsByTypeTuple,
9986
tuple[Group, AccessRightsDict] | None,
100-
tuple[Group, AccessRightsDict] | None,
87+
Group | None,
10188
]:
10289
"""
10390
Get all groups needed for user profile including standard groups,
@@ -120,10 +107,8 @@ async def get_user_profile_groups(
120107
my_support_group = None
121108
if product.support_standard_group_id: # Support group is optional
122109
# NOTE: my_support_group can be part of groups_by_type.standard!
123-
my_support_group = await get_support_group_for_user_or_none(
124-
app=app,
125-
user_id=user_id,
126-
support_gid=product.support_standard_group_id,
110+
my_support_group = await get_group_from_gid(
111+
app, product.support_standard_group_id
127112
)
128113

129114
return groups_by_type, my_product_group, my_support_group

services/web/server/tests/unit/with_dbs/03/test_users_rest_profile.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88

99
import functools
10+
from collections.abc import Iterator
1011
from copy import deepcopy
1112
from http import HTTPStatus
1213
from typing import Any
1314
from unittest.mock import patch
1415

1516
import pytest
17+
import sqlalchemy as sa
1618
from aiohttp.test_utils import TestClient
1719
from aiopg.sa.connection import SAConnection
1820
from common_library.users_enums import UserRole
@@ -22,6 +24,7 @@
2224
from psycopg2 import OperationalError
2325
from pytest_simcore.helpers.assert_checks import assert_status
2426
from pytest_simcore.helpers.monkeypatch_envs import EnvVarsDict, setenvs_from_dict
27+
from pytest_simcore.helpers.postgres_tools import sync_insert_and_get_row_lifespan
2528
from pytest_simcore.helpers.webserver_users import UserInfoDict
2629
from servicelib.aiohttp import status
2730
from servicelib.rest_constants import RESPONSE_MODEL_POLICY
@@ -47,6 +50,41 @@ def app_environment(
4750
)
4851

4952

53+
@pytest.fixture(scope="module")
54+
def support_group(
55+
postgres_db: sa.engine.Engine,
56+
product_name: str,
57+
) -> Iterator[dict[str, Any]]:
58+
"""Creates a standard support group and assigns it to the current product"""
59+
from simcore_postgres_database.models.groups import groups
60+
from simcore_postgres_database.models.products import products
61+
62+
# Create support group using direct database insertion
63+
group_values = {
64+
"name": "Support Group",
65+
"description": "Support group for product",
66+
"type": "STANDARD",
67+
}
68+
69+
with sync_insert_and_get_row_lifespan(
70+
postgres_db,
71+
table=groups,
72+
values=group_values,
73+
pk_col=groups.c.gid,
74+
) as group_row:
75+
group_id = group_row["gid"]
76+
77+
# Update product to set support_standard_group_id
78+
with postgres_db.begin() as conn:
79+
conn.execute(
80+
sa.update(products)
81+
.where(products.c.name == product_name)
82+
.values(support_standard_group_id=group_id)
83+
)
84+
85+
yield group_row
86+
87+
5088
@pytest.mark.parametrize(
5189
"user_role,expected",
5290
[
@@ -100,6 +138,7 @@ async def test_get_profile(
100138
primary_group: dict[str, Any],
101139
standard_groups: list[dict[str, Any]],
102140
all_group: dict[str, str],
141+
support_group: dict[str, Any],
103142
):
104143
assert client.app
105144

@@ -130,13 +169,25 @@ async def test_get_profile(
130169
"thumbnail": None,
131170
}
132171

133-
assert got_profile_groups["support"] is None
172+
# support group exists
173+
assert got_profile_groups["support"]
174+
support_group_id = got_profile_groups["support"]["gid"]
134175

176+
assert support_group_id == support_group["gid"]
177+
assert got_profile_groups["support"]["description"] == support_group["description"]
178+
assert "accessRights" not in got_profile_groups["support"]
179+
180+
# standard groups with at least read access
135181
sorted_by_group_id = functools.partial(sorted, key=lambda d: d["gid"])
136182
assert sorted_by_group_id(
137183
got_profile_groups["organizations"]
138184
) == sorted_by_group_id(standard_groups)
139185

186+
# user is NOT part of the support group
187+
all_standard_groups_ids = {g["gid"] for g in standard_groups}
188+
assert support_group_id not in all_standard_groups_ids
189+
190+
# preferences
140191
assert profile.preferences == await get_frontend_user_preferences_aggregation(
141192
client.app, user_id=logged_user["id"], product_name="osparc"
142193
)

0 commit comments

Comments
 (0)