exclude KB from navigation if HELPDESK_KB_ENABLED is False (fixes #223)

This commit is contained in:
Stefano Brentegani 2014-07-21 18:44:54 +02:00
parent 21e46f010d
commit fe5c7135a6
4 changed files with 74 additions and 0 deletions

View File

@ -17,7 +17,9 @@
<li><a href='{% url 'helpdesk_list' %}'><span class="glyphicon glyphicon-tags"></span> <span class="nav-text">{% trans "Tickets" %}</span></a></li>
<li><a href='{% url 'helpdesk_submit' %}'><span class="glyphicon glyphicon-plus"></span> <span class="nav-text">{% trans "New Ticket" %}</span></a></li>
<li><a href='{% url 'helpdesk_report_index' %}'><span class="glyphicon glyphicon-stats"></span><span class="nav-text"> {% trans "Stats" %}</span></a></li>
{% if helpdesk_settings.HELPDESK_KB_ENABLED %}
<li><a href='{% url 'helpdesk_kb_index' %}'><span class="glyphicon glyphicon-tree-deciduous"></span><span class="nav-text">{% trans "Knowledgebase" %}</span></a></li>
{% endif %}
{% if user_saved_queries_ %}
<li class="headerlink dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-filter"></span><span class="nav-text"> {% trans "Saved Query" %} <b class="caret"></b></span></a>
<ul class="dropdown-menu">

View File

@ -1,2 +1,3 @@
from helpdesk.tests.ticket_submission import *
from helpdesk.tests.public_actions import *
from helpdesk.tests.navigation import *

33
helpdesk/tests/helpers.py Normal file
View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
import sys
try:
from django.contrib.auth import get_user_model
except ImportError:
from django.contrib.auth.models import User
else:
User = get_user_model()
def get_staff_user(username='helpdesk.staff', password='password'):
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
user = User.objects.create_user(username=username, password=password, email='staff@example.com')
user.is_staff = True
user.save()
else:
user.set_password(password)
user.save()
return user
def reload_urlconf(urlconf=None):
if urlconf is None:
from django.conf import settings
urlconf = settings.ROOT_URLCONF
if urlconf in sys.modules:
from django.core.urlresolvers import clear_url_caches
reload(sys.modules[urlconf])
clear_url_caches()

View File

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
from django.core.urlresolvers import reverse
from django.test import TestCase
from helpdesk.tests.helpers import get_staff_user, reload_urlconf
class TestKBDisabled(TestCase):
def setUp(self):
from helpdesk import settings
self.HELPDESK_KB_ENABLED = settings.HELPDESK_KB_ENABLED
if self.HELPDESK_KB_ENABLED:
settings.HELPDESK_KB_ENABLED = False
reload_urlconf()
def tearDown(self):
from helpdesk import settings
if self.HELPDESK_KB_ENABLED:
settings.HELPDESK_KB_ENABLED = True
reload_urlconf()
def test_navigation(self):
"""Test proper rendering of navigation.html by accessing the dashboard"""
from django.core.urlresolvers import NoReverseMatch
self.client.login(username=get_staff_user().username, password='password')
self.assertRaises(NoReverseMatch, reverse, 'helpdesk_kb_index')
try:
response = self.client.get(reverse('helpdesk_dashboard'))
except NoReverseMatch, e:
if 'helpdesk_kb_index' in e.message:
self.fail("Please verify any unchecked references to helpdesk_kb_index (start with navigation.html)")
else:
raise
else:
self.assertEqual(response.status_code, 200)