22from django .core .exceptions import PermissionDenied
33from rolepermissions .permissions import register_object_checker
44
5+ from hypha .apply .funds .models .co_applicants import COMMENT , READ_ONLY , CoApplicant
56from hypha .apply .funds .models .submissions import DRAFT_STATE
67
78from ..users .roles import STAFF_GROUP_NAME , SUPERADMIN , TEAMADMIN_GROUP_NAME , StaffAdmin
@@ -24,7 +25,17 @@ def can_edit_submission(user, submission):
2425 if submission .is_archive :
2526 return False , "Archived Submission"
2627
27- return True , ""
28+ if submission .phase .permissions .can_edit (user ):
29+ co_applicant = submission .co_applicants .filter (user = user ).first ()
30+ if co_applicant :
31+ if co_applicant .role not in [READ_ONLY , COMMENT ]:
32+ return (
33+ True ,
34+ "Co-applicant with read only or comment access can't edit submission" ,
35+ )
36+ return False , ""
37+ return True , "User can edit in current phase"
38+ return False , ""
2839
2940
3041@register_object_checker ()
@@ -220,10 +231,37 @@ def can_invite_co_applicants(user, submission):
220231 return False , "Forbidden Error"
221232
222233
234+ def can_view_co_applicants (user , submission ):
235+ if user .is_applicant and user == submission .user :
236+ return True , "Submission user can access their submission's co-applicants"
237+ if user .is_apply_staff :
238+ return True , "Staff can access each submissions' co-applicants"
239+ return False , "Forbidden Error"
240+
241+
242+ def can_update_co_applicant (user , invite ):
243+ if invite .invited_by == user :
244+ return True , "Same user who invited can delete the co-applicant"
245+ if invite .submission .user == user :
246+ return True , "Submission owner can delete the co-applicant"
247+ if user .is_apply_staff :
248+ return True , "Staff can delete any co-applicant of any submission"
249+ return False , "Forbidden Error"
250+
251+
252+ def user_can_view_post_comment_form (user , submission ):
253+ co_applicant = CoApplicant .objects .filter (user = user , submission = submission ).first ()
254+ if co_applicant and co_applicant .role == READ_ONLY :
255+ return False
256+ return True
257+
258+
223259permissions_map = {
224260 "submission_view" : is_user_has_access_to_view_submission ,
225261 "submission_edit" : can_edit_submission ,
226262 "can_view_submission_screening" : can_view_submission_screening ,
227263 "archive_alter" : can_alter_archived_submissions ,
228264 "co_applicant_invite" : can_invite_co_applicants ,
265+ "co_applicants_view" : can_view_co_applicants ,
266+ "co_applicants_update" : can_update_co_applicant ,
229267}
0 commit comments