diff --git a/changelog.d/20152.bugfix b/changelog.d/20152.bugfix new file mode 100644 index 0000000000..4233499d33 --- /dev/null +++ b/changelog.d/20152.bugfix @@ -0,0 +1 @@ +When not using MSC3866, omit the approval flag from the response of `GET /_synapse/admin/v2/users`. diff --git a/synapse/rest/admin/users.py b/synapse/rest/admin/users.py index ddb4483789..43dab16598 100644 --- a/synapse/rest/admin/users.py +++ b/synapse/rest/admin/users.py @@ -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)) diff --git a/tests/rest/admin/test_user.py b/tests/rest/admin/test_user.py index e2e133a85e..84bb7e319b 100644 --- a/tests/rest/admin/test_user.py +++ b/tests/rest/admin/test_user.py @@ -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: """