2020-09-30 11:33:01 +00:00
|
|
|
import {
|
|
|
|
validateInclusion,
|
|
|
|
validatePresence,
|
|
|
|
validateFormat,
|
|
|
|
} from 'ember-changeset-validations/validators';
|
|
|
|
import validateSometimes from 'ember-changeset-conditional-validations/validators/sometimes';
|
|
|
|
|
|
|
|
const name = 'intention-permission';
|
2022-09-15 08:43:17 +00:00
|
|
|
export default (schema) => ({
|
|
|
|
'*': validateSometimes([validatePresence(true)], function () {
|
2020-09-30 11:33:01 +00:00
|
|
|
const methods = this.get('HTTP.Methods') || [];
|
|
|
|
const headers = this.get('HTTP.Header') || [];
|
|
|
|
const pathType = this.get('HTTP.PathType') || 'NoPath';
|
|
|
|
const path = this.get('HTTP.Path') || '';
|
|
|
|
const isValid = [
|
|
|
|
methods.length !== 0,
|
|
|
|
headers.length !== 0,
|
|
|
|
pathType !== 'NoPath' && path !== '',
|
|
|
|
].includes(true);
|
|
|
|
return !isValid;
|
|
|
|
}),
|
|
|
|
Action: [validateInclusion({ in: schema[name].Action.allowedValues })],
|
|
|
|
HTTP: {
|
2022-09-15 08:43:17 +00:00
|
|
|
Path: validateSometimes([validateFormat({ regex: /^\// })], function () {
|
2020-09-30 11:33:01 +00:00
|
|
|
const pathType = this.get('HTTP.PathType');
|
|
|
|
return typeof pathType !== 'undefined' && pathType !== 'NoPath';
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
});
|