From c44c60f2910fa232fa04a4f9a0c23ac29a1c6984 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Sat, 8 Jul 2017 17:16:05 -0700 Subject: [PATCH] Cleans up web UI and fixes ACL token "stuckness" issue. (#3245) * Removes GitHub reference. * Doesn't display ACL token on the unauthorized page. * Removes useless fetch for nodes and cleans up comments. * Provides a path to reset the ACL token when it's invalid. This included making the settings page global so it's reachable, and adding some more information about an error on the error page. * Updates built-in web assets. --- index.html | 25 +++++++++++++------------ javascripts/app/controllers.js | 17 +++++++++++++++++ javascripts/app/helpers.js | 6 +++++- javascripts/app/router.js | 8 +++++--- javascripts/app/routes.js | 7 ++----- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/index.html b/index.html index 157176e7eaf0..bacbac6e2135 100644 --- a/index.html +++ b/index.html @@ -56,10 +56,16 @@

JavaScript Required

{{#if controller.model.statusText }}

HTTP error code from Consul: {{controller.model.status}} {{controller.model.statusText}}

{{/if}} -

This is an error page for the Consul web UI. You may have visited a URL that is loading an - unknown resource, so you can try going back to the root.

-

Otherwise, please report any unexpected - issues on the GitHub page.

+ {{#if controller.model.responseText }} +

Error message from Consul: {{limit controller.model.responseText 255}}

+ {{/if}} +

Consul returned an error. You may have visited a URL that is loading an unknown resource, so you + can try going back to the root. If your ACL token was not found you can reset it, and then you + will be redirected to the settings page to enter a new ACL token.

+
+ + +
@@ -70,13 +76,7 @@

JavaScript Required

Access Denied

- {{#if aclToken}} -

Your ACL token, {{aclToken}}, does not - have the appropriate permissions to perform the expected action.

- {{else}} -

The default agent token does not - have the appropriate permissions to perform the expected action.

- {{/if}} +

Your ACL token does not have the appropriate permissions to perform the expected action.

Learn more in the ACL documentation.

@@ -759,7 +759,7 @@

Settings

These settings allow you to configure your browser for the Consul Web UI. Everything is saved to localstorage, and should persist through visits and browser usage.

Settings are automatically persisted upon modification, so no manual save is required.

-
Access Token
+
ACL Token
{{ input type="text" value=model.token class="form-control form-mono" placeholder="token"}} The token is sent with requests as the ?token parameter. This is used to control the ACL for the @@ -767,6 +767,7 @@
Access Token
+
diff --git a/javascripts/app/controllers.js b/javascripts/app/controllers.js index 2e088333bf15..512a5cd9bda2 100644 --- a/javascripts/app/controllers.js +++ b/javascripts/app/controllers.js @@ -501,6 +501,23 @@ App.SettingsController = Ember.ObjectController.extend({ notify('Settings reset', 3000); this.set('isLoading', false); } + }, + + close: function() { + this.transitionToRoute('index'); + } + } +}); + +App.ErrorController = Ember.ObjectController.extend({ + actions: { + resetToken: function() { + App.set('settings.token', ''); + this.transitionToRoute('settings'); + }, + + backHome: function() { + this.transitionToRoute('index'); } } }); diff --git a/javascripts/app/helpers.js b/javascripts/app/helpers.js index 49d68c7b3e14..7aa9eb19d4ac 100644 --- a/javascripts/app/helpers.js +++ b/javascripts/app/helpers.js @@ -50,7 +50,6 @@ Ember.Handlebars.helper('aclName', function(name, id) { } }); - Ember.Handlebars.helper('formatRules', function(rules) { if (rules === "") { return "No rules defined"; @@ -59,6 +58,11 @@ Ember.Handlebars.helper('formatRules', function(rules) { } }); +Ember.Handlebars.helper('limit', function(str, limit) { + if (str.length > limit) + return str.substring(0, limit) + '...'; + return str; +}); // We need to do this because of our global namespace properties. The // service.Tags diff --git a/javascripts/app/router.js b/javascripts/app/router.js index f79df94ffd4e..74079523edd8 100644 --- a/javascripts/app/router.js +++ b/javascripts/app/router.js @@ -43,15 +43,17 @@ App.Router.map(function() { // Shows a page explaining that ACLs haven't been set-up this.route("aclsdisabled", { path: "/aclsdisabled" }); - // Shows a page explaining that the ACL key being used isn't + + // Shows a page explaining that the ACL token being used isn't // authorized this.route("unauthorized", { path: "/unauthorized" }); - - this.resource("settings", { path: "/settings" }); }); // Shows a datacenter picker. If you only have one // it just redirects you through. this.route("index", { path: "/" }); + + // The settings page is global. + this.resource("settings", { path: "/settings" }); }); diff --git a/javascripts/app/routes.js b/javascripts/app/routes.js index 5cc3c6c61d2e..f3c18b3faa56 100644 --- a/javascripts/app/routes.js +++ b/javascripts/app/routes.js @@ -327,7 +327,7 @@ App.NodesShowRoute = App.BaseRoute.extend({ max = 0; } - // Return a promise hash of the node and nodes + // Return a promise hash of the node return Ember.RSVP.hash({ dc: dc.dc, token: token, @@ -340,9 +340,6 @@ App.NodesShowRoute = App.BaseRoute.extend({ }, node: Ember.$.getJSON(formatUrl(consulHost + '/v1/internal/ui/node/' + params.name, dc.dc, token)).then(function(data) { return App.Node.create(data); - }), - nodes: Ember.$.getJSON(formatUrl(consulHost + '/v1/internal/ui/node/' + params.name, dc.dc, token)).then(function(data) { - return App.Node.create(data); }) }); }, @@ -431,7 +428,7 @@ App.AclsShowRoute = App.BaseRoute.extend({ var dc = this.modelFor('dc').dc; var token = App.get('settings.token'); - // Return a promise hash of the node and nodes + // Return a promise hash of the ACLs return Ember.RSVP.hash({ dc: dc, acl: Ember.$.getJSON(formatUrl(consulHost + '/v1/acl/info/'+ params.id, dc, token)).then(function(data) {