diff --git a/scipost_django/scipost/models.py b/scipost_django/scipost/models.py index c8d0af2c42506051849f5b8c255ad93388bfa136..45bac55a8c85ffae461e3a57c8acd2f17f254cd1 100644 --- a/scipost_django/scipost/models.py +++ b/scipost_django/scipost/models.py @@ -106,7 +106,7 @@ class Contributor(models.Model): null=True, ) # If this Contributor is merged into another, then this field is set to point to the new one: - duplicate_of = models.ForeignKey( + duplicate_of = models.ForeignKey["Contributor"]( "scipost.Contributor", on_delete=models.SET_NULL, null=True, diff --git a/scipost_django/submissions/templates/submissions/_report_public_without_comments.html b/scipost_django/submissions/templates/submissions/_report_public_without_comments.html index d04345c198c896d5d570be38a546a157ea69529e..6f0183a9fe4e2116cb2832137336a1e85b9417be 100644 --- a/scipost_django/submissions/templates/submissions/_report_public_without_comments.html +++ b/scipost_django/submissions/templates/submissions/_report_public_without_comments.html @@ -53,7 +53,7 @@ </div> {% endif %} {% else %} - {% if user|is_in_group:'Editorial Administrators' and not user|is_possible_author_of_submission:submission %} + {% if user|is_in_group:'Editorial Administrators' or user == report.author.user and not user|is_possible_author_of_submission:submission %} <button class="btn btn-sm btn-danger text-white my-2" hx-get="{% url "submissions:_hx_anonymize_report" report_id=report.id %}" hx-target="#report_{{report.report_nr}}" diff --git a/scipost_django/submissions/utils.py b/scipost_django/submissions/utils.py index a7a387ad6f8e0f9f7997acb5745133af3afdf5e9..69a3d8a811e6513b3627eef946239fb375ba670c 100644 --- a/scipost_django/submissions/utils.py +++ b/scipost_django/submissions/utils.py @@ -540,6 +540,25 @@ class SubmissionUtils(BaseMailUtil): f'the <a href="https://{domain}/submissions/' "{{ identifier_w_vn_nr }}\">Submission's page</a>.</p>" ) + if not cls.report.anonymous: + email_text += ( + "\n\nPlease note that your Report is not anonymous and thus your identity will be publicly visible. " + "You may anonymize your Report within 24 hours at " + f"https://{domain}/submissions/" + + cls.report.submission.preprint.identifier_w_vn_nr + + f"#report_{cls.report.report_nr}." + "\n\nIf you choose to do so, your identity will be immediately hidden from the public. " + "However, kindly understand that SciPost cannot guarantee that this information " + "has not already been saved by unaffiliated third-parties during the time in which is was public." + ) + email_text_html += ( + "\n<p>Please note that your Report is not anonymous and thus your identity will be publicly visible. " + f'You may anonymize your Report within 24 hours at the <a href="https://{domain}/submissions/"' + f"{{ identifier_w_vn_nr }}//#report_{cls.report.report_nr}\">Submission's page</a>.</p>" + "<p>If you choose to do so, your identity will be immediately hidden from the public. " + "However, kindly understand that SciPost cannot guarantee that this information " + "has not already been saved by unaffiliated third-parties during the time in which is was public.</p>" + ) else: email_text += ( "\n\nYour Report has been reviewed by the Editor-in-charge of the Submission, " diff --git a/scipost_django/submissions/views/__init__.py b/scipost_django/submissions/views/__init__.py index 11d0fbf3244569b8fbd863ae31c33d7448ae83ce..6b7f8f44a8d4adc1fce180e14e795a1f28ca82c6 100644 --- a/scipost_django/submissions/views/__init__.py +++ b/scipost_django/submissions/views/__init__.py @@ -22,7 +22,7 @@ from django.contrib.messages.views import SuccessMessageMixin from django.core.exceptions import PermissionDenied from django.db import transaction, IntegrityError from django.db.models import Q, Count, Sum -from django.http import Http404, HttpResponse, HttpResponseRedirect +from django.http import Http404, HttpRequest, HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404, get_list_or_404, render, redirect from django.template import Template, Context from django.urls import reverse, reverse_lazy @@ -899,16 +899,28 @@ def report_pdf_compile(request, report_id): @login_required -@user_passes_test(is_edadmin) -def _hx_anonymize_report(request, report_id): +def _hx_anonymize_report(request: HttpRequest, report_id): report = get_object_or_404(Report, id=report_id) - report.anonymous = True - report.save() - report.submission.add_event_for_eic( - f"{request.user.get_full_name()} anonymized " - f"referee report #{report.report_nr} " - f"(by {report.author.profile.full_name})" - ) + + is_report_author = report.author.user == request.user + if not (is_edadmin(request.user) or is_report_author): + raise PermissionDenied + + if is_report_author and report.date_submitted < ( + timezone.now() - datetime.timedelta(days=1) + ): + messages.error( + request, + "You can only anonymize your own report within 24 hours of submission.", + ) + else: + report.anonymous = True + report.save() + report.submission.add_event_for_eic( + f"{request.user.get_full_name()} anonymized " + f"referee report #{report.report_nr} " + f"(by {report.author.profile.full_name})" + ) return render( request,