diff --git a/app/app/components/layout/zone-navigation.js b/app/app/components/layout/zone-navigation.js index a734a1d1..ce327661 100644 --- a/app/app/components/layout/zone-navigation.js +++ b/app/app/components/layout/zone-navigation.js @@ -38,7 +38,7 @@ export default Ember.Component.extend(TooltipMixin, { this._super(...arguments); if (this.get("session.authenticated") && this.get("session.user.id") !== '0') { - this.get("session.user.accounts").forEach((account) => { + this.get("session.accounts").forEach((account) => { // TODO: do not mutate account.active here account.active = account.orgId === this.get("appMeta.orgId"); }); diff --git a/app/app/services/session.js b/app/app/services/session.js index 996beed9..787adc67 100644 --- a/app/app/services/session.js +++ b/app/app/services/session.js @@ -26,25 +26,36 @@ export default SimpleAuthSession.extend({ currentFolder: null, isMac: false, isMobile: false, - + hasAccounts: computed('isAuthenticated', 'session.content.authenticated.user', function() { + return this.get('session.authenticator') !== 'authenticator:anonymous' && this.get('session.content.authenticated.user.accounts').length > 0; + }), + accounts: computed('hasAccounts', function() { + return this.get('session.content.authenticated.user.accounts'); + }), user: computed('isAuthenticated', 'session.content.authenticated.user', function () { if (this.get('isAuthenticated')) { - let user = this.get('session.content.authenticated.user') || { id: '' }; + let user = this.get('session.content.authenticated.user') || { id: '0' }; let data = this.get('store').normalize('user', user); return this.get('store').push(data); } }), authenticated: computed('session.content.authenticated.user', function () { - return this.get('session.content.authenticated.user.id') !== '0'; + return this.get('session.authenticator') !== 'authenticator:anonymous' && this.get('session.content.authenticated.user.id') !== '0'; }), isAdmin: computed('session.content.authenticated.user', function () { - return this.get('session.content.authenticated.user.admin') === true; + return this.get('session.authenticator') !== 'authenticator:anonymous' && + this.get('session.content.authenticated.user.id') !== '0' && + this.get('session.content.authenticated.user.admin') === true; }), isEditor: computed('session.content.authenticated.user', function () { - return this.get('session.content.authenticated.user.editor') === true; + return this.get('session.authenticator') !== 'authenticator:anonymous' && + this.get('session.content.authenticated.user.id') !== '0' && + this.get('session.content.authenticated.user.editor') === true; }), isGlobalAdmin: computed('session.content.authenticated.user', function () { - return this.get('session.content.authenticated.user.global') === true; + return this.get('session.authenticator') !== 'authenticator:anonymous' && + this.get('session.content.authenticated.user.id') !== '0' && + this.get('session.content.authenticated.user.global') === true; }), init() { diff --git a/app/app/templates/components/layout/zone-navigation.hbs b/app/app/templates/components/layout/zone-navigation.hbs index cf773a13..1354cd05 100644 --- a/app/app/templates/components/layout/zone-navigation.hbs +++ b/app/app/templates/components/layout/zone-navigation.hbs @@ -1,6 +1,6 @@
- {{#if session.authenticated}} + {{#if session.hasAccounts}} {{#dropdown-menu target="accounts-button" position="bottom right" open="click" }} {{/dropdown-menu}} {{/if}}