Skip to content

Commit 8f96782

Browse files
🐛 fix list_users_in_group introduced in previous PR (#8249)
1 parent c1c5d79 commit 8f96782

File tree

3 files changed

+84
-9
lines changed

3 files changed

+84
-9
lines changed

services/web/server/src/simcore_service_webserver/conversations/_controller/_conversations_messages_rest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ async def create_conversation_message(request: web.Request):
117117
request, template_name
118118
)
119119
_url = request.url
120-
if _url.port:
121-
_conversation_url = f"{_url.scheme}://{_url.host}:{_url.port}/#/conversations/{path_params.conversation_id}"
122-
else:
123-
_conversation_url = f"{_url.scheme}://{_url.host}/#/conversations/{path_params.conversation_id}"
120+
_conversation_url = f"{_url.scheme}://{_url.host}/#/conversation/{path_params.conversation_id}"
124121
_extra_context = _conversation.extra_context
125122
await email_service.send_email_from_template(
126123
request,

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,16 @@ async def list_users_in_group(
550550

551551
# Get all users in the group
552552
query = (
553-
sa.select(*_GROUP_COLUMNS)
554-
.select_from(
555-
groups.join(
556-
user_to_groups, user_to_groups.c.gid == groups.c.gid, isouter=True
557-
).join(users, users.c.id == user_to_groups.c.uid)
553+
sa.select(
554+
users.c.id,
555+
users.c.name,
556+
users.c.email,
557+
users.c.first_name,
558+
users.c.last_name,
559+
users.c.primary_gid,
560+
# user_to_groups.c.access_rights, # <-- currently not neccessary, might be added if needed
558561
)
562+
.select_from(users.join(user_to_groups, users.c.id == user_to_groups.c.uid))
559563
.where(user_to_groups.c.gid == group_id)
560564
)
561565

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=too-many-arguments
3+
# pylint: disable=unused-argument
4+
# pylint: disable=unused-variable
5+
6+
from collections.abc import AsyncGenerator, Callable, Coroutine
7+
from typing import Any
8+
9+
import pytest
10+
from aiohttp.test_utils import TestClient
11+
from models_library.groups import GroupMember, StandardGroupCreate
12+
from pytest_simcore.helpers.webserver_users import UserInfoDict
13+
from simcore_postgres_database.models.users import UserRole
14+
from simcore_service_webserver.groups import _groups_repository
15+
16+
17+
@pytest.fixture
18+
async def create_test_group(
19+
client: TestClient, logged_user: UserInfoDict
20+
) -> AsyncGenerator[Callable[..., Coroutine[Any, Any, Any]], None]:
21+
"""Fixture that creates a standard group and ensures cleanup."""
22+
created_groups = []
23+
24+
async def _create_group(
25+
name: str = "Test Group",
26+
description: str = "A test group",
27+
thumbnail: str | None = None,
28+
):
29+
group, _ = await _groups_repository.create_standard_group(
30+
app=client.app,
31+
user_id=logged_user["id"],
32+
create=StandardGroupCreate(
33+
name=name,
34+
description=description,
35+
thumbnail=thumbnail,
36+
),
37+
)
38+
created_groups.append(group)
39+
return group
40+
41+
yield _create_group
42+
43+
# Cleanup all created groups
44+
for group in created_groups:
45+
await _groups_repository.delete_standard_group(
46+
app=client.app, user_id=logged_user["id"], group_id=group.gid
47+
)
48+
49+
50+
@pytest.mark.parametrize("user_role", [UserRole.USER])
51+
async def test_list_users_in_group_owner_only(
52+
client: TestClient,
53+
user_role: UserRole,
54+
logged_user: UserInfoDict,
55+
create_test_group: Callable[..., Coroutine[Any, Any, Any]],
56+
):
57+
"""Test list_users_in_group returns only the owner for a new group."""
58+
assert client.app
59+
60+
# Create a standard group
61+
group = await create_test_group(
62+
name="Test Owner Only Group",
63+
description="A test group to check owner-only user list",
64+
)
65+
66+
# List users in the group - should only contain the owner
67+
users_in_group = await _groups_repository.list_users_in_group(
68+
app=client.app, group_id=group.gid
69+
)
70+
71+
# Should contain exactly one user (the owner)
72+
assert len(users_in_group) == 1
73+
assert isinstance(users_in_group[0], GroupMember)
74+
assert users_in_group[0].id == logged_user["id"]

0 commit comments

Comments
 (0)