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.
This commit is contained in:
parent
517918060a
commit
b98bedebec
|
@ -30,6 +30,7 @@ def services_js(request, *args, **kwargs):
|
||||||
'slug': service_slug,
|
'slug': service_slug,
|
||||||
'service_id': service_id,
|
'service_id': service_id,
|
||||||
'uniq': bool(len(services_dict) == 1),
|
'uniq': bool(len(services_dict) == 1),
|
||||||
|
'url': service['url'],
|
||||||
'backoffice_menu_url': service['backoffice-menu-url'],
|
'backoffice_menu_url': service['backoffice-menu-url'],
|
||||||
})
|
})
|
||||||
response_body = 'var COMBO_KNOWN_SERVICES = %s;' % json.dumps(services)
|
response_body = 'var COMBO_KNOWN_SERVICES = %s;' % json.dumps(services)
|
||||||
|
|
|
@ -65,6 +65,9 @@ $(function() {
|
||||||
create_menu_items();
|
create_menu_items();
|
||||||
} else {
|
} else {
|
||||||
var this_hostname = window.location.hostname;
|
var this_hostname = window.location.hostname;
|
||||||
|
var look_for_wcs = false;
|
||||||
|
var authentic_url = undefined;
|
||||||
|
|
||||||
$(COMBO_KNOWN_SERVICES).each(function(index, element) {
|
$(COMBO_KNOWN_SERVICES).each(function(index, element) {
|
||||||
if (element.backoffice_menu_url === null) {
|
if (element.backoffice_menu_url === null) {
|
||||||
element.data = Array();
|
element.data = Array();
|
||||||
|
@ -77,12 +80,17 @@ $(function() {
|
||||||
*/
|
*/
|
||||||
var that_hostname = $('<a>').attr('href', element.backoffice_menu_url)[0].hostname;
|
var that_hostname = $('<a>').attr('href', element.backoffice_menu_url)[0].hostname;
|
||||||
if (that_hostname != this_hostname) {
|
if (that_hostname != this_hostname) {
|
||||||
|
look_for_wcs = true;
|
||||||
element.data = Array();
|
element.data = Array();
|
||||||
check_all_done();
|
check_all_done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (element.service_id === 'authentic') {
|
||||||
|
authentic_url = element.url;
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({url: element.backoffice_menu_url,
|
$.ajax({url: element.backoffice_menu_url,
|
||||||
xhrFields: { withCredentials: true },
|
xhrFields: { withCredentials: true },
|
||||||
async: 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');
|
var sidepage_button = $('#sidepage #applabel');
|
||||||
|
|
Loading…
Reference in New Issue