diff options
Diffstat (limited to 'gn_auth/auth/authorisation/resources/groups')
-rw-r--r-- | gn_auth/auth/authorisation/resources/groups/models.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/resources/groups/models.py b/gn_auth/auth/authorisation/resources/groups/models.py index 5ec26c5..959389c 100644 --- a/gn_auth/auth/authorisation/resources/groups/models.py +++ b/gn_auth/auth/authorisation/resources/groups/models.py @@ -451,3 +451,16 @@ def resource_owner(conn: db.DbConnection, resource: Resource) -> Group: json.loads(row["group_metadata"])) raise MissingGroupError("Resource has no 'owning' group.") + +def add_resources_to_group(conn: db.DbConnection, + resources: tuple[Resource, ...], + group: Group): + """Link the resources to the admin group.""" + with db.cursor(conn) as cursor: + cursor.executemany( + "INSERT INTO resource_ownership VALUES(:group_id, :resource_id) " + "ON CONFLICT (group_id, resource_id) DO NOTHING", + tuple({ + "group_id": str(group.group_id), + "resource_id": str(rsc.resource_id) + } for rsc in resources)) |