From ccd4ee5405f6a302283bac80dee15919dd3c6ffe Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Thu, 21 Mar 2024 10:10:46 +0300 Subject: Add extra endpoint to get user authorisation given a resource name. * gn_auth/auth/authorisation/resources/models.py (user_roles_on_resources): New function. * gn_auth/auth/authorisation/resources/views.py (resources_authorisation): New endpoint. Signed-off-by: Munyoki Kilyungi --- gn_auth/auth/authorisation/resources/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gn_auth/auth/authorisation/resources/models.py') diff --git a/gn_auth/auth/authorisation/resources/models.py b/gn_auth/auth/authorisation/resources/models.py index 8bd8c73..60d24ff 100644 --- a/gn_auth/auth/authorisation/resources/models.py +++ b/gn_auth/auth/authorisation/resources/models.py @@ -420,3 +420,14 @@ def user_roles_on_resources(conn: db.DbConnection, with db.cursor(conn) as cursor: cursor.execute(query, params) return reduce(__organise__, cursor.fetchall(), {}) + + +def get_resource_id(conn: db.DbConnection, name: str) -> Optional[str]: + """Given a resource_name, return it's resource_id.""" + with db.cursor(conn) as cursor: + cursor.execute( + "SELECT resource_id \ +FROM resources as r WHERE r.resource_name=?", (name, )) + if res := cursor.fetchone(): + return res["resource_id"] + return None -- cgit v1.2.3