From a139e8c41aea8da54683dc610c8459ae45f0eb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 10 May 2017 12:09:09 +0200 Subject: [PATCH] Added p.a.projects.utils.get_admin_group_id() --- pillar/api/projects/utils.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pillar/api/projects/utils.py b/pillar/api/projects/utils.py index d38fc21f..92e3c11a 100644 --- a/pillar/api/projects/utils.py +++ b/pillar/api/projects/utils.py @@ -27,12 +27,25 @@ def project_total_file_size(project_id): return 0 -def get_admin_group(project): +def get_admin_group_id(project_id: ObjectId) -> ObjectId: + project = current_app.db('projects').find_one({'_id': project_id}, + {'permissions': 1}) + # TODO: search through all groups to find the one with the project ID as its name, + # or identify "the admin group" in a different way (for example the group with DELETE rights). + try: + admin_group_id = ObjectId(project['permissions']['groups'][0]['group']) + except KeyError: + raise ValueError(f'Project {project_id} does not seem to have an admin group') + + return admin_group_id + + +def get_admin_group(project: dict) -> dict: """Returns the admin group for the project.""" groups_collection = current_app.data.driver.db['groups'] - # TODO: search through all groups to find the one with the project ID as its name. + # TODO: see get_admin_group_id admin_group_id = ObjectId(project['permissions']['groups'][0]['group']) group = groups_collection.find_one({'_id': admin_group_id})