Skip to content

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

Rename reaches member clients through the tenants authentication reads

Simon Flackafcf9806e88e
diff --git a/core/switch_core/chats/member_names.py b/core/switch_core/chats/member_names.py
index 697a261b1..08677d60a 100644
--- a/core/switch_core/chats/member_names.py
+++ b/core/switch_core/chats/member_names.py
@@ -10,20 +10,26 @@ row-level security, so one tenant session at a time.
from __future__ import annotations
+from collections.abc import Iterable
+
from sqlalchemy import update
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
from switch_core.chats import MEMBER_CLIENT_TYPE
from switch_core.db.models import Client
from switch_core.db.session_scope import tenant_session
-from switch_core.db.tenant_lookup import tenants_bindable_by_user
async def rename_member_clients(
- session_factory: async_sessionmaker[AsyncSession], user_id: str, name: str
+ session_factory: async_sessionmaker[AsyncSession],
+ tenant_ids: Iterable[str],
+ user_id: str,
+ name: str,
) -> None:
- """Give every member client of `user_id` the display name `name`."""
- for tenant_id in await tenants_bindable_by_user(session_factory, user_id):
+ """Give every member client of `user_id` in `tenant_ids` the display name
+ `name`. The caller says which tenants: the ones the person can reach, as
+ authentication already reads them (`gateway.auth.tenants_bindable_by`)."""
+ for tenant_id in tenant_ids:
async with tenant_session(session_factory, tenant_id) as session:
await session.execute(
update(Client)
diff --git a/core/switch_core/gateway/auth_routes.py b/core/switch_core/gateway/auth_routes.py
index 02eac1567..45a675296 100644
--- a/core/switch_core/gateway/auth_routes.py
+++ b/core/switch_core/gateway/auth_routes.py
@@ -46,6 +46,7 @@ from switch_core.gateway.auth import (
operator_entered_workspace,
require_admin,
set_session_cookie,
+ tenants_bindable_by,
verify_password_off_loop,
)
from switch_core.gateway.dependencies import (
@@ -550,7 +551,12 @@ async def update_me(
await session.commit()
# The name other members see beside what this person writes in a
# Console chat is their member client's, copied when it was made.
- await rename_member_clients(session_factory, user.id, req.name)
+ await rename_member_clients(
+ session_factory,
+ await tenants_bindable_by(session_factory, user.id),
+ user.id,
+ req.name,
+ )
return _session_response(user)