1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 15:49:44 +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);
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");
});

View file

@ -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() {

View file

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