aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-07-30 09:26:33 -0500
committerFrederick Muriuki Muriithi2025-07-30 09:26:33 -0500
commitfcd6551c4f82248b71d9241085773e24adcf24e9 (patch)
tree23895dac130631879511bd9b67006f6bd4d8c44c
parent37456060798ec087bcde92e8f048d9db74937b09 (diff)
downloadgn-auth-fcd6551c4f82248b71d9241085773e24adcf24e9.tar.gz
Function to fetch the `system-administrator` role details from db.
-rw-r--r--gn_auth/auth/authorisation/users/admin/models.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/users/admin/models.py b/gn_auth/auth/authorisation/users/admin/models.py
index 36f3c09..53f1f68 100644
--- a/gn_auth/auth/authorisation/users/admin/models.py
+++ b/gn_auth/auth/authorisation/users/admin/models.py
@@ -1,9 +1,28 @@
"""Major function for handling admin users."""
from gn_auth.auth.db import sqlite3 as db
from gn_auth.auth.authentication.users import User
+from gn_auth.auth.authorisation.roles.models import Role, db_rows_to_roles
def make_sys_admin(cursor: db.DbCursor, user: User) -> User:
"""Make a given user into an system admin."""
+
+def sysadmin_role(conn: db.DbConnection) -> Role:
+ """Fetch the `system-administrator` role details."""
+ with db.cursor(conn) as cursor:
+ cursor.execute(
+ "SELECT roles.*, privileges.* "
+ "FROM roles INNER JOIN role_privileges "
+ "ON roles.role_id=role_privileges.role_id "
+ "INNER JOIN privileges "
+ "ON role_privileges.privilege_id=privileges.privilege_id "
+ "WHERE role_name='system-administrator'")
+ results = db_rows_to_roles(cursor.fetchall())
+
+ assert len(results) == 1, (
+ "There should only ever be one 'system-administrator' role.")
+ return results[0]
+
+
cursor.execute(
"SELECT * FROM roles WHERE role_name='system-administrator'")
admin_role = cursor.fetchone()