Merge "When creating a role, check if the role already exists"

This commit is contained in:
Zuul 2018-12-03 14:35:22 +00:00 committed by Gerrit Code Review
commit f07c8e179a

View File

@ -51,6 +51,21 @@
gettext,
toast
) {
var invalidMsg = gettext("Role already exists.");
var roles = [];
var form = [
{
key: "name",
validationMessage: {
rolesExists: invalidMsg
},
$validators: {
rolesExists: function (name) {
return (roles.indexOf(name) === -1);
}
}
}
];
var service = {
allowed: allowed,
perform: perform,
@ -69,12 +84,13 @@
}
function perform() {
getRoles();
var model = {name: ''};
var config = {
title: gettext('Create Role'),
schema: schema,
form: ['*'],
form: form,
model: model,
size: 'md'
};
@ -95,6 +111,16 @@
.result;
}
function getRoles() {
keystoneAPI.getRoles().then(function(response) {
roles = response.data.items.map(getName);
});
}
function getName(item) {
return item.name;
}
}
})();