mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-06-12 04:36:44 +02:00
separate authorisation function from decorator
This commit is contained in:
parent
aea940cb3f
commit
581e43a3b0
@ -4,14 +4,12 @@ from helpdesk import settings as helpdesk_settings
|
|||||||
|
|
||||||
if helpdesk_settings.HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK:
|
if helpdesk_settings.HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK:
|
||||||
# apply a custom user validation condition
|
# apply a custom user validation condition
|
||||||
helpdesk_staff_member_required = user_passes_test(helpdesk_settings.HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK)
|
is_helpdesk_staff = helpdesk_settings.HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK
|
||||||
elif helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE:
|
elif helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE:
|
||||||
# treat 'normal' users like 'staff'
|
# treat 'normal' users like 'staff'
|
||||||
helpdesk_staff_member_required = user_passes_test(lambda u: u.is_authenticated() and u.is_active)
|
is_helpdesk_staff = lambda u: u.is_authenticated() and u.is_active
|
||||||
else:
|
else:
|
||||||
try:
|
is_helpdesk_staff = lambda u: u.is_authenticated() and u.is_active and u.is_staff
|
||||||
from django.contrib.admin.views.decorators import staff_member_required as helpdesk_staff_member_required
|
|
||||||
except ImportError:
|
|
||||||
helpdesk_staff_member_required = user_passes_test(lambda u: u.is_authenticated() and u.is_active and u.is_staff)
|
|
||||||
|
|
||||||
|
helpdesk_staff_member_required = user_passes_test(is_helpdesk_staff)
|
||||||
helpdesk_superuser_required = user_passes_test(lambda u: u.is_authenticated() and u.is_active and u.is_superuser)
|
helpdesk_superuser_required = user_passes_test(lambda u: u.is_authenticated() and u.is_active and u.is_superuser)
|
||||||
|
@ -39,7 +39,6 @@ class KBDisabledTestCase(TestCase):
|
|||||||
class StaffUserTestCaseMixin(object):
|
class StaffUserTestCaseMixin(object):
|
||||||
HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE = False
|
HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE = False
|
||||||
HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK = None
|
HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK = None
|
||||||
expected_login_template = 'admin/login.html'
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_settings = settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE, settings.HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK
|
self.old_settings = settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE, settings.HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK
|
||||||
@ -62,13 +61,12 @@ class StaffUserTestCaseMixin(object):
|
|||||||
def test_anonymous_user(self):
|
def test_anonymous_user(self):
|
||||||
"""Access to the dashboard always requires a login"""
|
"""Access to the dashboard always requires a login"""
|
||||||
response = self.client.get(reverse('helpdesk_dashboard'), follow=True)
|
response = self.client.get(reverse('helpdesk_dashboard'), follow=True)
|
||||||
self.assertTemplateUsed(response, self.expected_login_template)
|
self.assertTemplateUsed(response, 'helpdesk/registration/login.html')
|
||||||
|
|
||||||
|
|
||||||
class NonStaffUsersAllowedTestCase(StaffUserTestCaseMixin, TestCase):
|
class NonStaffUsersAllowedTestCase(StaffUserTestCaseMixin, TestCase):
|
||||||
HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE = True
|
HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE = True
|
||||||
HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK = None
|
HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK = None
|
||||||
expected_login_template = 'helpdesk/registration/login.html'
|
|
||||||
|
|
||||||
def test_non_staff_allowed(self):
|
def test_non_staff_allowed(self):
|
||||||
"""If HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE is True,
|
"""If HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE is True,
|
||||||
@ -100,7 +98,6 @@ class StaffUsersOnlyTestCase(StaffUserTestCaseMixin, TestCase):
|
|||||||
|
|
||||||
class CustomStaffUserTestCase(StaffUserTestCaseMixin, TestCase):
|
class CustomStaffUserTestCase(StaffUserTestCaseMixin, TestCase):
|
||||||
HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE = False
|
HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE = False
|
||||||
expected_login_template = 'helpdesk/registration/login.html'
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK(user):
|
def HELPDESK_CUSTOM_STAFF_FILTER_CALLBACK(user):
|
||||||
@ -122,4 +119,4 @@ class CustomStaffUserTestCase(StaffUserTestCaseMixin, TestCase):
|
|||||||
|
|
||||||
self.client.login(username=user.username, password='frog')
|
self.client.login(username=user.username, password='frog')
|
||||||
response = self.client.get(reverse('helpdesk_dashboard'), follow=True)
|
response = self.client.get(reverse('helpdesk_dashboard'), follow=True)
|
||||||
self.assertTemplateUsed(response, self.expected_login_template)
|
self.assertTemplateUsed(response, 'helpdesk/registration/login.html')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user