9
9
from model_utils .models import TimeStampedModel
10
10
from simple_history .models import HistoricalRecords
11
11
12
- from ifxuser .models import Organization
12
+ from ifxuser .models import Organization , OrgRelation
13
13
from coldfront .core .field_of_science .models import FieldOfScience
14
14
from coldfront .core .utils .common import import_from_settings
15
15
@@ -194,6 +194,24 @@ def user_permissions(self, user):
194
194
195
195
user_conditions = (models .Q (status__name = 'Active' ) & models .Q (user = user ))
196
196
if not self .projectuser_set .filter (user_conditions ).exists () and not self .pi .id == user .id :
197
+ # if the user is an approver in a project's department, give them user permissions
198
+ departments = Organization .objects .filter (
199
+ org_tree = 'Research Computing Storage Billing' ,
200
+ useraffiliation__role = 'approver' ,
201
+ useraffiliation__user = user ,
202
+ )
203
+ for department in departments :
204
+ child_lab_ids = list (
205
+ OrgRelation .objects .filter (parent = department , child__rank = "lab" ).values_list (
206
+ 'child_id' , flat = True
207
+ )
208
+ )
209
+ project_org_links = ProjectOrganization .objects .filter (
210
+ organization_id__in = child_lab_ids
211
+ ).values_list ("project_id" )
212
+ proj_pool = Project .objects .filter (pk__in = project_org_links )
213
+ if self in proj_pool :
214
+ return [ProjectPermission .USER ]
197
215
return []
198
216
199
217
@@ -216,16 +234,6 @@ def user_permissions(self, user):
216
234
if self .pi .id == user .id :
217
235
permissions .append (ProjectPermission .PI )
218
236
219
- # if the user is an approver in a department connected to the project,
220
- # give them user permissions
221
- departments = Organization .objects .filter (
222
- org_tree = 'Research Computing Storage Billing'
223
- )
224
- proj_departments = [d for d in departments if self in d .get_projects ()]
225
- for department in proj_departments :
226
- if user in department .useraffiliation_set .filter (role = 'approver' ):
227
- permissions .append (ProjectPermission .USER )
228
-
229
237
return permissions
230
238
231
239
def has_perm (self , user , perm ):
0 commit comments