Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ async def create_conversation_message(request: web.Request):
)
_url = request.url
if _url.port:
_conversation_url = f"{_url.scheme}://{_url.host}:{_url.port}/#/conversations/{path_params.conversation_id}"
_conversation_url = f"{_url.scheme}://{_url.host}:{_url.port}/#/conversation/{path_params.conversation_id}"
else:
_conversation_url = f"{_url.scheme}://{_url.host}/#/conversations/{path_params.conversation_id}"
_conversation_url = f"{_url.scheme}://{_url.host}/#/conversation/{path_params.conversation_id}"
_extra_context = _conversation.extra_context
await email_service.send_email_from_template(
request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,16 @@ async def list_users_in_group(

# Get all users in the group
query = (
sa.select(*_GROUP_COLUMNS)
.select_from(
groups.join(
user_to_groups, user_to_groups.c.gid == groups.c.gid, isouter=True
).join(users, users.c.id == user_to_groups.c.uid)
sa.select(
users.c.id,
users.c.name,
users.c.email,
users.c.first_name,
users.c.last_name,
users.c.primary_gid,
# user_to_groups.c.access_rights, # <-- currently not neccessary, might be added if needed
)
.select_from(users.join(user_to_groups, users.c.id == user_to_groups.c.uid))
.where(user_to_groups.c.gid == group_id)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# pylint: disable=redefined-outer-name
# pylint: disable=too-many-arguments
# pylint: disable=unused-argument
# pylint: disable=unused-variable

from collections.abc import AsyncGenerator, Callable, Coroutine
from typing import Any

import pytest
from aiohttp.test_utils import TestClient
from models_library.groups import GroupMember, StandardGroupCreate
from pytest_simcore.helpers.webserver_users import UserInfoDict
from simcore_postgres_database.models.users import UserRole
from simcore_service_webserver.groups._groups_repository import (
create_standard_group,
delete_standard_group,
list_users_in_group,
)


@pytest.fixture
async def create_test_group(
client: TestClient, logged_user: UserInfoDict
) -> AsyncGenerator[Callable[..., Coroutine[Any, Any, Any]], None]:
"""Fixture that creates a standard group and ensures cleanup."""
created_groups = []

async def _create_group(
name: str = "Test Group",
description: str = "A test group",
thumbnail: str | None = None,
):
group, _ = await create_standard_group(
app=client.app,
user_id=logged_user["id"],
create=StandardGroupCreate(
name=name,
description=description,
thumbnail=thumbnail,
),
)
created_groups.append(group)
return group

yield _create_group

# Cleanup all created groups
for group in created_groups:
await delete_standard_group(
app=client.app, user_id=logged_user["id"], group_id=group.gid
)


@pytest.mark.parametrize("user_role", [UserRole.USER])
async def test_list_users_in_group_owner_only(
client: TestClient,
user_role: UserRole,
logged_user: UserInfoDict,
create_test_group,
):
"""Test list_users_in_group returns only the owner for a new group."""
assert client.app

# Create a standard group
group = await create_test_group(
name="Test Owner Only Group",
description="A test group to check owner-only user list",
)

# List users in the group - should only contain the owner
users_in_group = await list_users_in_group(app=client.app, group_id=group.gid)

# Should contain exactly one user (the owner)
assert len(users_in_group) == 1
assert isinstance(users_in_group[0], GroupMember)
assert users_in_group[0].id == logged_user["id"]
Loading