1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-28 01:29:43 +02:00

improved account switcher logic

This commit is contained in:
Harvey Kandola 2017-04-16 15:47:39 +01:00
parent f2a672b33d
commit 972cc688eb
3 changed files with 21 additions and 12 deletions

View file

@ -38,7 +38,7 @@ export default Ember.Component.extend(TooltipMixin, {
this._super(...arguments); this._super(...arguments);
if (this.get("session.authenticated") && this.get("session.user.id") !== '0') { 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 // TODO: do not mutate account.active here
account.active = account.orgId === this.get("appMeta.orgId"); account.active = account.orgId === this.get("appMeta.orgId");
}); });

View file

@ -26,25 +26,36 @@ export default SimpleAuthSession.extend({
currentFolder: null, currentFolder: null,
isMac: false, isMac: false,
isMobile: 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 () { user: computed('isAuthenticated', 'session.content.authenticated.user', function () {
if (this.get('isAuthenticated')) { 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); let data = this.get('store').normalize('user', user);
return this.get('store').push(data); return this.get('store').push(data);
} }
}), }),
authenticated: computed('session.content.authenticated.user', function () { 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 () { 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 () { 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 () { 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() { init() {

View file

@ -1,6 +1,6 @@
<div id="zone-navigation" class="zone-navigation"> <div id="zone-navigation" class="zone-navigation">
<ul id="top-zone" class="top-zone"> <ul id="top-zone" class="top-zone">
{{#if session.authenticated}} {{#if session.hasAccounts}}
<li> <li>
<div id="accounts-button" class="round-button-mono button-white"> <div id="accounts-button" class="round-button-mono button-white">
<i class="material-icons">apps</i> <i class="material-icons">apps</i>
@ -71,14 +71,12 @@
{{/if}} {{/if}}
</ul> </ul>
{{#if session.authenticated}} {{#if session.hasAccounts}}
{{#dropdown-menu target="accounts-button" position="bottom right" open="click" }} {{#dropdown-menu target="accounts-button" position="bottom right" open="click" }}
<ul class="menu"> <ul class="menu">
{{#each session.user.accounts as |account|}} {{#each session.accounts as |account|}}
<li class="item" {{action 'switchAccount' account.domain }}>{{account.title}}</li> <li class="item" {{action 'switchAccount' account.domain }}>{{account.title}}</li>
{{/each}} {{/each}}
<li class="divider"></li>
<li class="item"><a href="https://documize.com/welcome">Add team...</a></li>
</ul> </ul>
{{/dropdown-menu}} {{/dropdown-menu}}
{{/if}} {{/if}}