summary refs log tree commit diff
path: root/synapse/storage/registration.py
diff options
context:
space:
mode:
authorreivilibre <38398653+reivilibre@users.noreply.github.com>2019-08-27 10:14:00 +0100
committerGitHub <noreply@github.com>2019-08-27 10:14:00 +0100
commit1a7e6eb63387704ef379bf962318f710ce5ae5f3 (patch)
treed758ab954a9fbad9db495f76e0c59ef43ea7b766 /synapse/storage/registration.py
parentPropagate opentracing contexts through EDUs (#5852) (diff)
downloadsynapse-1a7e6eb63387704ef379bf962318f710ce5ae5f3.tar.xz
Add Admin API capability to set adminship of a user (#5878)
Admin API: Set adminship of a user
Diffstat (limited to 'synapse/storage/registration.py')
-rw-r--r--synapse/storage/registration.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/synapse/storage/registration.py b/synapse/storage/registration.py
index 55e4e84d71..9027b917c1 100644
--- a/synapse/storage/registration.py
+++ b/synapse/storage/registration.py
@@ -272,6 +272,14 @@ class RegistrationWorkerStore(SQLBaseStore):
 
     @defer.inlineCallbacks
     def is_server_admin(self, user):
+        """Determines if a user is an admin of this homeserver.
+
+        Args:
+            user (UserID): user ID of the user to test
+
+        Returns (bool):
+            true iff the user is a server admin, false otherwise.
+        """
         res = yield self._simple_select_one_onecol(
             table="users",
             keyvalues={"name": user.to_string()},
@@ -282,6 +290,21 @@ class RegistrationWorkerStore(SQLBaseStore):
 
         return res if res else False
 
+    def set_server_admin(self, user, admin):
+        """Sets whether a user is an admin of this homeserver.
+
+        Args:
+            user (UserID): user ID of the user to test
+            admin (bool): true iff the user is to be a server admin,
+                false otherwise.
+        """
+        return self._simple_update_one(
+            table="users",
+            keyvalues={"name": user.to_string()},
+            updatevalues={"admin": 1 if admin else 0},
+            desc="set_server_admin",
+        )
+
     def _query_for_auth(self, txn, token):
         sql = (
             "SELECT users.name, users.is_guest, access_tokens.id as token_id,"