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

Commit

Permalink
Fixed set a user as an admin with the new API (#6928)
Browse files Browse the repository at this point in the history
* commit '9b06d8f8a':
  Fixed set a user as an admin with the new API (#6928)
  • Loading branch information
anoadragon453 committed Mar 24, 2020
2 parents 637f8d9 + 9b06d8f commit 4c75c20
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 42 deletions.
1 change: 1 addition & 0 deletions changelog.d/6910.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed set a user as an admin with the admin API `PUT /_synapse/admin/v2/users/<user_id>`. Contributed by @dklimpel.
6 changes: 2 additions & 4 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ async def on_PUT(self, request, user_id):
if target_user == auth_user and not set_admin_to:
raise SynapseError(400, "You may not demote yourself.")

await self.admin_handler.set_user_server_admin(
target_user, set_admin_to
)
await self.store.set_server_admin(target_user, set_admin_to)

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

await self.store.set_user_server_admin(target_user, set_admin_to)
await self.store.set_server_admin(target_user, set_admin_to)

return 200, {}
16 changes: 10 additions & 6 deletions synapse/storage/data_stores/main/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,16 @@ def set_server_admin(self, user, admin):
admin (bool): true iff the user is to be a server admin,
false otherwise.
"""
return self.db.simple_update_one(
table="users",
keyvalues={"name": user.to_string()},
updatevalues={"admin": 1 if admin else 0},
desc="set_server_admin",
)

def set_server_admin_txn(txn):
self.db.simple_update_one_txn(
txn, "users", {"name": user.to_string()}, {"admin": 1 if admin else 0}
)
self._invalidate_cache_and_stream(
txn, self.get_user_by_id, (user.to_string(),)
)

return self.db.runInteraction("set_server_admin", set_server_admin_txn)

def _query_for_auth(self, txn, token):
sql = (
Expand Down
Loading

0 comments on commit 4c75c20

Please sign in to comment.