Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide pending orgs from normal users #1488

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def setUp(self):
})
self.user.set_password('password')
self.user.save()
self.simple_user = UserF.create(**{
'username': 'user',
'password': 'password',
'is_staff': False
})

self.simple_user.set_password('password')
self.simple_user.save()
self.project = ProjectF.create()
self.certifying_organisation = CertifyingOrganisationF.create(
project=self.project
Expand Down Expand Up @@ -86,6 +94,17 @@ def test_list_pending_view(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['pending'], True)

@override_settings(VALID_DOMAIN=['testserver', ])
def test_list_pending_view_non_staff(self):
client = Client()
client.login(username='user', password='password')
response = client.get(
reverse('pending-certifyingorganisation-list',
kwargs={
'project_slug': self.project.slug
}) + '?ready=false')
self.assertEqual(response.status_code, 403)

@override_settings(VALID_DOMAIN=['testserver', ])
def test_list_pending_json(self):
client = Client()
Expand Down
26 changes: 24 additions & 2 deletions django_project/certification/views/certifying_organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
from django.http import HttpResponseRedirect, Http404
from django.db import IntegrityError
from django.core.exceptions import ValidationError
from braces.views import LoginRequiredMixin, UserPassesTestMixin
from braces.views import (
LoginRequiredMixin,
UserPassesTestMixin,
StaffuserRequiredMixin)
from django_datatables_view.base_datatable_view import BaseDatatableView
from django.contrib.sessions.models import Session
from pure_pagination.mixins import PaginationMixin
Expand Down Expand Up @@ -86,6 +89,25 @@ def convert_context_to_json(context):
return result


class CustomStaffuserRequiredMixin(StaffuserRequiredMixin):

"""Fix redirect loop when user is already authenticated but non staff."""

def no_permissions_fail(self, request=None):
"""
Called when the user has no permissions and no exception was raised.
"""
if not request.user.is_authenticated:
return super(
CustomStaffuserRequiredMixin, self).no_permissions_fail(
request)

return HttpResponse(
'Sorry! You do not have permission to perform this action.',
status=403
)


class CertifyingOrganisationMixin(object):
"""Mixin class to provide standard settings for Certifying Organisation."""

Expand Down Expand Up @@ -881,7 +903,7 @@ def filter_queryset(self, qs):


class PendingCertifyingOrganisationListView(
LoginRequiredMixin,
CustomStaffuserRequiredMixin,
CertifyingOrganisationMixin,
PaginationMixin,
ListView):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@
<li><a href="{% url 'about' the_project.slug %}">Learn about Certification</a></li>
<li><a href="{% url 'certifyingorganisation-create' the_project.slug %}">{% trans 'Sign Up for Certification!' %}</a></li>
<li><a href="{% url 'certifyingorganisation-list' the_project.slug %}">Approved Organisations</a></li>
<li><a href="{% url 'pending-certifyingorganisation-list' the_project.slug %}?ready=False">Pending Organisations</a></li>
<li><a href="{% url 'pending-certifyingorganisation-list' the_project.slug %}?ready=True">Pending Organisations - Ready</a></li>
{% if user.is_staff %}
<li><a href="{% url 'pending-certifyingorganisation-list' the_project.slug %}?ready=False">Pending Organisations</a></li>
<li><a href="{% url 'pending-certifyingorganisation-list' the_project.slug %}?ready=True">Pending Organisations - Ready</a></li>
{% endif %}
<li><a href="{% url 'validate-certificate-organisation' the_project.slug %}">Verify certificate for Certifying Organisation</a></li>
<li><a href="{% url 'validate-certificate' the_project.slug %}">Verify certificate for Attendee</a></li>
{% if user.is_staff or user in the_project.certification_managers.all %}
Expand Down
Loading