diff --git a/lib/global-admin/addon/accounts/edit/controller.js b/lib/global-admin/addon/accounts/edit/controller.js index a8fa628fb..f6b1e0ef7 100644 --- a/lib/global-admin/addon/accounts/edit/controller.js +++ b/lib/global-admin/addon/accounts/edit/controller.js @@ -48,13 +48,11 @@ export default Controller.extend(NewOrEdit, { willSave() { set(this, 'errors', null); - let errors = []; - let ok = true; - - ok = this.validate(); + let errors = []; + let ok = this.validate(); if (this.canUserLogIn && !this.canUserLogIn()) { - errors.pushObject(this.intl.findTranslationByKey('formGlobalRoles.loginError')); + errors.push(this.intl.findTranslationByKey('formGlobalRoles.loginError')); } if (!ok) { diff --git a/lib/global-admin/addon/accounts/new/controller.js b/lib/global-admin/addon/accounts/new/controller.js index 4ccdbb418..dd3cb93ba 100644 --- a/lib/global-admin/addon/accounts/new/controller.js +++ b/lib/global-admin/addon/accounts/new/controller.js @@ -73,7 +73,7 @@ export default Controller.extend(NewOrEdit, { var errors = []; if (this.canUserLogIn && !this.canUserLogIn()) { - errors.pushObject(this.intl.findTranslationByKey('formGlobalRoles.loginError')); + errors.push(this.intl.findTranslationByKey('formGlobalRoles.loginError')); } if ((get(this, 'model.account.username') || '').trim().length === 0) { diff --git a/lib/global-admin/addon/components/form-global-roles/component.js b/lib/global-admin/addon/components/form-global-roles/component.js index 8d097f77b..76104d26a 100644 --- a/lib/global-admin/addon/components/form-global-roles/component.js +++ b/lib/global-admin/addon/components/form-global-roles/component.js @@ -44,10 +44,6 @@ export default Component.extend({ this.initRoles(); - if (this.mode === 'new') { - this.populateDefaultRoles(); - } - setProperties(this, { '_boundSave': this.save.bind(this), '_boundValidator': this.confirmUserCanLogIn.bind(this), @@ -80,13 +76,11 @@ export default Component.extend({ save() { set(this, 'errors', null); - const add = []; - const remove = []; const allRoles = [...this.baseRoles, ...this.additionalRoles]; - - add.pushObjects(allRoles.filterBy('active').filterBy('existing', false).map((r) => this.make(r.role))); - - remove.pushObjects(allRoles.filterBy('active', false).filterBy('existing').map((r) => r.existing)); + // all active non-existant roles remapped to an array of the role resources for the save + const add = allRoles.filterBy('active').filterBy('existing', false).map((r) => this.make(r.role)); + // all inactive existing roles remapped to an array of the role resources for the remove save + const remove = allRoles.filterBy('active', false).filterBy('existing').map((r) => r.existing); return PromiseAll(add.map((x) => x.save())).then(() => { return PromiseAll(remove.map((x) => x.delete())).then(() => { @@ -99,13 +93,17 @@ export default Component.extend({ const { allRoles, user } = this; const { globalRoleBindings: usersGlobalRoleBindings = [] } = user; const visibleRoles = allRoles.filterBy('isHidden', false); - const baseRoles = [ADMIN, USER, BASE].map((spr) => allRoles.findBy('id', spr)) + const baseRoles = [ADMIN, USER, BASE].map((r) => allRoles.findBy('id', r)); setProperties(this, { baseRoles: baseRoles.map(roleMapper), additionalRoles: visibleRoles.map(roleMapper), }); + if (this.mode === 'new') { + this.populateDefaultRoles(); + } + function roleMapper(role) { const binding = usersGlobalRoleBindings.findBy('globalRole', role) || false; let translationKey = null;