mirror of
https://github.com/element-hq/synapse.git
synced 2026-08-29 03:28:34 +00:00
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:
@@ -0,0 +1 @@
|
||||
When not using MSC3866, omit the approval flag from the response of `GET /_synapse/admin/v2/users`.
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user