From 2f99a61de6197f694ec6623c3e7f44106d0080eb Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Mon, 28 Mar 2016 07:02:35 +0200 Subject: [PATCH] Removed contributor ranks, replaced by django groups and permissions --- .../commentaries/commentary_detail.html | 4 +- comments/models.py | 2 +- scipost/forms.py | 2 +- scipost/models.py | 18 +++----- scipost/templates/scipost/comments_block.html | 7 +-- .../scipost/thanks_for_registering.html | 2 +- .../scipost/vet_registration_requests.html | 6 +-- scipost/views.py | 43 +++++++++++++------ submissions/forms.py | 3 +- submissions/models.py | 2 +- .../submissions/submission_detail.html | 6 ++- theses/templates/theses/thesis_detail.html | 4 +- 12 files changed, 57 insertions(+), 42 deletions(-) diff --git a/commentaries/templates/commentaries/commentary_detail.html b/commentaries/templates/commentaries/commentary_detail.html index 120bbe5a7..032cbc1de 100644 --- a/commentaries/templates/commentaries/commentary_detail.html +++ b/commentaries/templates/commentaries/commentary_detail.html @@ -4,6 +4,8 @@ {% block headsup %} +{% load scipost_extras %} + <script> $(document).ready(function(){ $("#commentsbutton").click(function(){ @@ -49,7 +51,7 @@ {% include 'scipost/comments_block.html' %} -{% if user.is_authenticated and commentary.open_for_commenting and user.contributor.rank > 0 %} +{% if user.is_authenticated and commentary.open_for_commenting and user|is_in_group:'Registered Contributors' %} <section> <hr class="hr12"> <div class="flex-greybox"> diff --git a/comments/models.py b/comments/models.py index 73a2f9210..da6575a27 100644 --- a/comments/models.py +++ b/comments/models.py @@ -33,7 +33,7 @@ comment_status_dict = dict(COMMENT_STATUS) class Comment(models.Model): """ A Comment is an unsollicited note, submitted by a Contributor, on a particular publication or in reply to an earlier Comment. """ # status: - # 1: vetted (by Contributor with rank >= 2) + # 1: vetted # 0: unvetted # -1: rejected (unclear) # -2: rejected (incorrect) diff --git a/scipost/forms.py b/scipost/forms.py index 082dc0bda..f2a9f8687 100644 --- a/scipost/forms.py +++ b/scipost/forms.py @@ -72,7 +72,7 @@ class UpdatePersonalDataForm(forms.ModelForm): widgets = {'country_of_employment': CountrySelectWidget()} class VetRegistrationForm(forms.Form): - promote_to_rank_1 = forms.BooleanField(required=False) + promote_to_registered_contributor = forms.BooleanField(required=False, label='Accept registration') refuse = forms.BooleanField(required=False) refusal_reason = forms.ChoiceField(choices=REGISTRATION_REFUSAL_CHOICES, required=False) email_response_field = forms.CharField(widget=forms.Textarea(), label='Justification (optional)', required=False) diff --git a/scipost/models.py b/scipost/models.py index 39e779e7d..724e626e5 100644 --- a/scipost/models.py +++ b/scipost/models.py @@ -13,26 +13,18 @@ disciplines_dict = dict(SCIPOST_DISCIPLINES) -CONTRIBUTOR_RANKS = ( - # ranks determine the type of Contributor: +CONTRIBUTOR_STATUS = ( + # status determine the type of Contributor: # 0: newly registered (unverified; not allowed to submit, comment or vote) - # 1: normal user (allowed to submit, comment and vote) - # 2: scipost editor (1 + no need for vetting of comments, also allowed to vet commentary request and comments from normal users) - # 3: scipost journal editor (2 + allowed to accept papers in SciPost Journals) - # 4: scipost journal editor-in-chief - # 5: Lead Editor (all rights granted, including rank promotions and overriding all) + # 1: contributor has been vetted through # - # Negative ranks denote rejected requests or : + # Negative status denotes rejected requests or: # -1: not a professional scientist (defined as at least PhD student in known university) # -2: other account already exists for this person # -3: barred from SciPost (abusive behaviour) # -4: disabled account (deceased) (0, 'newly registered'), (1, 'normal user'), - (2, 'Commentary Editor'), - (3, 'Journal Specialty Editor'), - (4, 'Journal Editor-in-chief'), - (5, 'Field Head Editor'), (-1, 'not a professional scientist'), (-2, 'other account already exists'), (-3, 'barred from SciPost'), @@ -54,7 +46,7 @@ class Contributor(models.Model): # username, password, email, first_name and last_name are inherited from User activation_key = models.CharField(max_length=40, default='') key_expires = models.DateTimeField(default=timezone.now) - rank = models.SmallIntegerField(default=0, choices=CONTRIBUTOR_RANKS) + status = models.SmallIntegerField(default=0, choices=CONTRIBUTOR_STATUS) title = models.CharField(max_length=4, choices=TITLE_CHOICES) discipline = models.CharField(max_length=20, choices=SCIPOST_DISCIPLINES, default='physics') orcid_id = models.CharField(max_length=20, verbose_name="ORCID id", blank=True) diff --git a/scipost/templates/scipost/comments_block.html b/scipost/templates/scipost/comments_block.html index 0a68d70ea..735b37643 100644 --- a/scipost/templates/scipost/comments_block.html +++ b/scipost/templates/scipost/comments_block.html @@ -1,3 +1,4 @@ +{% load scipost_extras %} {% if comments %} <section> <hr class="hr12"> @@ -16,7 +17,7 @@ {{ comment.print_identifier|safe }} {{ comment.categories_as_ul|safe }} <div class="opinionsDisplay"> - {% if user.is_authenticated and user.contributor.rank > 0 %} + {% if user.is_authenticated and user|is_in_group:'Registered Contributors' %} {% if user.contributor != comment.author %} <form action="{% url 'comments:express_opinion' comment_id=comment.id opinion='A' %}" method="post"> {% csrf_token %} @@ -62,7 +63,7 @@ {{ reply.print_identifier|safe }} {{ reply.categories_as_ul|safe }} <div class="opinionsDisplay"> - {% if user.is_authenticated and user.contributor.rank > 0 %} + {% if user.is_authenticated and user|is_in_group:'Registered Contributors' %} {% if user.contributor != reply.author %} <form action="{% url 'comments:express_opinion' comment_id=reply.id opinion='A' %}" method="post"> {% csrf_token %} @@ -95,7 +96,7 @@ {% endif %} {% endfor %} - {% if user.is_authenticated and user.contributor.rank > 0 %} + {% if user.is_authenticated and user|is_in_group:'Registered Contributors' %} <div class="row"> <div class="col-1"></div> <hr class="hr6"/> diff --git a/scipost/templates/scipost/thanks_for_registering.html b/scipost/templates/scipost/thanks_for_registering.html index 619362c8d..ad7b2038a 100644 --- a/scipost/templates/scipost/thanks_for_registering.html +++ b/scipost/templates/scipost/thanks_for_registering.html @@ -7,7 +7,7 @@ <section> <h1>Thanks for registering to SciPost.</h1> <p>You will receive an email with a link to verify your email address. Please visit this link within 48 hours.</p> -<p>Your credentials will thereafter be verified. If your registration is accepted, your rank (currently: 'newly registered') will be set to 'normal user', enabling you to contribute.</p> +<p>Your credentials will thereafter be verified. If your registration is vetted through by the administrators, you will be enabled to contribute.</p> </section> {% endblock bodysup %} diff --git a/scipost/templates/scipost/vet_registration_requests.html b/scipost/templates/scipost/vet_registration_requests.html index fed3f55fc..5ccf996e8 100644 --- a/scipost/templates/scipost/vet_registration_requests.html +++ b/scipost/templates/scipost/vet_registration_requests.html @@ -28,7 +28,7 @@ $( document ).ready(function() { } } else { - if (clickedBox.attr("name") == "promote_to_rank_1"){ + if (clickedBox.attr("name") == "promote_to_registered_contributor"){ $(boxes[1]).prop('checked', false); if ($(specificTarget[0]).is(":visible")){ toggleBoxes(specificTarget) @@ -52,8 +52,8 @@ $( document ).ready(function() { {% else %} <h1>SciPost Registration requests to vet:</h1> - <p>These Contributors are currently on rank 0 (submitting, commenting and voting disabled).</p> - <p>Use this page to promote them to rank 1 or refuse registration.</p> + <p>These Contributors are currently not registered (submitting, commenting and voting disabled).</p> + <p>Use this page to promote them to give them registered status, or refuse registration.</p> {% for contributor_to_vet in contributors_to_vet %} <br> diff --git a/scipost/views.py b/scipost/views.py index a4a105d3d..77c49fa28 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -60,6 +60,23 @@ VettingEditors.permissions.add(can_vet_commentary_requests, can_vet_thesislink_r ) +############## +# Utilitites # +############## + +def is_registered(user): + return user.groups.filter(name='Registered Contributors').exists() + +def is_SP_Admin(user): + return user.groups.filter(name='SciPost Administrators').exists() + +def is_MEC(user): + return user.groups.filter(name='Editorial College').exists() + +def is_VE(user): + return user.groups.filter(name='Vetting Editors').exists() + + ############# # Main view ############# @@ -165,10 +182,9 @@ def request_new_activation_link(request, oldkey): @permission_required('scipost.can_vet_registration_requests') def vet_registration_requests(request): contributor = Contributor.objects.get(user=request.user) - #contributor_to_vet = Contributor.objects.filter(user__is_active=True, rank=0).first() # limit to one at a time - contributors_to_vet = Contributor.objects.filter(user__is_active=True, rank=0).order_by('key_expires') + contributors_to_vet = Contributor.objects.filter(user__is_active=True, status=0).order_by('key_expires') + reg_cont_group = Group.objects.get(name='Registered Contributors') form = VetRegistrationForm() - #context = {'contributor_to_vet': contributor_to_vet, 'form': form } context = {'contributors_to_vet': contributors_to_vet, 'form': form } return render(request, 'scipost/vet_registration_requests.html', context) @@ -179,11 +195,11 @@ def vet_registration_request_ack(request, contributor_id): form = VetRegistrationForm(request.POST) contributor = Contributor.objects.get(pk=contributor_id) if form.is_valid(): - if form.cleaned_data['promote_to_rank_1']: - contributor.rank = 1 + if form.cleaned_data['promote_to_registered_contributor']: + contributor.status = 1 contributor.vetted_by = request.user.contributor contributor.save() - group = Groups.objects.get(name='Registered Contributors') + group = Group.objects.get(name='Registered Contributors') request.user.groups.add(group) email_text = ('Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + ', \n\nYour registration to the SciPost publication portal has been accepted. ' + @@ -203,7 +219,7 @@ def vet_registration_request_ack(request, contributor_id): emailmessage = EmailMessage('SciPost registration: unsuccessful', email_text, 'registration@scipost.org', [contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) emailmessage.send(fail_silently=False) - contributor.rank = form.cleaned_data['refusal_reason'] + contributor.status = form.cleaned_data['refusal_reason'] contributor.save() context = {} @@ -267,7 +283,7 @@ def login_view(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) - if user is not None and user.contributor.rank > 0: + if user is not None and is_registered(user): if user.is_active: login(request, user) contributor = Contributor.objects.get(user=request.user) @@ -295,21 +311,20 @@ def personal_page(request): nr_reg_to_vet = 0 nr_reg_awaiting_validation = 0 nr_submissions_to_process = 0 - if contributor.rank >= 4: + if is_SP_Admin(request.user): now = timezone.now() intwodays = now + timezone.timedelta(days=2) - # count the number of pending registration request - nr_reg_to_vet = Contributor.objects.filter(user__is_active=True, rank=0).count() + # count the number of pending registration requests + nr_reg_to_vet = Contributor.objects.filter(user__is_active=True, status=0).count() nr_reg_awaiting_validation = Contributor.objects.filter( - user__is_active=False, key_expires__gte=now, key_expires__lte=intwodays, rank=0 - ).count() + user__is_active=False, key_expires__gte=now, key_expires__lte=intwodays, status=0).count() nr_submissions_to_process = Submission.objects.filter(vetted=False).count() nr_commentary_page_requests_to_vet = 0 nr_comments_to_vet = 0 nr_reports_to_vet = 0 nr_thesislink_requests_to_vet = 0 nr_authorship_claims_to_vet = 0 - if contributor.rank >= 2: + if is_VE(request.user): nr_commentary_page_requests_to_vet = Commentary.objects.filter(vetted=False).count() nr_comments_to_vet = Comment.objects.filter(status=0).count() nr_reports_to_vet = Report.objects.filter(status=0).count() diff --git a/submissions/forms.py b/submissions/forms.py index 7c0388d27..5b4ea273c 100644 --- a/submissions/forms.py +++ b/submissions/forms.py @@ -1,4 +1,5 @@ from django import forms +from django.contrib.auth.models import User, Group from .models import * @@ -14,7 +15,7 @@ class SubmissionForm(forms.ModelForm): self.fields['abstract'].widget.attrs.update({'cols': 100}) class ProcessSubmissionForm(forms.Form): - editor_in_charge = forms.ModelChoiceField(queryset=Contributor.objects.filter(rank__gte=3), required=True, label='Select an Editor-in-charge') + editor_in_charge = forms.ModelChoiceField(queryset=Contributor.objects.filter(user__groups__name='Editorial College'), required=True, label='Select an Editor-in-charge') class SubmissionSearchForm(forms.Form): author = forms.CharField(max_length=100, required=False, label="Author(s)") diff --git a/submissions/models.py b/submissions/models.py index 8b0e70701..17aff76b7 100644 --- a/submissions/models.py +++ b/submissions/models.py @@ -125,7 +125,7 @@ REPORT_REC = ( class Report(models.Model): """ Both types of reports, invited or contributed. """ # status: - # 1: vetted (by Contributor with rank >= 2) + # 1: vetted # 0: unvetted # -1: rejected (unclear) # -2: rejected (incorrect) diff --git a/submissions/templates/submissions/submission_detail.html b/submissions/templates/submissions/submission_detail.html index 7f188bbf4..ca736098c 100644 --- a/submissions/templates/submissions/submission_detail.html +++ b/submissions/templates/submissions/submission_detail.html @@ -4,6 +4,8 @@ {% block headsup %} +{% load scipost_extras %} + <script> $(document).ready(function(){ $("#reportsbutton").click(function(){ @@ -113,7 +115,7 @@ {% endif %} -{% if user.is_authenticated and submission.open_for_reporting and user.contributor.rank > 0 %} +{% if user.is_authenticated and submission.open_for_reporting and user|is_in_group:'Registered Contributors' %} <section> <hr class="hr6"> <div class="row"> @@ -127,7 +129,7 @@ {% include 'scipost/comments_block.html' %} -{% if user.is_authenticated and submission.open_for_commenting and user.contributor.rank > 0 %} +{% if user.is_authenticated and submission.open_for_commenting and user|is_in_group:'Registered Contributors' %} <section> <hr class="hr12"> <div class="flex-greybox"> diff --git a/theses/templates/theses/thesis_detail.html b/theses/templates/theses/thesis_detail.html index f7c907514..28fbffece 100644 --- a/theses/templates/theses/thesis_detail.html +++ b/theses/templates/theses/thesis_detail.html @@ -4,6 +4,8 @@ {% block headsup %} +{% load scipost_extras %} + <script> $(document).ready(function(){ $("#commentsbutton").click(function(){ @@ -40,7 +42,7 @@ {% include 'scipost/comments_block.html' %} -{% if user.is_authenticated and thesislink.open_for_commenting and user.contributor.rank > 0 %} +{% if user.is_authenticated and thesislink.open_for_commenting and user|is_in_group:'Registered Contributors' %} <section> <hr class="hr12"> <div class="flex-greybox"> -- GitLab