From a018f330d3cdc94f8f770e794f0c1ada7b07682c Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Sat, 19 May 2018 11:51:39 +0200 Subject: [PATCH] Not finished. --- submissions/helpers.py | 28 ++++++- .../submission_author_information.html | 2 +- .../submission_editorial_information.html | 2 +- .../submissions/submission_detail.html | 70 ++++++++-------- submissions/views.py | 81 +++++++++---------- 5 files changed, 98 insertions(+), 85 deletions(-) diff --git a/submissions/helpers.py b/submissions/helpers.py index 766a11c8f..f5f6c2eec 100644 --- a/submissions/helpers.py +++ b/submissions/helpers.py @@ -8,8 +8,7 @@ from .exceptions import ArxivPDFNotFound def retrieve_pdf_from_arxiv(arxiv_id): - """ - Try to download the pdf as bytes object from arXiv for a certain arXiv Identifier. + """Try to download the pdf as bytes object from arXiv for a certain arXiv Identifier. Raise ArxivPDFNotFound instead. :arxiv_id: Arxiv Identifier with or without (takes latest version instead) version number @@ -19,3 +18,28 @@ def retrieve_pdf_from_arxiv(arxiv_id): if response.status_code != 200: raise ArxivPDFNotFound('No pdf found on arXiv.') return response.content + + +def check_verified_author(submission, user): + """Check if user is verified author of Submission.""" + if not hasattr(user, 'contributor'): + return False + + return submission.authors.filter(user=user).exists() + + +def check_unverified_author(submission, user): + """Check if user may be author of Submission. + + Only return true if author is unverified. Verified authors will return false. + """ + if not hasattr(user, 'contributor'): + return False + + if submission.authors.filter(user=user).exists(): + # User is verified author. + return False + + return ( + user.last_name in submission.author_list and + not submission.authors_false_claims.filter(user=user).exists()) diff --git a/submissions/templates/partials/submissions/submission_author_information.html b/submissions/templates/partials/submissions/submission_author_information.html index ed192e918..f5e7d4d4a 100644 --- a/submissions/templates/partials/submissions/submission_author_information.html +++ b/submissions/templates/partials/submissions/submission_author_information.html @@ -1,6 +1,6 @@ {% load bootstrap %} -<h2 class="highlight">Author information</h2> +<h3 class="highlight">Author information <small><small class="text-muted"><i class="fa fa-question-circle-o" data-toggle="tooltip" data-title="You see this information because you are a verified author of this Submission."></i></small></small></h3> <a href="javascript:;" class="btn btn-default mb-2" data-toggle="toggle" data-target="#authorinformation">Show/hide author information</a> <div id="authorinformation" class="mt-2"> diff --git a/submissions/templates/partials/submissions/submission_editorial_information.html b/submissions/templates/partials/submissions/submission_editorial_information.html index fde63531b..c873fbd2c 100644 --- a/submissions/templates/partials/submissions/submission_editorial_information.html +++ b/submissions/templates/partials/submissions/submission_editorial_information.html @@ -1,6 +1,6 @@ {% load bootstrap %} -<h2 class="highlight">Editorial information</h2> +<h3 class="highlight">Editorial information</h3> <a href="javascript:;" class="btn btn-default mb-2" data-toggle="toggle" data-target="#editorialinformation">Show/hide editorial information</a> <div id="editorialinformation" class="mt-2"> diff --git a/submissions/templates/submissions/submission_detail.html b/submissions/templates/submissions/submission_detail.html index f14586d26..99e0513f7 100644 --- a/submissions/templates/submissions/submission_detail.html +++ b/submissions/templates/submissions/submission_detail.html @@ -20,12 +20,27 @@ {% block content %} <div class="row"> + {% if is_author_unchecked %} + <div class="col-12"> + <div class="border border-warning py-2 px-3 mb-3"> + <h3><i class="fa fa-exclamation-circle text-warning"></i> Please advise</h3> + The system flagged you as a potential author of this Submission. Please <a href="{% url 'scipost:claim_authorships' %}">clarify this here</a>. Particular actions and information may be blocked until your authorship has been verified. + </div> + </div> + {% endif %} + {% if unfinished_report_for_user %} + <div class="col-12"> + <div class="border border-warning py-2 px-3 mb-3"> + <i class="fa fa-exclamation-circle text-warning"></i> You have an unfinished report for this submission, <a href="{% url 'submissions:submit_report' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}">finish your report here.</a></h3> + </div> + </div> + {% endif %} <div class="col-md-8"> <h2>SciPost Submission Page</h2> <h1 class="text-primary">{{submission.title}}</h1> <h3 class="mb-3">by {{submission.author_list}}</h3> - <div class="pl-2"> + <div class="pl-2 mb-1"> {% if submission.publication and submission.publication.is_published %} <h3>- Published as <a href="{{submission.publication.get_absolute_url}}"> {% if submission.publication.in_issue %} @@ -41,10 +56,6 @@ <h3>- You are the Editor-in-charge, go to the <a href="{% url 'submissions:editorial_page' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}">Editorial Page</a> to take editorial actions</h3> {% endif %} - {% if unfinished_report_for_user %} - <h3>- <span class="circle text-danger border-danger">!</span> You have an unfinished report for this submission, <a href="{% url 'submissions:submit_report' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}">finish your report here.</a></h3> - {% endif %} - {% if not submission.is_current %} <h3><span class="text-danger">- This is not the current version.</span></h3> {% endif %} @@ -82,14 +93,6 @@ {% if is_author %} {% include 'partials/submissions/submission_author_information.html' with submission=submission %} -{% elif is_author_unchecked %} - - <div class="border border-warning py-2 px-3 mb-4"> - <h3>Advise</h3> - The system flagged you as a potential author of this Submission. - Please go to your <a href="{% url 'scipost:personal_page' %}">personal page</a> - under the Submissions tab to clarify this. - </div> {% endif %} {% if can_read_editorial_information %} @@ -99,23 +102,24 @@ {% if perms.scipost.can_submit_comments %} <div class="row"> <div class="col-12"> - <h2 class="highlight">Actions</h2> + <h3 class="highlight">Actions</h3> <ul> - {% if submission.open_for_reporting %} - {% if perms.scipost.can_referee and not is_author and not is_author_unchecked %} + {% if submission.is_open_for_reporting and perms.scipost.can_referee %} + {% if not is_author and not is_author_unchecked %} <li> - <h3><a href="{% url 'submissions:submit_report' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}">{% if unfinished_report_for_user %}Finish your report{% else %}Contribute a Report{% endif %}</a></h3> <div class="text-danger">Deadline for reporting: {{ submission.reporting_deadline|date:"Y-m-d" }}</div> </li> {% elif is_author_unchecked %} <li> - <h3 class="text-blue">Contribute a Report [deactivated]</h3> - <div>The system flagged you as a potential author of this Submission. - Please go to your <a href="{% url 'scipost:personal_page' %}">personal page</a> - under the Submissions tab to clarify this.</div> + <h3><a href="javascript:;">Contribute a Report</a> <small><span class="text-danger">[deactivated]</span></small></h3> + <div class="border border-warning py-2 px-3 mb-2"> + The system flagged you as a potential author of this Submission. Please <a href="{% url 'scipost:claim_authorships' %}">clarify this here</a>. You are not allowed to contributor a Report until your authorship has been verified. + </div> </li> {% endif %} + {% elif unfinished_report_for_user %} + <li><i class="fa fa-exclamation"></i> You have an unfinished report for this submission. You can <a href="{% url 'submissions:submit_report' arxiv_identifier_w_vn_nr=submission.arxiv_identifier_w_vn_nr %}">finish your report here</a>.</li> {% else %} <li>Reporting for this Submission is closed.</li> {% endif %} @@ -126,15 +130,13 @@ {% else %} <li>Commenting on this Submission is closed.</li> {% endif %} - </ul> - {% if perms.scipost.can_manage_reports %} - <h3>Admin Actions</h3> - <ul> + + {% if perms.scipost.can_manage_reports %} <li> <a href="{% url 'submissions:treated_submission_pdf_compile' submission.arxiv_identifier_w_vn_nr %}">Update the Refereeing Package pdf</a> </li> - <ul> - {% endif %} + {% endif %} + <ul> </div> </div> {% endif %} @@ -165,17 +167,11 @@ {% if contributed_reports %} <hr class="divider"> -<div class="row"> - <div class="col-12"> - <div class="card card-grey"> - <div class="card-body"> - <h2 class="card-title mb-0">Contributed Reports on this Submission</h2> - <a href="javascript:;" data-toggle="toggle" data-target="#contributedreportslist">Toggle contributed reports view</a> - </div> - </div> - </div> -</div> +<div class="mb-3"> + <h2 class="highlight">Contributed Reports on this Submission</h2> + <a href="javascript:;" data-toggle="toggle" data-target="#contributedreportslist">Show/hide contributed reports</a> +</div> <div id="contributedreportslist"> {% for report in contributed_reports %} {% include 'partials/submissions/report_public.html' with report=report user=request.user perms=perms %} diff --git a/submissions/views.py b/submissions/views.py index 27562a478..00c5d84a2 100644 --- a/submissions/views.py +++ b/submissions/views.py @@ -24,6 +24,7 @@ from django.views.generic.list import ListView from .constants import ( STATUS_VETTED, STATUS_EIC_ASSIGNED, SUBMISSION_STATUS, STATUS_ASSIGNMENT_FAILED, STATUS_DRAFT, CYCLE_DIRECT_REC) +from .helpers import check_verified_author, check_unverified_author from .models import ( Submission, EICRecommendation, EditorialAssignment, RefereeInvitation, Report, SubmissionEvent) from .mixins import SubmissionAdminViewMixin @@ -196,22 +197,9 @@ def submission_detail(request, arxiv_identifier_w_vn_nr): 'can_read_editorial_information': False } - if hasattr(request.user, 'contributor'): - # Check if Contributor is author of the Submission - is_author = submission.authors.filter(user=request.user).exists() - if is_author: - is_author_unchecked = not submission.authors_false_claims.filter( - user=request.user).exists() and request.user.last_name in submission.author_list - else: - is_author_unchecked = False - - unfinished_report_for_user = submission.reports.in_draft().filter( - author__user=request.user).first() - context['proofs_decision_form'] = ProofsDecisionForm() - else: - is_author = False - is_author_unchecked = False - unfinished_report_for_user = None + # Check if Contributor is author of the Submission + is_author = check_verified_author(submission, request.user) + is_author_unchecked = check_unverified_author(submission, request.user) if not submission.visible_public and not is_author: if not request.user.is_authenticated: @@ -221,6 +209,9 @@ def submission_detail(request, arxiv_identifier_w_vn_nr): contributor__user=request.user).exists(): raise Http404 + if is_author: + context['proofs_decision_form'] = ProofsDecisionForm() + if submission.open_for_commenting and request.user.has_perms('scipost.can_submit_comments'): context['comment_form'] = CommentForm() @@ -231,16 +222,23 @@ def submission_detail(request, arxiv_identifier_w_vn_nr): # User is referee for the Submission if request.user.is_authenticated: + context['unfinished_report_for_user'] = submission.reports.in_draft().filter( + author__user=request.user).first() context['invitations'] = submission.referee_invitations.filter(referee__user=request.user) - # User may read eg. Editorial Recommendations if he/she is in the Pool. - context['can_read_editorial_information'] = submission.fellows.filter( - contributor__user=request.user).exists() + if is_author or is_author_unchecked: + # Authors are not allowed to read all editorial info! Whatever + # their permission level is. + context['can_read_editorial_information'] = False + else: + # User may read eg. Editorial Recommendations if he/she is in the Pool. + context['can_read_editorial_information'] = submission.fellows.filter( + contributor__user=request.user).exists() - # User may also read eg. Editorial Recommendations if he/she is editorial administrator. - if not context['can_read_editorial_information']: - context['can_read_editorial_information'] = request.user.has_perm( - 'can_oversee_refereeing') + # User may also read eg. Editorial Recommendations if he/she is editorial administrator. + if not context['can_read_editorial_information']: + context['can_read_editorial_information'] = request.user.has_perm( + 'can_oversee_refereeing') if 'invitations' in context and context['invitations']: context['communication'] = submission.editorial_communications.for_referees().filter( @@ -254,7 +252,6 @@ def submission_detail(request, arxiv_identifier_w_vn_nr): 'comments': comments, 'invited_reports': invited_reports, 'contributed_reports': contributed_reports, - 'unfinished_report_for_user': unfinished_report_for_user, 'author_replies': author_replies, 'is_author': is_author, 'is_author_unchecked': is_author_unchecked, @@ -1295,17 +1292,22 @@ def submit_report(request, arxiv_identifier_w_vn_nr): for the current user on this submission. """ submission = get_object_or_404(Submission, arxiv_identifier_w_vn_nr=arxiv_identifier_w_vn_nr) + # Check whether the user can submit a report: - current_contributor = request.user.contributor - is_author = current_contributor in submission.authors.all() - is_author_unchecked = (not is_author and not - (current_contributor in submission.authors_false_claims.all()) and - (request.user.last_name in submission.author_list)) + is_author = check_verified_author(submission, request.user) + is_author_unchecked = check_unverified_author(submission, request.user) invitation = submission.referee_invitations.filter( - fulfilled=False, cancelled=False, referee=current_contributor).first() + fulfilled=False, cancelled=False, referee__user=request.user).first() errormessage = None - if not invitation: + if is_author: + errormessage = 'You are an author of this Submission and cannot submit a Report.' + elif is_author_unchecked: + errormessage = ('The system flagged you as a potential author of this Submission. ' + 'Please go to your personal page under the Submissions tab' + ' to clarify this.') + elif not invitation: + # User is going to contribute a Report. Check deadlines for doing so. if timezone.now() > submission.reporting_deadline + datetime.timedelta(days=1): errormessage = ('The reporting deadline has passed. You cannot submit' ' a Report anymore.') @@ -1315,26 +1317,17 @@ def submit_report(request, arxiv_identifier_w_vn_nr): if errormessage: # Remove old drafts from the database - reports_in_draft_to_remove = (submission.reports.in_draft() - .filter(author=current_contributor)) - if reports_in_draft_to_remove: - reports_in_draft_to_remove.delete() - if is_author: - errormessage = 'You are an author of this Submission and cannot submit a Report.' - if is_author_unchecked: - errormessage = ('The system flagged you as a potential author of this Submission. ' - 'Please go to your personal page under the Submissions tab' - ' to clarify this.') + submission.reports.in_draft().filter(author__user=request.user).delete() if errormessage: messages.warning(request, errormessage) - return redirect(reverse('scipost:personal_page')) + return redirect(submission.get_absolute_url()) # Find and fill earlier version of report try: - report_in_draft = submission.reports.in_draft().get(author=current_contributor) + report_in_draft = submission.reports.in_draft().get(author__user=request.user) except Report.DoesNotExist: - report_in_draft = Report(author=current_contributor, submission=submission) + report_in_draft = Report(author=request.user.contributor, submission=submission) form = ReportForm(request.POST or None, instance=report_in_draft, submission=submission) # Check if data sent is valid -- GitLab