From 7aac7db652a1805a3a5f49d2cd3363a089d3f552 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Thu, 7 Aug 2025 15:16:32 +0100 Subject: [PATCH] Set type of `user_id` on `is_server_admin` to str (#18786) --- changelog.d/18786.bugfix | 1 + synapse/api/auth/internal.py | 2 +- synapse/handlers/room_member.py | 2 +- synapse/module_api/__init__.py | 2 +- synapse/rest/admin/users.py | 2 +- synapse/storage/databases/main/registration.py | 4 ++-- synapse/visibility.py | 3 +-- 7 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 changelog.d/18786.bugfix diff --git a/changelog.d/18786.bugfix b/changelog.d/18786.bugfix new file mode 100644 index 000000000..8dee972e1 --- /dev/null +++ b/changelog.d/18786.bugfix @@ -0,0 +1 @@ +Fix invalidation of storage cache that was broken in 1.135.0. \ No newline at end of file diff --git a/synapse/api/auth/internal.py b/synapse/api/auth/internal.py index afc7b5c4a..b33384c13 100644 --- a/synapse/api/auth/internal.py +++ b/synapse/api/auth/internal.py @@ -296,4 +296,4 @@ class InternalAuth(BaseAuth): Returns: True if the user is an admin """ - return await self.store.is_server_admin(requester.user) + return await self.store.is_server_admin(requester.user.to_string()) diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index df67bf441..fea25b992 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -1914,7 +1914,7 @@ class RoomMemberMasterHandler(RoomMemberHandler): check_complexity and self.hs.config.server.limit_remote_rooms.admins_can_join ): - check_complexity = not await self.store.is_server_admin(user) + check_complexity = not await self.store.is_server_admin(user.to_string()) if check_complexity: # Fetch the room complexity diff --git a/synapse/module_api/__init__.py b/synapse/module_api/__init__.py index f039cd54c..fd0811ca1 100644 --- a/synapse/module_api/__init__.py +++ b/synapse/module_api/__init__.py @@ -694,7 +694,7 @@ class ModuleApi: Returns: True if the user is a server admin, False otherwise. """ - return await self._store.is_server_admin(UserID.from_string(user_id)) + return await self._store.is_server_admin(user_id) async def set_user_admin(self, user_id: str, admin: bool) -> None: """Sets if a user is a server admin. diff --git a/synapse/rest/admin/users.py b/synapse/rest/admin/users.py index 80cdcdee7..8240b270b 100644 --- a/synapse/rest/admin/users.py +++ b/synapse/rest/admin/users.py @@ -950,7 +950,7 @@ class UserAdminServlet(RestServlet): "Only local users can be admins of this homeserver", ) - is_admin = await self.store.is_server_admin(target_user) + is_admin = await self.store.is_server_admin(target_user.to_string()) return HTTPStatus.OK, {"admin": is_admin} diff --git a/synapse/storage/databases/main/registration.py b/synapse/storage/databases/main/registration.py index c4131ddf7..117444e7b 100644 --- a/synapse/storage/databases/main/registration.py +++ b/synapse/storage/databases/main/registration.py @@ -674,7 +674,7 @@ class RegistrationWorkerStore(StatsStore, CacheInvalidationWorkerStore): ) @cached(max_entries=100000) - async def is_server_admin(self, user: UserID) -> bool: + async def is_server_admin(self, user: str) -> bool: """Determines if a user is an admin of this homeserver. Args: @@ -685,7 +685,7 @@ class RegistrationWorkerStore(StatsStore, CacheInvalidationWorkerStore): """ res = await self.db_pool.simple_select_one_onecol( table="users", - keyvalues={"name": user.to_string()}, + keyvalues={"name": user}, retcol="admin", allow_none=True, desc="is_server_admin", diff --git a/synapse/visibility.py b/synapse/visibility.py index 280bcaa0f..501fad383 100644 --- a/synapse/visibility.py +++ b/synapse/visibility.py @@ -52,7 +52,6 @@ from synapse.types import ( RetentionPolicy, StateMap, StrCollection, - UserID, get_domain_from_id, ) from synapse.types.state import StateFilter @@ -121,7 +120,7 @@ async def filter_events_for_client( if not ( filter_send_to_client and client_config.return_soft_failed_events - and await storage.main.is_server_admin(UserID.from_string(user_id)) + and await storage.main.is_server_admin(user_id) ): events = [e for e in events if not e.internal_metadata.is_soft_failed()] if len(events_before_filtering) != len(events):