Commit e5cdd89c authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Helpdesk api fix

handle prefix that contains text after "@".
parent 476af05e
......@@ -148,9 +148,13 @@ class HelpdeskTests(TestCase):
self.assertEqual(r.status_code, 200)
self.assertEqual(r.content, "[]")
# 1 user exist
# 1 user exists
r = self.client.get(reverse('helpdesk-userslist') + "?prefix=testuser@",
user_token="0001")
self.assertEqual(r.status_code, 200)
self.assertEqual(r.content, '["testuser@test.com"]')
r = self.client.get(reverse('helpdesk-userslist') + "?prefix=testuser@t",
user_token="0001")
self.assertEqual(r.status_code, 200)
self.assertEqual(r.content, '["testuser@test.com"]')
......@@ -8,10 +8,26 @@ from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.http import Http404, HttpResponse
from django.utils import simplejson as json
from urllib import unquote
from synnefo.lib.astakos import get_user, get_token_from_cookie
from synnefo.lib.astakos import get_user
from synnefo.db.models import *
def get_token_from_cookie(request, cookiename):
"""
Extract token from the cookie name provided. Cookie should be in the same
form as astakos service sets its cookie contents::
<user_uniq>|<user_token>
"""
try:
cookie_content = unquote(request.COOKIES.get(cookiename, None))
return cookie_content.split("|")[1]
except AttributeError:
pass
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
......@@ -85,6 +101,7 @@ def account(request, account):
return direct_to_template(request, "helpdesk/account.html",
extra_context=user_context)
@helpdesk_user_required
def user_list(request):
"""
......@@ -93,9 +110,12 @@ def user_list(request):
"""
prefix = request.GET.get('prefix', None)
if not prefix or not prefix.endswith("@"):
if not prefix or "@" not in prefix:
raise Http404
# keep only the user part (e.g. "user@")
prefix = prefix.split("@")[0] + "@"
q = Q(userid__startswith=prefix) & ~Q(userid=None)
vm_users = VirtualMachine.objects.filter(q).values_list("userid", flat=True)
net_users = Network.objects.filter(q).values_list("userid", flat=True)
......
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