diff --git a/comments/views.py b/comments/views.py index 1d952dd960767fe8ed76243dfa38dbc7e5f55534..2e3bcef7f52140600b04c263e668284212ccb2ce 100644 --- a/comments/views.py +++ b/comments/views.py @@ -53,6 +53,8 @@ def vet_submitted_comment_ack(request, comment_id): elif form.cleaned_data['action_option'] == '2': # the comment request is simply rejected comment.status = int(form.cleaned_data['refusal_reason']) + if comment.status == 0: + comment.status == -1 comment.save() email_text = ('Dear ' + title_dict[comment.author.title] + ' ' + comment.author.user.last_name + ', \n\nThe Comment you have submitted, concerning publication with title ') diff --git a/scipost/models.py b/scipost/models.py index ec91a80630f5d61fe93fbc4a7da85a70d625d6a7..39e779e7de30783aa76815491a6aacda2082eca8 100644 --- a/scipost/models.py +++ b/scipost/models.py @@ -1,6 +1,6 @@ from django.utils import timezone from django.db import models -from django.contrib.auth.models import User +from django.contrib.auth.models import User, Group from django_countries.fields import CountryField @@ -64,6 +64,17 @@ class Contributor(models.Model): personalwebpage = models.URLField(verbose_name='personal web page', blank=True) vetted_by = models.OneToOneField('self', blank=True, null=True) + class Meta: + permissions = ( + ('can_manage_registration_invitations', 'Can manage registration invitations'), + ('can_vet_registration_requests', 'Can vet registration requests'), + ('can_vet_commentary_requests', 'Can vet Commentary page requests'), + ('can_vet_thesislink_requests', 'Can vet Thesis Link requests'), + ('can_vet_authorship_claims', 'Can vet Authorship claims'), + ('can_vet_comments', 'Can vet submitted comments'), + ('can_process_incoming_submissions', 'Can process incoming Submissions'), + ('can_vet_submitted_reports', 'Can vet submitted Reports'), + ) def __str__ (self): return self.user.last_name + ', ' + self.user.first_name @@ -95,6 +106,24 @@ class Contributor(models.Model): return output + + +################## +#### Groups ###### +################## + +SciPostAdmin, created = Group.objects.get_or_create(name='SciPost Administrators') + +AdvisoryBoard, created = Group.objects.get_or_create(name='Advisory Board') + +EditorialCollege, created = Group.objects.get_or_create(name='Editorial College') + +VettingEditors, created = Group.objects.get_or_create(name='Vetting Editors') + +RegisteredContributors, created = Group.objects.get_or_create(name='Registered Contributors') + + + INVITATION_TYPE = ( ('F', 'Editorial Fellow'), ('C', 'Contributor'), diff --git a/scipost/templates/scipost/personal_page.html b/scipost/templates/scipost/personal_page.html index ad938b91c0bb3ee4fe1545c423fa1bec024ae58b..a36bc2b4f10c393c8b7d65804d016188e7b2bfdc 100644 --- a/scipost/templates/scipost/personal_page.html +++ b/scipost/templates/scipost/personal_page.html @@ -4,6 +4,8 @@ {% block headsup %} +{% load scipost_extras %} + <script> $(document).ready(function(){ $("#mysubmissionsbutton").click(function(){ @@ -28,9 +30,18 @@ {% block bodysup %} +{% if not request.user|is_in_group:'Registered Contributors' %} +<section> + <hr class="hr12"> + <h3>Your credentials will soon be verified by an Editor.</h3> + <p>If accepted, you will become a registered Contributor, enabling you to submit, comment and vote.</p> +</section> + +{% else %} + <section> <div class="flex-greybox"> - <h1>Welcome to your SciPost Personal Page, {{ user.username }} (rank {{ contributor.rank }} Contributor)</h1> + <h1>Welcome to your SciPost Personal Page, {{ user.username }} </h1> </div> <hr class="hr12"> @@ -43,6 +54,22 @@ {{ contributor.private_info_as_table|safe }} </div> <div class="col-6"> + {% if request.user|is_in_group:'SciPost Administrators' %} + <h3>You are a SciPost Administrator.</h3> + {% endif %} + {% if request.user|is_in_group:'Advisory Board' %} + <h3>You are a member of the Advisory Board.</h3> + {% endif %} + {% if request.user|is_in_group:'Editorial College' %} + <h3>You are a member of the Editorial College.</h3> + {% endif %} + {% if request.user|is_in_group:'Vetting Editors' %} + <h3>You are a SciPost Vetting Editor.</h3> + {% endif %} + {% if request.user|is_in_group:'Registered Contributors' %} + <h3>You are a Registered Contributor.</h3> + {% endif %} + <br/> <h3>Update your personal data or password</h3> <ul> <li><a href="{% url 'scipost:update_personal_data' %}">Update your personal data</a></li> @@ -52,7 +79,7 @@ </div> </section> -{% if contributor.rank >= 2 %} +{% if request.user|is_in_group:'Vetting Editors' %} <section> <hr class="hr12"> <div class="flex-greybox"> @@ -60,13 +87,13 @@ </div> <br> <div class="row"> - {% if contributor.rank >= 4 %} + {% if request.user|is_in_group:'SciPost Administrators' %} <div class="col-4"> <h3>Registration actions</h3> <ul> <li><a href="{% url 'scipost:vet_registration_requests' %}">Vet Registration requests</a> ({{ nr_reg_to_vet }})</li> - <li>Awaiting validation ({{ nr_reg_awaiting_validation }}) (no action necessary)</li> - <li><a href="{% url 'scipost:registration_invitations' %}">Manage Registration Invitations</a></li> + <li>Awaiting validation ({{ nr_reg_awaiting_validation }}) (no action necessary)</li> + <li><a href="{% url 'scipost:registration_invitations' %}">Manage Registration Invitations</a></li> </ul> </div> {% endif %} @@ -81,13 +108,11 @@ <li><a href="{% url 'scipost:vet_authorship_claims' %}">Vet Authorship Claims</a> ({{ nr_authorship_claims_to_vet }})</li> </ul> </div> - {% if contributor.rank >= 3 %} + {% if request.user|is_in_group:'Editorial College' %} <div class="col-4"> <h3>Submissions processing</h3> <ul> - {% if contributor.rank >= 4 %} <li><a href="{% url 'submissions:process_new_submissions' %}">Process new SciPost Submissions</a> ({{ nr_submissions_to_process }})</li> - {% endif %} </ul> </div> {% endif %} @@ -167,13 +192,6 @@ </div> </section> -{% if contributor.rank == 0 %} -<section> - <hr class="hr12"> - <p>Your credentials will soon be verified by an Editor. If accepted, your rank (currently 0: newly registered) will be set to 1 (normal user), enabling you to submit, comment and vote.</p> -</section> -{% endif %} - {% if own_comments %} <section> <hr class="hr12"> @@ -208,4 +226,6 @@ </section> {% endif %} +{% endif %} + {% endblock bodysup %} diff --git a/scipost/templatetags/__init__.py b/scipost/templatetags/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scipost/templatetags/scipost_extras.py b/scipost/templatetags/scipost_extras.py new file mode 100644 index 0000000000000000000000000000000000000000..73dd7f02847c018683156960dc0f572e719178fb --- /dev/null +++ b/scipost/templatetags/scipost_extras.py @@ -0,0 +1,9 @@ +from django import template +from django.contrib.auth.models import Group + +register = template.Library() + +@register.filter(name='is_in_group') +def is_in_group(user, group_name): + group = Group.objects.get(name=group_name) + return True if group in user.groups.all() else False diff --git a/scipost/views.py b/scipost/views.py index 9f3a1da83e3771b512b267606b79d9a9ca379fa6..a4a105d3d78ed988104ecd8dbd751c6a4a690cd6 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -6,7 +6,8 @@ import string from django.utils import timezone from django.shortcuts import get_object_or_404, render from django.contrib.auth import authenticate, login, logout -from django.contrib.auth.models import User +from django.contrib.auth.decorators import permission_required +from django.contrib.auth.models import User, Group, Permission from django.contrib.auth.views import password_reset, password_reset_confirm from django.core.mail import EmailMessage from django.core.urlresolvers import reverse @@ -33,6 +34,32 @@ from theses.models import ThesisLink from theses.forms import ThesisLinkSearchForm +################################ +# Assign permissions to groups # +################################ + +# Registration +can_manage_registration_invitations = Permission.objects.get(codename='can_manage_registration_invitations') +can_vet_registration_requests = Permission.objects.get(codename='can_vet_registration_requests') +# Vetting of simple objects +can_vet_commentary_requests = Permission.objects.get(codename='can_vet_commentary_requests') +can_vet_thesislink_requests = Permission.objects.get(codename='can_vet_thesislink_requests') +can_vet_authorship_claims = Permission.objects.get(codename='can_vet_authorship_claims') +can_vet_comments = Permission.objects.get(codename='can_vet_comments') +# Submission handling +can_process_incoming_submissions = Permission.objects.get(codename='can_process_incoming_submissions') +can_vet_submitted_reports = Permission.objects.get(codename='can_vet_submitted_reports') + +SciPostAdmin.permissions.add(can_manage_registration_invitations, + can_vet_registration_requests, + can_vet_commentary_requests, can_vet_thesislink_requests, + can_vet_authorship_claims, can_vet_comments, + ) +VettingEditors.permissions.add(can_vet_commentary_requests, can_vet_thesislink_requests, + can_vet_authorship_claims, can_vet_comments, + ) + + ############# # Main view ############# @@ -135,7 +162,7 @@ def request_new_activation_link(request, oldkey): return render (request, 'scipost/request_new_activation_link_ack.html') - +@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 @@ -145,7 +172,7 @@ def vet_registration_requests(request): context = {'contributors_to_vet': contributors_to_vet, 'form': form } return render(request, 'scipost/vet_registration_requests.html', context) - +@permission_required('scipost.can_vet_registration_requests') def vet_registration_request_ack(request, contributor_id): # process the form if request.method == 'POST': @@ -156,6 +183,8 @@ def vet_registration_request_ack(request, contributor_id): contributor.rank = 1 contributor.vetted_by = request.user.contributor contributor.save() + group = Groups.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. ' + 'You can now login and contribute. \n\nThe SciPost Team.')