cleanup from review

This commit is contained in:
Westly Wright 2019-10-22 15:43:18 -07:00
parent 943d8b6662
commit 94a4c1a7e2
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
3 changed files with 13 additions and 17 deletions

View File

@ -49,12 +49,10 @@ export default Controller.extend(NewOrEdit, {
set(this, 'errors', null);
let errors = [];
let ok = true;
ok = this.validate();
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) {

View File

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

View File

@ -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;