From a0ab22769d477ed8b01b2bd5915907e1b0abe693 Mon Sep 17 00:00:00 2001 From: geistling <34081638+geistling@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:34:54 -0400 Subject: [PATCH 1/3] give department approvers user permissions for child projects --- coldfront/core/project/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/coldfront/core/project/models.py b/coldfront/core/project/models.py index b3c4f1290..fb8fb7dad 100644 --- a/coldfront/core/project/models.py +++ b/coldfront/core/project/models.py @@ -9,6 +9,7 @@ from model_utils.models import TimeStampedModel from simple_history.models import HistoricalRecords +from coldfront.core.department.models import DepartmentProject from coldfront.core.field_of_science.models import FieldOfScience from coldfront.core.utils.common import import_from_settings @@ -214,6 +215,14 @@ def user_permissions(self, user): if self.pi.id == user.id: permissions.append(ProjectPermission.PI) + + # if the user is an approver in a department connected to the project, + # give them user permissions + department = DepartmentProject.objects.get(project=self).department + for parent_department in department.parents.filter(org_tree='Research Computing Storage Billing'): + if user in parent_department.useraffiliation_set.filter(role='approver'): + permissions.append(ProjectPermission.USER) + return permissions def has_perm(self, user, perm): From 9059cddb66b0a31fef9ee87d80a7b9cd8639b6d9 Mon Sep 17 00:00:00 2001 From: geistling <34081638+geistling@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:57:25 -0400 Subject: [PATCH 2/3] fix circular import --- coldfront/core/project/models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/coldfront/core/project/models.py b/coldfront/core/project/models.py index fb8fb7dad..3e578ca14 100644 --- a/coldfront/core/project/models.py +++ b/coldfront/core/project/models.py @@ -9,7 +9,7 @@ from model_utils.models import TimeStampedModel from simple_history.models import HistoricalRecords -from coldfront.core.department.models import DepartmentProject +from coldfront.core.department.models import Department from coldfront.core.field_of_science.models import FieldOfScience from coldfront.core.utils.common import import_from_settings @@ -218,9 +218,12 @@ def user_permissions(self, user): # if the user is an approver in a department connected to the project, # give them user permissions - department = DepartmentProject.objects.get(project=self).department - for parent_department in department.parents.filter(org_tree='Research Computing Storage Billing'): - if user in parent_department.useraffiliation_set.filter(role='approver'): + departments = Department.objects.filter( + org_tree='Research Computing Storage Billing' + ) + proj_departments = [d for d in departments if self in d.get_projects()] + for department in proj_departments: + if user in department.useraffiliation_set.filter(role='approver'): permissions.append(ProjectPermission.USER) return permissions From e61f48bb5f5fe3f8101e753672b58f90489eab31 Mon Sep 17 00:00:00 2001 From: geistling <34081638+geistling@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:02:46 -0400 Subject: [PATCH 3/3] fix circular import --- coldfront/core/project/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coldfront/core/project/models.py b/coldfront/core/project/models.py index 3e578ca14..8cb765662 100644 --- a/coldfront/core/project/models.py +++ b/coldfront/core/project/models.py @@ -9,7 +9,7 @@ from model_utils.models import TimeStampedModel from simple_history.models import HistoricalRecords -from coldfront.core.department.models import Department +from ifxuser.models import Organization from coldfront.core.field_of_science.models import FieldOfScience from coldfront.core.utils.common import import_from_settings @@ -218,7 +218,7 @@ def user_permissions(self, user): # if the user is an approver in a department connected to the project, # give them user permissions - departments = Department.objects.filter( + departments = Organization.objects.filter( org_tree='Research Computing Storage Billing' ) proj_departments = [d for d in departments if self in d.get_projects()]