Commit 0f0faad3 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Helpdesk application improvements

- Additional setting HELPDESK_ENABLED to be able to enable/disable
  helpdesk views.
- Fix fixtures to play along with new network models
- Include helpdesk default settings module
parent 364a9891
#Enable the helpdesk application
#HELPDESK_ENABLED = True
# Which is the cookie name that stores the token, leave it commented out
# to use same value as UI_AUTH_COOKIE_NAME value.
#HELPDESK_AUTH_COOKIE_NAME = UI_AUTH_COOKIE_NAME
......@@ -94,12 +94,13 @@
}
},
{
"model": "db.NetworkLink",
"model": "db.NetworkInterface",
"pk": 1,
"fields": {
"index": 0,
"name": "snf_null",
"available": 0
"machine": 1,
"network": 1,
"mac": "00:11"
}
}
]
......@@ -68,10 +68,21 @@ class HelpdeskTests(TestCase):
astakos.get_user = get_user_mock
settings.SKIP_SSH_VALIDATION = True
settings.HELPDESK_ENABLED = True
self.client = AaiClient()
self.user = 'test'
self.keys_url = reverse('ui_keys_collection')
def test_enabled_setting(self):
settings.HELPDESK_ENABLED = False
# helpdesk is disabled
r = self.client.get(reverse('helpdesk-index'), user_token="0001")
self.assertEqual(r.status_code, 404)
r = self.client.get(reverse('helpdesk-details', args=['testuser@test.com']),
user_token="0001")
self.assertEqual(r.status_code, 404)
def test_ip_lookup(self):
# ip does not exist, proper message gets displayed
r = self.client.get(reverse('helpdesk-details',
......
......@@ -32,11 +32,14 @@ def get_token_from_cookie(request, cookiename):
return None
# TODO: here we mix ui setting with helpdesk settings
# if sometime in the future helpdesk gets splitted from the
# cyclades api code this should change and helpdesk should provide
# its own setting HELPDESK_AUTH_COOKIE_NAME.
HELPDESK_AUTH_COOKIE = getattr(settings, 'UI_AUTH_COOKIE_NAME', '_pithos2_a')
AUTH_COOKIE = getattr(settings, 'UI_AUTH_COOKIE_NAME', getattr(settings,
'HELPDESK_AUTH_COOKIE_NAME', '_pithos2_a'))
def helpdesk_user_required(func, groups=['helpdesk']):
"""
......@@ -44,7 +47,11 @@ def helpdesk_user_required(func, groups=['helpdesk']):
permissions (exists in helpdesk group)
"""
def wrapper(request, *args, **kwargs):
token = get_token_from_cookie(request, HELPDESK_AUTH_COOKIE)
HELPDESK_ENABLED = getattr(settings, 'HELPDESK_ENABLED', True)
if not HELPDESK_ENABLED:
raise Http404
token = get_token_from_cookie(request, AUTH_COOKIE)
get_user(request, settings.ASTAKOS_URL, fallback_token=token)
if hasattr(request, 'user') and request.user:
groups = request.user.get('groups', [])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment