Repository: couchdb-fauxton Updated Branches: refs/heads/master a0886ac95 -> b2195ac7d
Fix for logout link showing up twice in footer An old bug is the Logout link in the footer showing up twice. It's a little difficult to reproduce consistently, but I've found this works the best (Mac, chrome): 1. open dev tools 2. Login to Fauxton, notice the single "logout" link in footer. 3. click on the browser URL bar and click <enter> 4. Repeat the above until you see two "logout" links in the footer. What's happening is the change event on Auth.session is firing twice, each of which adds a new footer link. Seems like with some page loads it only fires once, sometimes twice. This ensures the link is removed prior to adding it. Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/8311d62f Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/8311d62f Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/8311d62f Branch: refs/heads/master Commit: 8311d62f47bd587a98bf385d7820998a5dfd40fc Parents: a0886ac Author: Ben Keen <ben.k...@gmail.com> Authored: Tue Oct 6 20:36:44 2015 -0700 Committer: Ben Keen <ben.k...@gmail.com> Committed: Fri Nov 27 10:10:19 2015 -0800 ---------------------------------------------------------------------- app/addons/auth/base.js | 9 ++++-- app/addons/fauxton/navigation/stores.js | 3 +- .../navigation/tests/componentsSpec.react.jsx | 31 +++++++++++++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/8311d62f/app/addons/auth/base.js ---------------------------------------------------------------------- diff --git a/app/addons/auth/base.js b/app/addons/auth/base.js index 0d3a04a..a0af863 100644 --- a/app/addons/auth/base.js +++ b/app/addons/auth/base.js @@ -29,7 +29,7 @@ function (app, FauxtonAPI, Auth) { title: "Login", href: "#login", icon: "fonticon-user", - bottomNav: true, + bottomNav: true }); Auth.session.on('change', function () { @@ -42,7 +42,7 @@ function (app, FauxtonAPI, Auth) { title: "Admin Party!", href: "#createAdmin", icon: "fonticon-user", - bottomNav: true, + bottomNav: true }; } else if (session.isLoggedIn()) { link = { @@ -50,9 +50,12 @@ function (app, FauxtonAPI, Auth) { title: session.user().name, href: "#changePassword", icon: "fonticon-user", - bottomNav: true, + bottomNav: true }; + // ensure the footer link is removed before adding it + FauxtonAPI.removeHeaderLink({id: "logout", footerNav: true}); + FauxtonAPI.addHeaderLink({ id: 'logout', footerNav: true, http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/8311d62f/app/addons/fauxton/navigation/stores.js ---------------------------------------------------------------------- diff --git a/app/addons/fauxton/navigation/stores.js b/app/addons/fauxton/navigation/stores.js index 8ec8d0f..248522b 100644 --- a/app/addons/fauxton/navigation/stores.js +++ b/app/addons/fauxton/navigation/stores.js @@ -171,13 +171,14 @@ function (app, FauxtonAPI, ActionTypes) { dispatch: function (action) { switch (action.type) { - case ActionTypes.ADD_NAVBAR_LINK: this.addLink(action.link); break; + case ActionTypes.TOGGLE_NAVBAR_MENU: this.toggleMenu(); break; + case ActionTypes.UPDATE_NAVBAR_LINK: this.updateLink(action.link); break; http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/8311d62f/app/addons/fauxton/navigation/tests/componentsSpec.react.jsx ---------------------------------------------------------------------- diff --git a/app/addons/fauxton/navigation/tests/componentsSpec.react.jsx b/app/addons/fauxton/navigation/tests/componentsSpec.react.jsx index 60bb201..cb8d468 100644 --- a/app/addons/fauxton/navigation/tests/componentsSpec.react.jsx +++ b/app/addons/fauxton/navigation/tests/componentsSpec.react.jsx @@ -13,9 +13,11 @@ define([ 'api', 'addons/fauxton/navigation/components.react', 'addons/fauxton/navigation/actions', + 'core/auth', + 'addons/auth/base', 'testUtils', "react" -], function (FauxtonAPI, Views, Actions, utils, React) { +], function (FauxtonAPI, Views, Actions, Auth, BaseAuth, utils, React) { var assert = utils.assert; var TestUtils = React.addons.TestUtils; @@ -42,6 +44,33 @@ define([ }); + it('logout link only ever appears once', function () { + FauxtonAPI.auth = new Auth(); + sinon.stub(FauxtonAPI.session, 'isLoggedIn').returns(true); + sinon.stub(FauxtonAPI.session, 'isAdminParty').returns(false); + sinon.stub(FauxtonAPI.session, 'user').returns({ name: 'test-user' }); + BaseAuth.initialize(); + + var container = document.createElement('div'); + var el = TestUtils.renderIntoDocument(<Views.NavBar />, container); + + FauxtonAPI.session.trigger('change'); + + // confirm the logout link is present + var matches = React.findDOMNode(el).outerHTML.match(/Logout/); + assert.equal(matches.length, 1); + + // now confirm there's still only a single logout link after publishing multiple + FauxtonAPI.session.trigger('change'); + FauxtonAPI.session.trigger('change'); + matches = React.findDOMNode(el).outerHTML.match(/Logout/); + assert.equal(matches.length, 1); + + FauxtonAPI.session.isLoggedIn.restore(); + FauxtonAPI.session.user.restore(); + FauxtonAPI.session.isAdminParty.restore(); + }); + describe('CSRF info', function () { var container, el, server;