|
41 | 41 | from projects.models import TeamComment
|
42 | 42 | from projects.serializers import HostedFileSerializer, HostedFileDownloadSerializer
|
43 | 43 | from projects.models import AGREEMENT_FORM_TYPE_MODEL, AGREEMENT_FORM_TYPE_FILE
|
| 44 | +from projects.models import InstitutionalOfficial |
44 | 45 |
|
45 | 46 | # Get an instance of a logger
|
46 | 47 | logger = logging.getLogger(__name__)
|
@@ -1157,6 +1158,54 @@ def grant_view_permission(request, project_key, user_email):
|
1157 | 1158 | participant = project.participant_set.get(user__email=user_email)
|
1158 | 1159 | participant.permission = 'VIEW'
|
1159 | 1160 | participant.save()
|
| 1161 | + |
| 1162 | + # Check if this project allows institutional signers |
| 1163 | + if project.institutional_signers: |
| 1164 | + |
| 1165 | + # Check if this is a signing official |
| 1166 | + try: |
| 1167 | + official = InstitutionalOfficial.objects.get( |
| 1168 | + project=project, |
| 1169 | + user=participant.user, |
| 1170 | + ) |
| 1171 | + |
| 1172 | + # Iterate linked members |
| 1173 | + for member_email in official.member_emails: |
| 1174 | + |
| 1175 | + logger.debug(f"Institutional signer/{participant.user.email}: Checking for existing linked member '{member_email}'") |
| 1176 | + |
| 1177 | + # Check if a participant exists for this email with no VIEW permission |
| 1178 | + if Participant.objects.filter(project=project, user__email=member_email).exclude(permission="VIEW").exists(): |
| 1179 | + |
| 1180 | + # Fetch them |
| 1181 | + member_participant = Participant.objects.get(project=project, user__email=member_email) |
| 1182 | + |
| 1183 | + # Approve signed agreement forms |
| 1184 | + for signed_agreement_form in SignedAgreementForm.objects.filter(project=project, user=member_participant.user): |
| 1185 | + |
| 1186 | + # If allows institutional signers, auto-approve |
| 1187 | + if signed_agreement_form.agreement_form.institutional_signers: |
| 1188 | + |
| 1189 | + signed_agreement_form.status = "A" |
| 1190 | + signed_agreement_form.save() |
| 1191 | + |
| 1192 | + # Grant this user access immediately if all agreement forms are accepted |
| 1193 | + for agreement_form in project.agreement_forms.all(): |
| 1194 | + if not SignedAgreementForm.objects.filter( |
| 1195 | + agreement_form=agreement_form, |
| 1196 | + project=project, |
| 1197 | + user=member_participant.user, |
| 1198 | + status="A" |
| 1199 | + ): |
| 1200 | + break |
| 1201 | + else: |
| 1202 | + |
| 1203 | + # Call this method to process the access |
| 1204 | + grant_view_permission(request, project_key, member_email) |
| 1205 | + |
| 1206 | + except ObjectDoesNotExist: |
| 1207 | + pass |
| 1208 | + |
1160 | 1209 | except Exception as e:
|
1161 | 1210 | logger.exception(
|
1162 | 1211 | '[HYPATIO][DEBUG][grant_view_permission] User {user} could not have permission added to project {project_key}: {e}'.format(
|
@@ -1226,6 +1275,26 @@ def remove_view_permission(request, project_key, user_email):
|
1226 | 1275 | participant = project.participant_set.get(user__email=user_email)
|
1227 | 1276 | participant.permission = None
|
1228 | 1277 | participant.save()
|
| 1278 | + |
| 1279 | + # Check if this project allows institutional signers |
| 1280 | + if project.institutional_signers: |
| 1281 | + |
| 1282 | + # Check if this is a signing official |
| 1283 | + try: |
| 1284 | + official = InstitutionalOfficial.objects.get( |
| 1285 | + project=project, |
| 1286 | + user=participant.user, |
| 1287 | + ) |
| 1288 | + |
| 1289 | + # Iterate linked members |
| 1290 | + for member_email in official.member_emails: |
| 1291 | + |
| 1292 | + # Remove their access |
| 1293 | + remove_view_permission(request, project_key, member_email) |
| 1294 | + |
| 1295 | + except ObjectDoesNotExist: |
| 1296 | + pass |
| 1297 | + |
1229 | 1298 | except Exception as e:
|
1230 | 1299 | logger.exception(
|
1231 | 1300 | '[HYPATIO][ERROR][grant_view_permission] User {user} could not have permission remove from project {project_key}: {e}'.format(
|
|
0 commit comments