|
19 | 19 | from django.core.mail import EmailMultiAlternatives
|
20 | 20 | from django.template.loader import render_to_string
|
21 | 21 | from dbmi_client import fileservice
|
| 22 | +from django.shortcuts import get_object_or_404 |
22 | 23 |
|
23 | 24 | from hypatio.sciauthz_services import SciAuthZ
|
24 | 25 | from hypatio.scireg_services import get_user_profile, get_distinct_countries_participating
|
25 | 26 |
|
26 | 27 | from manage.forms import NotificationForm
|
27 | 28 | from manage.models import ChallengeTaskSubmissionExport
|
28 | 29 | from manage.forms import UploadSignedAgreementFormForm
|
| 30 | +from manage.forms import UploadSignedAgreementFormFileForm |
29 | 31 | from projects.models import AgreementForm, ChallengeTaskSubmission
|
30 | 32 | from projects.models import DataProject
|
31 | 33 | from projects.models import Participant
|
@@ -603,7 +605,8 @@ def team_notification(request, project_key=None):
|
603 | 605 | try:
|
604 | 606 | msg = EmailMultiAlternatives(subject=subject,
|
605 | 607 | body=msg_plain,
|
606 |
| - from_email=settings.DEFAULT_FROM_EMAIL, |
| 608 | + from_email=settings.EMAIL_FROM_ADDRESS, |
| 609 | + reply_to=(settings.EMAIL_REPLY_TO_ADDRESS, ), |
607 | 610 | to=[team.team_leader.email])
|
608 | 611 | msg.attach_alternative(msg_html, "text/html")
|
609 | 612 | msg.send()
|
@@ -908,3 +911,87 @@ def post(self, request, project_key, user_email, *args, **kwargs):
|
908 | 911 | response['X-IC-Script'] += "$('#page-modal').modal('hide');"
|
909 | 912 |
|
910 | 913 | return response
|
| 914 | + |
| 915 | + |
| 916 | +@method_decorator([user_auth_and_jwt], name='dispatch') |
| 917 | +class UploadSignedAgreementFormFileView(View): |
| 918 | + """ |
| 919 | + View to upload signed agreement form files for participants. |
| 920 | +
|
| 921 | + * Requires token authentication. |
| 922 | + * Only admin users are able to access this view. |
| 923 | + """ |
| 924 | + def get(self, request, signed_agreement_form_id, *args, **kwargs): |
| 925 | + """ |
| 926 | + Return the upload form template |
| 927 | + """ |
| 928 | + user = request.user |
| 929 | + user_jwt = request.COOKIES.get("DBMI_JWT", None) |
| 930 | + |
| 931 | + signed_agreement_form = get_object_or_404(SignedAgreementForm, id=signed_agreement_form_id) |
| 932 | + |
| 933 | + sciauthz = SciAuthZ(user_jwt, user.email) |
| 934 | + is_manager = sciauthz.user_has_manage_permission(signed_agreement_form.project.project_key) |
| 935 | + |
| 936 | + if not is_manager: |
| 937 | + logger.debug('User {email} does not have MANAGE permissions for item {project_key}.'.format( |
| 938 | + email=user.email, |
| 939 | + project_key=signed_agreement_form.project.project_key |
| 940 | + )) |
| 941 | + return HttpResponse(403) |
| 942 | + |
| 943 | + # Return file upload form |
| 944 | + form = UploadSignedAgreementFormFileForm() |
| 945 | + |
| 946 | + # Set context |
| 947 | + context = { |
| 948 | + "form": form, |
| 949 | + "signed_agreement_form_id": signed_agreement_form_id, |
| 950 | + } |
| 951 | + |
| 952 | + # Render html |
| 953 | + return render(request, "manage/upload-signed-agreement-form-file.html", context) |
| 954 | + |
| 955 | + def post(self, request, signed_agreement_form_id, *args, **kwargs): |
| 956 | + """ |
| 957 | + Process the form |
| 958 | + """ |
| 959 | + user = request.user |
| 960 | + user_jwt = request.COOKIES.get("DBMI_JWT", None) |
| 961 | + |
| 962 | + signed_agreement_form = get_object_or_404(SignedAgreementForm, id=signed_agreement_form_id) |
| 963 | + |
| 964 | + sciauthz = SciAuthZ(user_jwt, user.email) |
| 965 | + is_manager = sciauthz.user_has_manage_permission(signed_agreement_form.project.project_key) |
| 966 | + |
| 967 | + if not is_manager: |
| 968 | + logger.debug('User {email} does not have MANAGE permissions for item {project_key}.'.format( |
| 969 | + email=user.email, |
| 970 | + project_key=signed_agreement_form.project.project_key |
| 971 | + )) |
| 972 | + return HttpResponse(403) |
| 973 | + |
| 974 | + # Assembles the form and run validation. |
| 975 | + form = UploadSignedAgreementFormFileForm(data=request.POST, files=request.FILES) |
| 976 | + if not form.is_valid(): |
| 977 | + logger.warning('Form failed: {}'.format(form.errors.as_json())) |
| 978 | + return HttpResponse(status=400) |
| 979 | + |
| 980 | + logger.debug(f"[upload_signed_agreement_form_file] Data -> {form.cleaned_data}") |
| 981 | + |
| 982 | + # Set the file and save |
| 983 | + signed_agreement_form.upload = form.cleaned_data['file'] |
| 984 | + signed_agreement_form.save() |
| 985 | + |
| 986 | + # Create the response. |
| 987 | + response = HttpResponse(status=201) |
| 988 | + |
| 989 | + # Setup the script run. |
| 990 | + response['X-IC-Script'] = "notify('{}', '{}', 'glyphicon glyphicon-{}');".format( |
| 991 | + "success", "Signed agreement form file successfully uploaded", "thumbs-up" |
| 992 | + ) |
| 993 | + |
| 994 | + # Close the modal |
| 995 | + response['X-IC-Script'] += "$('#page-modal').modal('hide');" |
| 996 | + |
| 997 | + return response |
0 commit comments