-
Notifications
You must be signed in to change notification settings - Fork 383
/
RulesEditor.js
32 lines (31 loc) · 1.17 KB
/
RulesEditor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Copyright 2018, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const {isEqual, isEmpty} = require("lodash");
const checkIp = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.)){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(\/)(?:3[0-2]|[1-2]?[0-9]))\b/g;
const RulesEditorUtils = {
isSaveDisabled: (currentRule, initRule) => {
return RulesEditorUtils.isRulePristine(currentRule, initRule) && initRule.hasOwnProperty("id");
},
areDetailsActive: (layer, {grant} = {}) => {
return !!layer && grant !== "DENY";
},
isRulePristine: (currentRule, initRule) => {
return isEqual(currentRule, initRule);
},
isRuleValid: ({ipaddress = ""} = {}) => {
if (ipaddress.length > 0 ) {
return !!ipaddress.match(checkIp);
}
return true;
},
askConfirm: ({constraints = {}} = {}, key, value) => {
return !isEmpty(constraints) && (key === "workspace" || key === "layer" || (key === "grant" && value !== "ALLOW"));
},
checkIp
};
module.exports = RulesEditorUtils;