2017-05-23 18:56:10 +00:00
|
|
|
angular.module('portainer.services')
|
|
|
|
.factory('FormValidator', [function FormValidatorFactory() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var validator = {};
|
|
|
|
|
|
|
|
validator.validateAccessControl = function(accessControlData, isAdmin) {
|
2017-07-12 07:51:51 +00:00
|
|
|
if (!accessControlData.AccessControlEnabled) {
|
2017-05-23 18:56:10 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2017-07-12 07:51:51 +00:00
|
|
|
if (isAdmin && accessControlData.Ownership === 'restricted' &&
|
|
|
|
accessControlData.AuthorizedUsers.length === 0 &&
|
|
|
|
accessControlData.AuthorizedTeams.length === 0) {
|
2017-05-23 18:56:10 +00:00
|
|
|
return 'You must specify at least one team or user.';
|
2017-07-12 07:51:51 +00:00
|
|
|
} else if (!isAdmin && accessControlData.Ownership === 'restricted' &&
|
|
|
|
accessControlData.AuthorizedTeams.length === 0) {
|
2017-05-23 18:56:10 +00:00
|
|
|
return 'You must specify at least a team.';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
|
|
|
return validator;
|
|
|
|
}]);
|