about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-11-17 14:00:12 +0300
committerFrederick Muriuki Muriithi2023-11-17 14:00:12 +0300
commitfeaf215b9f36c1c25a7329eed91e1fdcb068a02f (patch)
treee23620db01442df9ce1a02c1d9398434e07725c2
parent8c6fffb7914d32df513939f05e6258dd4e6a81ad (diff)
downloadgn-auth-feaf215b9f36c1c25a7329eed91e1fdcb068a02f.tar.gz
Bug: Update query in script
Update query in script to provide resource_id for the user_roles tabel.
-rw-r--r--scripts/register_sys_admin.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/scripts/register_sys_admin.py b/scripts/register_sys_admin.py
index 7d4d667..78a0b33 100644
--- a/scripts/register_sys_admin.py
+++ b/scripts/register_sys_admin.py
@@ -61,8 +61,19 @@ def save_admin(conn: db.DbConnection, name: str, email: str, passwd: str):
         cursor.execute(
             "SELECT * FROM roles WHERE role_name='system-administrator'")
         admin_role = cursor.fetchone()
-        cursor.execute("INSERT INTO user_roles VALUES (:user_id, :role_id)",
-                       {**admin, "role_id": admin_role["role_id"]})
+        cursor.execute(
+            "SELECT * FROM resources AS r "
+            "INNER JOIN resource_categories AS rc "
+            "ON r.resource_category_id=rc.resource_category_id "
+            "WHERE resource_category_key='system'")
+        the_system = cursor.fetchall()
+        cursor.execute(
+            "INSERT INTO user_roles VALUES (:user_id, :role_id, :resource_id)",
+            {
+                **admin,
+                "role_id": admin_role["role_id"],
+                "resource_id": the_system["resource_id"]
+            })
         return 0
 
 def register_admin(authdbpath: Path):