consul/ui/packages/consul-ui/app/validations/intention-permission.js
Valeriia Ruban 663a5642c2
[UI]: update Ember to 3.27 (#16227)
* Upgrade to 3.25 via ember-cli-update

* v3.25.3...v3.26.1

* v3.26.1...v3.27.0


Co-authored-by: Michael Klein <michael@firstiwaslike.com>
2023-02-10 13:32:19 -08:00

34 lines
1.0 KiB
JavaScript

import {
validateInclusion,
validatePresence,
validateFormat,
} from 'ember-changeset-validations/validators';
import validateSometimes from 'consul-ui/validations/sometimes';
const name = 'intention-permission';
export default (schema) => ({
'*': [
validateSometimes(validatePresence(true), function () {
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: {
Path: [
validateSometimes(validateFormat({ regex: /^\// }), function () {
const pathType = this.get('HTTP.PathType');
return typeof pathType !== 'undefined' && pathType !== 'NoPath';
}),
],
},
});