diff options
author | Frederick Muriuki Muriithi | 2023-03-03 10:48:30 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-03-03 10:48:30 +0300 |
commit | 94502a92d8ae3277b8dd07eb1117367821241913 (patch) | |
tree | c6857578610ea4504a0fdfa088f8abf320e57013 /gn3/auth/authorisation/privileges.py | |
parent | 8f5f0c692293b96c2ec48a810196556764101ccc (diff) | |
download | genenetwork3-94502a92d8ae3277b8dd07eb1117367821241913.tar.gz |
auth: group roles: enable creation and listing of group roles.
Diffstat (limited to 'gn3/auth/authorisation/privileges.py')
-rw-r--r-- | gn3/auth/authorisation/privileges.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gn3/auth/authorisation/privileges.py b/gn3/auth/authorisation/privileges.py index ae4ed88..dbb4129 100644 --- a/gn3/auth/authorisation/privileges.py +++ b/gn3/auth/authorisation/privileges.py @@ -29,3 +29,19 @@ def user_privileges(conn: db.DbConnection, user: User) -> Iterable[Privilege]: results = cursor.fetchall() return (Privilege(row[0], row[1]) for row in results) + +def privileges_by_ids( + conn: db.DbConnection, privileges_ids: tuple[str, ...]) -> tuple[ + Privilege, ...]: + """Fetch privileges by their ids.""" + if len(privileges_ids) == 0: + return tuple() + + with db.cursor(conn) as cursor: + clause = ", ".join(["?"] * len(privileges_ids)) + cursor.execute( + f"SELECT * FROM privileges WHERE privilege_id IN ({clause})", + privileges_ids) + return tuple( + Privilege(row["privilege_id"], row["privilege_description"]) + for row in cursor.fetchall()) |