summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2013-04-26 16:20:37 +0200
committerPetr Vobornik <pvoborni@redhat.com>2013-05-06 16:22:30 +0200
commit853cdbbfd301d1da41b6f2185f24c5ff6deb48b3 (patch)
treef30f36ff515dd7fbb8c126b3dd1670b089d49b14
parentc506087227acdbc9edba8f000fe7a7ab3abdf621 (diff)
downloadfreeipa-853cdbbfd301d1da41b6f2185f24c5ff6deb48b3.tar.gz
freeipa-853cdbbfd301d1da41b6f2185f24c5ff6deb48b3.tar.xz
freeipa-853cdbbfd301d1da41b6f2185f24c5ff6deb48b3.zip
Navigation: handle invalid routes
https://fedorahosted.org/freeipa/ticket/3235
-rw-r--r--install/ui/src/freeipa/Application_controller.js22
-rw-r--r--install/ui/src/freeipa/navigation/Router.js58
2 files changed, 69 insertions, 11 deletions
diff --git a/install/ui/src/freeipa/Application_controller.js b/install/ui/src/freeipa/Application_controller.js
index 7f62159a0..4c1007b7b 100644
--- a/install/ui/src/freeipa/Application_controller.js
+++ b/install/ui/src/freeipa/Application_controller.js
@@ -76,6 +76,7 @@ define([
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-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));
this.app_widget.render();
@@ -126,16 +127,20 @@ define([
// choose default facet if not defined by route
if (!this.current_facet) {
- if (IPA.is_selfservice) {
- this.on_profile();
- } else {
- this.router.navigate_to_entity_facet('user', 'search');
- }
+ this.navigate_to_default();
}
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() {
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.
*/
diff --git a/install/ui/src/freeipa/navigation/Router.js b/install/ui/src/freeipa/navigation/Router.js
index 09aed16aa..3ac8357ed 100644
--- a/install/ui/src/freeipa/navigation/Router.js
+++ b/install/ui/src/freeipa/navigation/Router.js
@@ -113,7 +113,9 @@ define(['dojo/_base/declare',
}, this);
// 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 facet_name = event.params.facet;
- var pkeys = this._decode_pkeys(event.params.pkeys || '');
- var args = ioquery.queryToObject(event.params.args || '');
+ var pkeys, 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;
// set new facet state
var entity = reg.entity.get(entity_name);
+ if (!entity) {
+ this._error('Unknown entity', 'route', event.params);
+ return;
+ }
var facet = entity.get_facet(facet_name);
+ if (!facet) {
+ this._error('Unknown facet', 'route', event.params);
+ return;
+ }
facet.reset_state(args);
this.show_facet(facet);
@@ -147,10 +163,20 @@ define(['dojo/_base/declare',
if (this.check_clear_ignore()) return;
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
var facet = reg.facet.get(facet_name);
+ if (!facet) {
+ this._error('Unknown facet', 'route', event.params);
+ return;
+ }
facet.reset_state(args);
this.show_facet(facet);
@@ -164,9 +190,16 @@ define(['dojo/_base/declare',
navigate_to_entity_facet: function(entity_name, facet_name, pkeys, args) {
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
if (!pkeys && !args) {
@@ -187,6 +220,10 @@ define(['dojo/_base/declare',
navigate_to_facet: function(facet_name, args) {
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();
var hash = this._create_facet_hash(facet, args);
return this.navigate_to_hash(hash, facet);
@@ -309,6 +346,15 @@ define(['dojo/_base/declare',
return keys;
},
+ _error: function(msg, type, context) {
+
+ this.emit('error', {
+ message: msg,
+ type: type,
+ context: context
+ });
+ },
+
/**
* Starts routing
*/