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() {
|
willSave() {
|
||||||
set(this, 'errors', null);
|
set(this, 'errors', null);
|
||||||
|
|
||||||
let errors = [];
|
let errors = [];
|
||||||
let ok = true;
|
let ok = this.validate();
|
||||||
|
|
||||||
ok = this.validate();
|
|
||||||
|
|
||||||
if (this.canUserLogIn && !this.canUserLogIn()) {
|
if (this.canUserLogIn && !this.canUserLogIn()) {
|
||||||
errors.pushObject(this.intl.findTranslationByKey('formGlobalRoles.loginError'));
|
errors.push(this.intl.findTranslationByKey('formGlobalRoles.loginError'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ export default Controller.extend(NewOrEdit, {
|
||||||
var errors = [];
|
var errors = [];
|
||||||
|
|
||||||
if (this.canUserLogIn && !this.canUserLogIn()) {
|
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) {
|
if ((get(this, 'model.account.username') || '').trim().length === 0) {
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,6 @@ export default Component.extend({
|
||||||
|
|
||||||
this.initRoles();
|
this.initRoles();
|
||||||
|
|
||||||
if (this.mode === 'new') {
|
|
||||||
this.populateDefaultRoles();
|
|
||||||
}
|
|
||||||
|
|
||||||
setProperties(this, {
|
setProperties(this, {
|
||||||
'_boundSave': this.save.bind(this),
|
'_boundSave': this.save.bind(this),
|
||||||
'_boundValidator': this.confirmUserCanLogIn.bind(this),
|
'_boundValidator': this.confirmUserCanLogIn.bind(this),
|
||||||
|
|
@ -80,13 +76,11 @@ export default Component.extend({
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
set(this, 'errors', null);
|
set(this, 'errors', null);
|
||||||
const add = [];
|
|
||||||
const remove = [];
|
|
||||||
const allRoles = [...this.baseRoles, ...this.additionalRoles];
|
const allRoles = [...this.baseRoles, ...this.additionalRoles];
|
||||||
|
// all active non-existant roles remapped to an array of the role resources for the save
|
||||||
add.pushObjects(allRoles.filterBy('active').filterBy('existing', false).map((r) => this.make(r.role)));
|
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
|
||||||
remove.pushObjects(allRoles.filterBy('active', false).filterBy('existing').map((r) => r.existing));
|
const remove = allRoles.filterBy('active', false).filterBy('existing').map((r) => r.existing);
|
||||||
|
|
||||||
return PromiseAll(add.map((x) => x.save())).then(() => {
|
return PromiseAll(add.map((x) => x.save())).then(() => {
|
||||||
return PromiseAll(remove.map((x) => x.delete())).then(() => {
|
return PromiseAll(remove.map((x) => x.delete())).then(() => {
|
||||||
|
|
@ -99,13 +93,17 @@ export default Component.extend({
|
||||||
const { allRoles, user } = this;
|
const { allRoles, user } = this;
|
||||||
const { globalRoleBindings: usersGlobalRoleBindings = [] } = user;
|
const { globalRoleBindings: usersGlobalRoleBindings = [] } = user;
|
||||||
const visibleRoles = allRoles.filterBy('isHidden', false);
|
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, {
|
setProperties(this, {
|
||||||
baseRoles: baseRoles.map(roleMapper),
|
baseRoles: baseRoles.map(roleMapper),
|
||||||
additionalRoles: visibleRoles.map(roleMapper),
|
additionalRoles: visibleRoles.map(roleMapper),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.mode === 'new') {
|
||||||
|
this.populateDefaultRoles();
|
||||||
|
}
|
||||||
|
|
||||||
function roleMapper(role) {
|
function roleMapper(role) {
|
||||||
const binding = usersGlobalRoleBindings.findBy('globalRole', role) || false;
|
const binding = usersGlobalRoleBindings.findBy('globalRole', role) || false;
|
||||||
let translationKey = null;
|
let translationKey = null;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue