Compare commits

...

2 Commits

Author SHA1 Message Date
Andrew Morgan
2b73bb0c78 newsfile 2025-08-06 15:03:35 +01:00
Andrew Morgan
84bfa2ab56 Set type of user_id on is_server_admin to str
This allows the cache of this function to be invalidated. As we were calling `_invalidate_cache_and_stream` with a `str` instead of a `UserID` as this function expected, the cache was not actually being invalidated.
2025-08-06 14:15:22 +01:00
7 changed files with 8 additions and 10 deletions

1
changelog.d/18786.bugfix Normal file
View File

@@ -0,0 +1 @@
Fix invalidation of storage cache that was broken in 1.135.0.

View File

@@ -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())

View File

@@ -1921,7 +1921,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

View File

@@ -761,7 +761,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.

View File

@@ -1000,7 +1000,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}

View File

@@ -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",

View File

@@ -52,7 +52,6 @@ from synapse.types import (
RetentionPolicy,
StateMap,
StrCollection,
UserID,
get_domain_from_id,
)
from synapse.types.state import StateFilter
@@ -120,9 +119,7 @@ async def filter_events_for_client(
# Default case is to *exclude* soft-failed events
events = [e for e in events if not e.internal_metadata.is_soft_failed()]
client_config = await storage.main.get_admin_client_config_for_user(user_id)
if filter_send_to_client and await storage.main.is_server_admin(
UserID.from_string(user_id)
):
if filter_send_to_client and await storage.main.is_server_admin(user_id):
if client_config.return_soft_failed_events:
# The user has requested that all events be included, so do that.
# We copy the list for mutation safety.