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

Commit 4c75c20

Browse files
committed
Fixed set a user as an admin with the new API (#6928)
* commit '9b06d8f8a': Fixed set a user as an admin with the new API (#6928)
2 parents 637f8d9 + 9b06d8f commit 4c75c20

File tree

4 files changed

+199
-42
lines changed

4 files changed

+199
-42
lines changed

changelog.d/6910.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed set a user as an admin with the admin API `PUT /_synapse/admin/v2/users/<user_id>`. Contributed by @dklimpel.

synapse/rest/admin/users.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,7 @@ async def on_PUT(self, request, user_id):
211211
if target_user == auth_user and not set_admin_to:
212212
raise SynapseError(400, "You may not demote yourself.")
213213

214-
await self.admin_handler.set_user_server_admin(
215-
target_user, set_admin_to
216-
)
214+
await self.store.set_server_admin(target_user, set_admin_to)
217215

218216
if "password" in body:
219217
if (
@@ -651,6 +649,6 @@ async def on_PUT(self, request, user_id):
651649
if target_user == auth_user and not set_admin_to:
652650
raise SynapseError(400, "You may not demote yourself.")
653651

654-
await self.store.set_user_server_admin(target_user, set_admin_to)
652+
await self.store.set_server_admin(target_user, set_admin_to)
655653

656654
return 200, {}

synapse/storage/data_stores/main/registration.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,16 @@ def set_server_admin(self, user, admin):
323323
admin (bool): true iff the user is to be a server admin,
324324
false otherwise.
325325
"""
326-
return self.db.simple_update_one(
327-
table="users",
328-
keyvalues={"name": user.to_string()},
329-
updatevalues={"admin": 1 if admin else 0},
330-
desc="set_server_admin",
331-
)
326+
327+
def set_server_admin_txn(txn):
328+
self.db.simple_update_one_txn(
329+
txn, "users", {"name": user.to_string()}, {"admin": 1 if admin else 0}
330+
)
331+
self._invalidate_cache_and_stream(
332+
txn, self.get_user_by_id, (user.to_string(),)
333+
)
334+
335+
return self.db.runInteraction("set_server_admin", set_server_admin_txn)
332336

333337
def _query_for_auth(self, txn, token):
334338
sql = (

0 commit comments

Comments
 (0)