From 6fe4c9deaf026ce684e043d4c06fd5e57b9a98e3 Mon Sep 17 00:00:00 2001 From: Jiri Kozel Date: Tue, 28 Nov 2023 17:00:05 +0100 Subject: [PATCH] On POST Workspace Layer/Map insert role name to DB --- src/layman/common/prime_db_schema/publications.py | 8 +++++--- src/layman/common/prime_db_schema/rights.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/layman/common/prime_db_schema/publications.py b/src/layman/common/prime_db_schema/publications.py index 53af81dac..4bd8e8e37 100644 --- a/src/layman/common/prime_db_schema/publications.py +++ b/src/layman/common/prime_db_schema/publications.py @@ -474,13 +474,15 @@ def insert_publication(workspace_name, info): ) pub_id = db_util.run_query(insert_publications_sql, data)[0][0] - read_users = get_user_and_role_names_for_db(info['access_rights']['read'], workspace_name)[0] - write_users = get_user_and_role_names_for_db(info['access_rights']['write'], workspace_name)[0] + read_users, read_roles = get_user_and_role_names_for_db(info['access_rights']['read'], workspace_name) + write_users, write_roles = get_user_and_role_names_for_db(info['access_rights']['write'], workspace_name) rights.insert_rights(pub_id, read_users, + read_roles, 'read') rights.insert_rights(pub_id, write_users, + write_roles, 'write') return pub_id @@ -553,7 +555,7 @@ def update_publication(workspace_name, info): pub_id = db_util.run_query(update_publications_sql, data)[0][0] for right_type in right_type_list: - rights.insert_rights(pub_id, access_rights_changes[right_type]['add'], right_type) + rights.insert_rights(pub_id, access_rights_changes[right_type]['add'], set(), right_type) rights.remove_rights(pub_id, access_rights_changes[right_type]['remove'], right_type) return pub_id diff --git a/src/layman/common/prime_db_schema/rights.py b/src/layman/common/prime_db_schema/rights.py index 4eca5f8d2..5e6032e11 100644 --- a/src/layman/common/prime_db_schema/rights.py +++ b/src/layman/common/prime_db_schema/rights.py @@ -9,6 +9,7 @@ def insert_rights(id_publication, users, + roles, type, ): sql = f'''insert into {DB_SCHEMA}.rights (id_user, id_publication, type) @@ -25,6 +26,15 @@ def insert_rights(id_publication, type, username, )) + sql = f'''insert into {DB_SCHEMA}.rights (role_name, id_publication, type) + values (%s, %s, %s) +returning id +;''' + for role_name in roles: + db_util.run_query(sql, (role_name, + id_publication, + type, + )) def delete_rights_for_publication(id_publication):