Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add set_user_admin function to the module API (#12341)
Browse files Browse the repository at this point in the history
  • Loading branch information
agraven authored Apr 1, 2022
1 parent bebf994 commit 4e900ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/12341.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow setting user admin status using the module API. Contributed by Famedly.
11 changes: 11 additions & 0 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,17 @@ async def is_user_admin(self, user_id: str) -> bool:
"""
return await self._store.is_server_admin(UserID.from_string(user_id))

async def set_user_admin(self, user_id: str, admin: bool) -> None:
"""Sets if a user is a server admin.
Added in Synapse v1.56.0.
Args:
user_id: The Matrix ID of the user to set admin status for.
admin: True iff the user is to be a server admin, false otherwise.
"""
await self._store.set_server_admin(UserID.from_string(user_id), admin)

def get_qualified_user_id(self, username: str) -> str:
"""Qualify a user id, if necessary
Expand Down
14 changes: 14 additions & 0 deletions tests/module_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ def test_can_register_admin_user(self):
self.assertEqual(found_user.user_id.to_string(), user_id)
self.assertIdentical(found_user.is_admin, True)

def test_can_set_admin(self):
user_id = self.get_success(
self.register_user(
"alice_wants_admin",
"1234",
displayname="Alice Powerhungry",
admin=False,
)
)
self.get_success(self.module_api.set_user_admin(user_id, True))
found_user = self.get_success(self.module_api.get_userinfo_by_id(user_id))
self.assertEqual(found_user.user_id.to_string(), user_id)
self.assertIdentical(found_user.is_admin, True)

def test_get_userinfo_by_id(self):
user_id = self.register_user("alice", "1234")
found_user = self.get_success(self.module_api.get_userinfo_by_id(user_id))
Expand Down

0 comments on commit 4e900ec

Please sign in to comment.