When creating a role, check if the role already exists
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,
}
function perform() {
+ getRoles();
var model = {name: ''};
var config = {
title: gettext('Create Role'),
schema: schema,
- form: ['*'],
+ form: form,
model: model,
size: 'md'
};
.result;
}
+ function getRoles() {
+ keystoneAPI.getRoles().then(function(response) {
+ roles = response.data.items.map(getName);
+ });
+ }
+
+ function getName(item) {
+ return item.name;
+ }
+
}
})();
