mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Navigation: handle invalid routes
https://fedorahosted.org/freeipa/ticket/3235
This commit is contained in:
parent
c506087227
commit
853cdbbfd3
@ -76,6 +76,7 @@ define([
|
|||||||
on(this.router, 'facet-show', lang.hitch(this, this.on_facet_show));
|
on(this.router, 'facet-show', lang.hitch(this, this.on_facet_show));
|
||||||
on(this.router, 'facet-change', lang.hitch(this, this.on_facet_change));
|
on(this.router, 'facet-change', lang.hitch(this, this.on_facet_change));
|
||||||
on(this.router, 'facet-change-canceled', lang.hitch(this, this.on_facet_canceled));
|
on(this.router, 'facet-change-canceled', lang.hitch(this, this.on_facet_canceled));
|
||||||
|
on(this.router, 'error', lang.hitch(this, this.on_router_error));
|
||||||
topic.subscribe('phase-error', lang.hitch(this, this.on_phase_error));
|
topic.subscribe('phase-error', lang.hitch(this, this.on_phase_error));
|
||||||
|
|
||||||
this.app_widget.render();
|
this.app_widget.render();
|
||||||
@ -126,16 +127,20 @@ define([
|
|||||||
|
|
||||||
// choose default facet if not defined by route
|
// choose default facet if not defined by route
|
||||||
if (!this.current_facet) {
|
if (!this.current_facet) {
|
||||||
if (IPA.is_selfservice) {
|
this.navigate_to_default();
|
||||||
this.on_profile();
|
|
||||||
} else {
|
|
||||||
this.router.navigate_to_entity_facet('user', 'search');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.run_time.promise;
|
return this.run_time.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
navigate_to_default: function() {
|
||||||
|
if (IPA.is_selfservice) {
|
||||||
|
this.on_profile();
|
||||||
|
} else {
|
||||||
|
this.router.navigate_to_entity_facet('user', 'search');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
start_logout: function() {
|
start_logout: function() {
|
||||||
IPA.logout();
|
IPA.logout();
|
||||||
},
|
},
|
||||||
@ -276,6 +281,13 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
on_router_error: function(error) {
|
||||||
|
|
||||||
|
if (error.type === 'route') {
|
||||||
|
this.navigate_to_default();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to find menu item with assigned facet and navigate to it.
|
* Tries to find menu item with assigned facet and navigate to it.
|
||||||
*/
|
*/
|
||||||
|
@ -113,7 +113,9 @@ define(['dojo/_base/declare',
|
|||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
// special pages
|
// special pages
|
||||||
this.register_route(this.page_routes, this.page_route_handler);
|
array.forEach(this.page_routes, function(route) {
|
||||||
|
this.register_route(route, this.page_route_handler);
|
||||||
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,13 +128,27 @@ define(['dojo/_base/declare',
|
|||||||
|
|
||||||
var entity_name = event.params.entity;
|
var entity_name = event.params.entity;
|
||||||
var facet_name = event.params.facet;
|
var facet_name = event.params.facet;
|
||||||
var pkeys = this._decode_pkeys(event.params.pkeys || '');
|
var pkeys, args;
|
||||||
var args = ioquery.queryToObject(event.params.args || '');
|
try {
|
||||||
|
pkeys = this._decode_pkeys(event.params.pkeys || '');
|
||||||
|
args = ioquery.queryToObject(event.params.args || '');
|
||||||
|
} catch (e) {
|
||||||
|
this._error('URI error', 'route', event.params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
args.pkeys = pkeys;
|
args.pkeys = pkeys;
|
||||||
|
|
||||||
// set new facet state
|
// set new facet state
|
||||||
var entity = reg.entity.get(entity_name);
|
var entity = reg.entity.get(entity_name);
|
||||||
|
if (!entity) {
|
||||||
|
this._error('Unknown entity', 'route', event.params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var facet = entity.get_facet(facet_name);
|
var facet = entity.get_facet(facet_name);
|
||||||
|
if (!facet) {
|
||||||
|
this._error('Unknown facet', 'route', event.params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
facet.reset_state(args);
|
facet.reset_state(args);
|
||||||
|
|
||||||
this.show_facet(facet);
|
this.show_facet(facet);
|
||||||
@ -147,10 +163,20 @@ define(['dojo/_base/declare',
|
|||||||
if (this.check_clear_ignore()) return;
|
if (this.check_clear_ignore()) return;
|
||||||
|
|
||||||
var facet_name = event.params.page;
|
var facet_name = event.params.page;
|
||||||
var args = ioquery.queryToObject(event.params.args || '');
|
var args;
|
||||||
|
try {
|
||||||
|
args = ioquery.queryToObject(event.params.args || '');
|
||||||
|
} catch (e) {
|
||||||
|
this._error('URI error', 'route', event.params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// set new facet state
|
// set new facet state
|
||||||
var facet = reg.facet.get(facet_name);
|
var facet = reg.facet.get(facet_name);
|
||||||
|
if (!facet) {
|
||||||
|
this._error('Unknown facet', 'route', event.params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
facet.reset_state(args);
|
facet.reset_state(args);
|
||||||
|
|
||||||
this.show_facet(facet);
|
this.show_facet(facet);
|
||||||
@ -164,9 +190,16 @@ define(['dojo/_base/declare',
|
|||||||
navigate_to_entity_facet: function(entity_name, facet_name, pkeys, args) {
|
navigate_to_entity_facet: function(entity_name, facet_name, pkeys, args) {
|
||||||
|
|
||||||
var entity = reg.entity.get(entity_name);
|
var entity = reg.entity.get(entity_name);
|
||||||
var facet = entity.get_facet(facet_name);
|
if (!entity) {
|
||||||
|
this._error('Unknown entity', 'navigation', { entity: entity_name});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!facet) return false; // TODO: maybe replace with exception
|
var facet = entity.get_facet(facet_name);
|
||||||
|
if (!facet) {
|
||||||
|
this._error('Unknown facet', 'navigation', { facet: facet_name});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Use current state if none supplied
|
// Use current state if none supplied
|
||||||
if (!pkeys && !args) {
|
if (!pkeys && !args) {
|
||||||
@ -187,6 +220,10 @@ define(['dojo/_base/declare',
|
|||||||
navigate_to_facet: function(facet_name, args) {
|
navigate_to_facet: function(facet_name, args) {
|
||||||
|
|
||||||
var facet = reg.facet.get(facet_name);
|
var facet = reg.facet.get(facet_name);
|
||||||
|
if (!facet) {
|
||||||
|
this._error('Unknown facet', 'navigation', { facet: facet_name});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!args) args = facet.get_state();
|
if (!args) args = facet.get_state();
|
||||||
var hash = this._create_facet_hash(facet, args);
|
var hash = this._create_facet_hash(facet, args);
|
||||||
return this.navigate_to_hash(hash, facet);
|
return this.navigate_to_hash(hash, facet);
|
||||||
@ -309,6 +346,15 @@ define(['dojo/_base/declare',
|
|||||||
return keys;
|
return keys;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_error: function(msg, type, context) {
|
||||||
|
|
||||||
|
this.emit('error', {
|
||||||
|
message: msg,
|
||||||
|
type: type,
|
||||||
|
context: context
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts routing
|
* Starts routing
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user