Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Send a room's owner with its detail

Abel Dantas32c2c530f721
diff --git a/core/switch_core/gateway/rooms.py b/core/switch_core/gateway/rooms.py
index 2e52d08f5..df9d8f9dc 100644
--- a/core/switch_core/gateway/rooms.py
+++ b/core/switch_core/gateway/rooms.py
@@ -202,6 +202,9 @@ async def _build_room_detail(
roles = await _list_room_role_details(session, room.id, protocol)
join_event_listeners = await room_store.get_join_event_listeners(session, room.id)
+ # The Gateway decides from the owner which controls to offer (only the
+ # owner or an admin may change access or delete the room).
+ owner = await session.get(User, room.owner_id) if room.owner_id else None
# Not held across the deeplink, which can ask the platform on a cache miss.
await session.commit()
external_channel_url = await _external_channel_url(room)
@@ -221,6 +224,8 @@ async def _build_room_detail(
external_channel_url=external_channel_url,
group_id=room.group_id,
group_name=group_name,
+ owner_id=room.owner_id,
+ owner_name=owner.name if owner else None,
read_visibility=room.read_visibility,
write_visibility=room.write_visibility,
created_at=str(room.created_at),
diff --git a/core/tests/switch_core/gateway/test_room_detail_access.py b/core/tests/switch_core/gateway/test_room_detail_access.py
new file mode 100644
index 000000000..da0f3c858
--- /dev/null
+++ b/core/tests/switch_core/gateway/test_room_detail_access.py
@@ -0,0 +1,85 @@
+"""What the room detail tells the Gateway about the caller's access.
+
+The Gateway offers a room's controls from what the server sends: the room's
+owner decides who may change its access or delete it, so the detail has to
+carry it.
+"""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+from typing import Any
+from unittest.mock import AsyncMock
+
+from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
+
+from switch_core.db.models import Room, User
+from switch_core.db.stores.agent_store import AgentStore
+from switch_core.db.stores.room_role_store import RoomRoleStore
+from switch_core.db.stores.room_store import RoomStore
+from switch_core.db.stores.user_store import UserStore
+from switch_core.gateway.rooms import get_room
+
+_ROOM_STORE = RoomStore()
+_USER_STORE = UserStore()
+
+
+def _protocol() -> Any:
+ """Just enough of `AgentCore` for a room with no agents or roles held."""
+ return SimpleNamespace(
+ get_agent_statuses_by_ids_in_session=AsyncMock(return_value={}),
+ room_role_store=RoomRoleStore(),
+ connections=SimpleNamespace(live_connection_ids=lambda: set()),
+ agent_store=AgentStore(),
+ )
+
+
+async def _add_user(session: AsyncSession, *, name: str) -> User:
+ user = User(name=name, email=f"{name}@example.com", role="user")
+ session.add(user)
+ await session.flush()
+ return user
+
+
+async def _add_room(
+ session: AsyncSession,
+ *,
+ name: str,
+ owner_id: str | None,
+ read_visibility: str = "private",
+ write_visibility: str = "private",
+) -> Room:
+ room = Room(
+ transport_room_id=f"!{name}:test",
+ name=name,
+ description=f"{name} desc",
+ owner_id=owner_id,
+ read_visibility=read_visibility,
+ write_visibility=write_visibility,
+ )
+ session.add(room)
+ await session.flush()
+ return room
+
+
+class TestRoomDetailOwner:
+ async def test_detail_names_the_owner(
+ self, session_factory: async_sessionmaker[AsyncSession]
+ ) -> None:
+ async with session_factory() as session:
+ owner = await _add_user(session, name="owner")
+ room = await _add_room(session, name="r1", owner_id=owner.id)
+
+ detail = await get_room(
+ room.id,
+ session,
+ _ROOM_STORE,
+ None, # type: ignore[arg-type] # bridge_store: the room has no bridge
+ None, # type: ignore[arg-type] # external_user_store
+ _protocol(),
+ owner,
+ await _USER_STORE.administers(session, owner),
+ )
+
+ assert detail.owner_id == owner.id
+ assert detail.owner_name == "owner"