diff options
author | Frederick Muriuki Muriithi | 2025-07-22 12:13:07 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-07-22 12:13:07 -0500 |
commit | 94159b250b400e6410b060717bf3dcebc74da0a2 (patch) | |
tree | 12e394a93cedc4a8d5b50ae3e96be52bcfd5883e | |
parent | ae637af6dce9499692e84313ebbe779e2fdde6ea (diff) | |
download | gn-auth-94159b250b400e6410b060717bf3dcebc74da0a2.tar.gz |
-rw-r--r-- | migrations/auth/20250722_02_M8TXv-add-system-user-edit-privilege-to-system-admin-role.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/migrations/auth/20250722_02_M8TXv-add-system-user-edit-privilege-to-system-admin-role.py b/migrations/auth/20250722_02_M8TXv-add-system-user-edit-privilege-to-system-admin-role.py new file mode 100644 index 0000000..b956bef --- /dev/null +++ b/migrations/auth/20250722_02_M8TXv-add-system-user-edit-privilege-to-system-admin-role.py @@ -0,0 +1,36 @@ +""" +Add 'system:user:edit' privilege to 'system-admin' role. +""" +import contextlib + +from yoyo import step + +__depends__ = {'20250722_01_7Gro7-create-new-system-user-edit-privilege'} + + +def system_administrator_role_id(cursor): + """Fetch ID for role 'system-administrator'.""" + cursor.execute( + "SELECT role_id FROM roles WHERE role_name='system-administrator'") + return cursor.fetchone()[0] + + +def add_system_user_edit_privilege(conn): + """Add the 'system:user:edit' to the 'system-administrator' role.""" + with contextlib.closing(conn.cursor()) as cursor: + cursor.execute( + "INSERT INTO role_privileges(role_id, privilege_id) " + "VALUES(?, ?)", + (system_administrator_role_id(cursor), 'system:user:edit')) + + +def remove_system_user_edit_privilege(conn): + """Remove the 'system:user:edit' from the 'system-administrator' role.""" + with contextlib.closing(conn.cursor()) as cursor: + cursor.execute( + "DELETE FROM role_privileges WHERE role_id=? AND privilege_id=?", + (system_administrator_role_id(cursor), 'system:user:edit')) + +steps = [ + step(add_system_user_edit_privilege, remove_system_user_edit_privilege) +] |