Skip to content

Commit

Permalink
RANGER-4392: Tag based policy with boolean expression is not working
Browse files Browse the repository at this point in the history
Signed-off-by: Dineshkumar Yadav <[email protected]>
  • Loading branch information
fimugdha authored and dineshkumar-yadav committed Sep 7, 2023
1 parent 5eedf6f commit 2f1b005
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,7 @@ const CustomCondition = (props) => {
<CreatableSelect
{...selectProps}
defaultValue={
selectedInputVal == ""
? null
: !isArray(selectedInputVal)
? selectedInputVal
?.split(", ")
.map((obj) => ({ label: obj, value: obj }))
: selectedInputVal
selectedInputVal == "" ? null : selectedInputVal
}
onChange={(e) => handleChange(e, m.name)}
placeholder="enter expression"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ export default function AddUpdatePolicyForm(props) {
policyData?.policyItems,
serviceCompData?.accessTypes,
null,
serviceCompData?.name
serviceCompData?.name,
serviceCompData
)
: [{}];
data.allowExceptions =
Expand All @@ -314,7 +315,8 @@ export default function AddUpdatePolicyForm(props) {
policyData?.allowExceptions,
serviceCompData?.accessTypes,
null,
serviceCompData?.name
serviceCompData?.name,
serviceCompData
)
: [{}];
data.denyPolicyItems =
Expand All @@ -323,7 +325,8 @@ export default function AddUpdatePolicyForm(props) {
policyData?.denyPolicyItems,
serviceCompData?.accessTypes,
null,
serviceCompData?.name
serviceCompData?.name,
serviceCompData
)
: [{}];
data.denyExceptions =
Expand All @@ -332,7 +335,8 @@ export default function AddUpdatePolicyForm(props) {
policyData.denyExceptions,
serviceCompData?.accessTypes,
null,
serviceCompData?.name
serviceCompData?.name,
serviceCompData
)
: [{}];
data.dataMaskPolicyItems =
Expand All @@ -341,7 +345,8 @@ export default function AddUpdatePolicyForm(props) {
policyData.dataMaskPolicyItems,
serviceCompData?.dataMaskDef?.accessTypes,
serviceCompData?.dataMaskDef?.maskTypes,
serviceCompData?.name
serviceCompData?.name,
serviceCompData
)
: [{}];
data.rowFilterPolicyItems =
Expand All @@ -350,7 +355,8 @@ export default function AddUpdatePolicyForm(props) {
policyData.rowFilterPolicyItems,
serviceCompData?.rowFilterDef?.accessTypes,
null,
serviceCompData?.name
serviceCompData?.name,
serviceCompData
)
: [{}];
if (policyId) {
Expand Down Expand Up @@ -433,8 +439,23 @@ export default function AddUpdatePolicyForm(props) {
/* Policy condition */
if (policyData?.conditions?.length > 0) {
data.conditions = {};

for (let val of policyData.conditions) {
data.conditions[val?.type] = val?.values?.join(",");
let conditionObj = find(
policyConditionUpdatedJSON(serviceCompData?.policyConditions),
function (m) {
if (m.name == val.type) {
return m;
}
}
);

if (!isEmpty(conditionObj.uiHint)) {
data.conditions[val?.type] = JSON.parse(conditionObj.uiHint)
.isMultiValue
? val?.values
: val?.values.toString();
}
}
}
}
Expand Down Expand Up @@ -498,11 +519,11 @@ export default function AddUpdatePolicyForm(props) {
([conditionKey, conditionValue]) => {
return obj.conditions.push({
type: conditionKey,
values: !isArray(conditionValue)
? conditionValue?.split(",")
: conditionValue.map((m) => {
values: isArray(conditionValue)
? conditionValue.map((m) => {
return m.value;
})
: [conditionValue]
});
}
);
Expand All @@ -527,7 +548,13 @@ export default function AddUpdatePolicyForm(props) {
return policyResourceItem;
};

const setPolicyItemVal = (formData, accessTypes, maskTypes, serviceType) => {
const setPolicyItemVal = (
formData,
accessTypes,
maskTypes,
serviceType,
serviceData
) => {
return formData.map((val) => {
let obj = {},
accessTypesObj = [];
Expand Down Expand Up @@ -603,13 +630,32 @@ export default function AddUpdatePolicyForm(props) {
obj.dataMaskInfo.valueExpr = val.dataMaskInfo.valueExpr;
}
}
/* Policy Condition*/

/* Policy Condition */
if (val?.conditions?.length > 0) {
obj.conditions = {};

for (let data of val.conditions) {
obj.conditions[data.type] = data.values.join(", ");
let conditionObj = find(
policyConditionUpdatedJSON(serviceData?.policyConditions),
function (m) {
if (m.name == data.type) {
return m;
}
}
);

if (!isEmpty(conditionObj.uiHint)) {
obj.conditions[data?.type] = JSON.parse(conditionObj.uiHint)
.isMultiValue
? data?.values.map((m) => {
return { value: m, label: m };
})
: data?.values.toString();
}
}
}

return obj;
});
};
Expand Down Expand Up @@ -717,7 +763,7 @@ export default function AddUpdatePolicyForm(props) {
Object.entries(values.conditions).map(([key, value]) => {
return data.conditions.push({
type: key,
values: value?.split(",")
values: isArray(value) ? value : [value]
});
});
} else {
Expand Down Expand Up @@ -1359,25 +1405,17 @@ export default function AddUpdatePolicyForm(props) {
<tr key={keyName}>
<td>
<center>
{" "}
{conditionObj.label}{" "}
{conditionObj.label}
</center>
</td>
<td>
{isObject(
values.conditions[keyName]
{isArray(
values?.conditions[keyName]
) ? (
<center>
{values.conditions[keyName]
.length > 1
? values.conditions[
keyName
].map((m) => {
return ` ${m.label} `;
})
: values.conditions[
keyName
].label}
{values.conditions[
keyName
].join(", ")}
</center>
) : (
<center>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Col, Form as FormB, Row, Modal, Button } from "react-bootstrap";
import { Form, Field } from "react-final-form";
import Select from "react-select";
import CreatableSelect from "react-select/creatable";
import { find } from "lodash";
import { find, isEmpty } from "lodash";
import { InfoIcon } from "../../utils/XAUtils";
import { RegexMessage } from "../../utils/XAMessages";
const esprima = require("esprima");
Expand Down Expand Up @@ -79,17 +79,17 @@ export default function PolicyConditionsComp(props) {
};

const handleChange = (val, input) => {
let value = null;
let value = [];
if (val) {
value = val.map((m) => m.value).join(",");
value = val.map((m) => m.value);
}
input.onChange(value);
};

const ipRangeVal = (val) => {
let value = null;
if (val) {
value = val.split(",").map((m) => ({ label: m, value: m }));
let value = [];
if (!isEmpty(val)) {
value = val.map((m) => ({ label: m, value: m }));
}
return value;
};
Expand Down

0 comments on commit 2f1b005

Please sign in to comment.