mirror of https://github.com/rancher/ui.git
cleanup from review
This commit is contained in:
parent
943d8b6662
commit
94a4c1a7e2
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue