Add JSONP view of accessible services (fixes #7624)
This commit is contained in:
parent
4d35b94827
commit
86a74dcaa5
|
@ -50,4 +50,5 @@ urlpatterns = patterns('',
|
|||
url('^manage/collectivities/add/$', views.collectivity_add, name='a2-pratic-collectivity-add'),
|
||||
url('^manage/collectivities/(?P<collectivity_pk>\d+)/', include(collectivity_urlpatterns)),
|
||||
url('^$', views.agent_homepage, name='auth_homepage'),
|
||||
url('^services.json$', views.agent_homepage_jsonp, name='auth_homepage_jsonp'),
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.views import redirect_to_login
|
||||
|
@ -398,3 +399,22 @@ def get_service_links(request):
|
|||
def agent_homepage(request):
|
||||
ctx = {'service_links': get_service_links(request)}
|
||||
return render(request, 'authentic2_pratic/agent_homepage.html', ctx)
|
||||
|
||||
def agent_homepage_jsonp(request):
|
||||
service_links = get_service_links(request)
|
||||
data = []
|
||||
for name, url, slug, needed_authent in service_links:
|
||||
data.append({
|
||||
'url': url,
|
||||
'label': name,
|
||||
'authentication_level_is_enough': not bool(needed_authent),
|
||||
'authentication_levels': filter(None, needed_authent.split(', ')),
|
||||
})
|
||||
response = HttpResponse(content_type='application/json')
|
||||
json_str = json.dumps(data)
|
||||
for variable in ('jsonpCallback', 'callback'):
|
||||
if variable in request.GET:
|
||||
json_str = '%s(%s);' % (request.GET[variable], json_str)
|
||||
break
|
||||
response.write(json_str)
|
||||
return response
|
||||
|
|
Reference in New Issue