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

Commit 692b828

Browse files
authored
Allow registering admin users using the module API (#12250)
Signed-off-by: Nicolas Werner <[email protected]>
1 parent 516d092 commit 692b828

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Diff for: changelog.d/12250.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow registering admin users using the module API. Contributed by Famedly.

Diff for: synapse/module_api/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,18 @@ def register_user(
611611
localpart: str,
612612
displayname: Optional[str] = None,
613613
emails: Optional[List[str]] = None,
614+
admin: bool = False,
614615
) -> "defer.Deferred[str]":
615616
"""Registers a new user with given localpart and optional displayname, emails.
616617
617618
Added in Synapse v1.2.0.
619+
Changed in Synapse v1.56.0: add 'admin' argument to register the user as admin.
618620
619621
Args:
620622
localpart: The localpart of the new user.
621623
displayname: The displayname of the new user.
622624
emails: Emails to bind to the new user.
625+
admin: True if the user should be registered as a server admin.
623626
624627
Raises:
625628
SynapseError if there is an error performing the registration. Check the
@@ -633,6 +636,7 @@ def register_user(
633636
localpart=localpart,
634637
default_display_name=displayname,
635638
bind_emails=emails or [],
639+
admin=admin,
636640
)
637641
)
638642

Diff for: tests/module_api/test_api.py

+10
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ def test_can_register_user(self):
8686
displayname = self.get_success(self.store.get_profile_displayname("bob"))
8787
self.assertEqual(displayname, "Bobberino")
8888

89+
def test_can_register_admin_user(self):
90+
user_id = self.get_success(
91+
self.register_user(
92+
"bob_module_admin", "1234", displayname="Bobberino Admin", admin=True
93+
)
94+
)
95+
found_user = self.get_success(self.module_api.get_userinfo_by_id(user_id))
96+
self.assertEqual(found_user.user_id.to_string(), user_id)
97+
self.assertIdentical(found_user.is_admin, True)
98+
8999
def test_get_userinfo_by_id(self):
90100
user_id = self.register_user("alice", "1234")
91101
found_user = self.get_success(self.module_api.get_userinfo_by_id(user_id))

0 commit comments

Comments
 (0)