MSC3866: Apply missed filter on /users response (#20152)

For the Admin API /users endpoint, the response is meant to exclude the
approval flag when MSC3866 is enabled, but the filter that applies the
exclusion never actually got used. Fix things so that it does.
This commit is contained in:
Andrew Ferrazzutti
2026-08-27 16:53:03 +01:00
committed by GitHub
parent 83193b378d
commit 305faa2ab5
3 changed files with 14 additions and 5 deletions
+1
View File
@@ -0,0 +1 @@
When not using MSC3866, omit the approval flag from the response of `GET /_synapse/admin/v2/users`.
+9 -5
View File
@@ -49,6 +49,7 @@ from synapse.rest.admin._base import (
assert_user_is_admin,
)
from synapse.rest.client._base import client_patterns
from synapse.storage.databases.main import UserPaginateResponse
from synapse.storage.databases.main.registration import ExternalIDReuseException
from synapse.storage.databases.main.stats import UserSortOrder
from synapse.types import JsonDict, JsonMapping, TaskStatus, UserID
@@ -181,13 +182,16 @@ class UsersRestServletV2(RestServlet):
)
# If support for MSC3866 is not enabled, don't show the approval flag.
filter = None
users_filter = None
if not self._msc3866_enabled:
users_filter = attr.filters.exclude(
attr.fields(UserPaginateResponse).approved
)
def _filter(a: attr.Attribute) -> bool:
return a.name != "approved"
ret = {"users": [attr.asdict(u, filter=filter) for u in users], "total": total}
ret = {
"users": [attr.asdict(u, filter=users_filter) for u in users],
"total": total,
}
if (start + limit) < total:
ret["next_token"] = str(start + len(users))
+4
View File
@@ -1424,6 +1424,10 @@ class UsersListTestCase(unittest.HomeserverTestCase):
self.assertIn("avatar_url", u)
self.assertIn("creation_ts", u)
self.assertIn("last_seen_ts", u)
if self.hs.config.experimental.msc3866.enabled:
self.assertIn("approved", u)
else:
self.assertNotIn("approved", u)
def _create_users(self, number_users: int) -> None:
"""