From b98bedebecae37ac04ce679aa9821d1c03f5f96b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 8 Jul 2015 09:13:27 +0200 Subject: [PATCH] publik: look deeper for relevant wcs instance (#7769) If there are several instances of wcs deployed (which is typical of a multi-collectivity deployment) we ask authentic for user details so we know where the user has been given roles, we can then get the relevant wcs. --- combo/apps/publik/views.py | 1 + data/themes/gadjo/static/js/publik.js | 46 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/combo/apps/publik/views.py b/combo/apps/publik/views.py index f405f316..6dbaeba8 100644 --- a/combo/apps/publik/views.py +++ b/combo/apps/publik/views.py @@ -30,6 +30,7 @@ def services_js(request, *args, **kwargs): 'slug': service_slug, 'service_id': service_id, 'uniq': bool(len(services_dict) == 1), + 'url': service['url'], 'backoffice_menu_url': service['backoffice-menu-url'], }) response_body = 'var COMBO_KNOWN_SERVICES = %s;' % json.dumps(services) diff --git a/data/themes/gadjo/static/js/publik.js b/data/themes/gadjo/static/js/publik.js index 66d8a1d1..519c47f6 100644 --- a/data/themes/gadjo/static/js/publik.js +++ b/data/themes/gadjo/static/js/publik.js @@ -65,6 +65,9 @@ $(function() { create_menu_items(); } else { var this_hostname = window.location.hostname; + var look_for_wcs = false; + var authentic_url = undefined; + $(COMBO_KNOWN_SERVICES).each(function(index, element) { if (element.backoffice_menu_url === null) { element.data = Array(); @@ -77,12 +80,17 @@ $(function() { */ var that_hostname = $('').attr('href', element.backoffice_menu_url)[0].hostname; if (that_hostname != this_hostname) { + look_for_wcs = true; element.data = Array(); check_all_done(); return; } } + if (element.service_id === 'authentic') { + authentic_url = element.url; + } + $.ajax({url: element.backoffice_menu_url, xhrFields: { withCredentials: true }, async: true, @@ -93,6 +101,44 @@ $(function() { } ); }); + if (look_for_wcs && authentic_url) { + /* if there is several wcs instances, we ask authentic for details on the + * user, to get the services where the user has some roles + */ + $.ajax({url: authentic_url + 'user_info/', + xhrFields: { withCredentials: true }, + async: true, + dataType: 'jsonp', + crossDomain: true, + success: function(data) { + var services_to_consider = Array(); + /* iterate over all services, to get those to consider */ + $(COMBO_KNOWN_SERVICES).each(function(index, element) { + if (element.service_id !== 'wcs') return; + $(data.services).each(function(auth_index, auth_element) { + if (auth_element.slug !== element.slug) return; + if (auth_element.roles.length == 0) return; + services_to_consider.push(element); + }); + }); + if (services_to_consider.length == 1) { + /* only handle the case with a single service, for now */ + var element = services_to_consider[0]; + $.ajax({url: element.backoffice_menu_url, + xhrFields: { withCredentials: true }, + async: true, + dataType: 'jsonp', + crossDomain: true, + success: function(data) { element.data = data; check_all_done(); }, + error: function(error) { console.log('bouh', error); element.data = Array(); check_all_done(); } + } + ); + } + }, + error: function(error) { console.log('bouh', error); } + } + ); + } } var sidepage_button = $('#sidepage #applabel');