Skip to content
Snippets Groups Projects
Unverified Commit 692b8283 authored by Nicolas Werner's avatar Nicolas Werner Committed by GitHub
Browse files

Allow registering admin users using the module API (#12250)

parent 516d092f
No related branches found
No related tags found
No related merge requests found
Allow registering admin users using the module API. Contributed by Famedly.
...@@ -611,15 +611,18 @@ class ModuleApi: ...@@ -611,15 +611,18 @@ class ModuleApi:
localpart: str, localpart: str,
displayname: Optional[str] = None, displayname: Optional[str] = None,
emails: Optional[List[str]] = None, emails: Optional[List[str]] = None,
admin: bool = False,
) -> "defer.Deferred[str]": ) -> "defer.Deferred[str]":
"""Registers a new user with given localpart and optional displayname, emails. """Registers a new user with given localpart and optional displayname, emails.
Added in Synapse v1.2.0. Added in Synapse v1.2.0.
Changed in Synapse v1.56.0: add 'admin' argument to register the user as admin.
Args: Args:
localpart: The localpart of the new user. localpart: The localpart of the new user.
displayname: The displayname of the new user. displayname: The displayname of the new user.
emails: Emails to bind to the new user. emails: Emails to bind to the new user.
admin: True if the user should be registered as a server admin.
Raises: Raises:
SynapseError if there is an error performing the registration. Check the SynapseError if there is an error performing the registration. Check the
...@@ -633,6 +636,7 @@ class ModuleApi: ...@@ -633,6 +636,7 @@ class ModuleApi:
localpart=localpart, localpart=localpart,
default_display_name=displayname, default_display_name=displayname,
bind_emails=emails or [], bind_emails=emails or [],
admin=admin,
) )
) )
......
...@@ -86,6 +86,16 @@ class ModuleApiTestCase(HomeserverTestCase): ...@@ -86,6 +86,16 @@ class ModuleApiTestCase(HomeserverTestCase):
displayname = self.get_success(self.store.get_profile_displayname("bob")) displayname = self.get_success(self.store.get_profile_displayname("bob"))
self.assertEqual(displayname, "Bobberino") self.assertEqual(displayname, "Bobberino")
def test_can_register_admin_user(self):
user_id = self.get_success(
self.register_user(
"bob_module_admin", "1234", displayname="Bobberino Admin", admin=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): def test_get_userinfo_by_id(self):
user_id = self.register_user("alice", "1234") user_id = self.register_user("alice", "1234")
found_user = self.get_success(self.module_api.get_userinfo_by_id(user_id)) found_user = self.get_success(self.module_api.get_userinfo_by_id(user_id))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment