Skip to content

Commit d2d2e9f

Browse files
committed
Replaced description in policy form with auto generation
1 parent 9d13371 commit d2d2e9f

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

client/src/locale/en.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,9 @@ const en = {
11151115
submitExisting: "Update",
11161116
breakdown: {
11171117
if: "If",
1118-
when: "When"
1118+
when: "When",
1119+
allowDescriptionPrefix: "A user from '{{idp}}' is only allowed acces to '{{sp}}'",
1120+
denyDescriptionPrefix: "A user from '{{idp}}' is denied acces to '{{sp}}'"
11191121
},
11201122
flash: {
11211123
created: "Policy {{name}} has been created and is ready for use",

client/src/policies/PolicyForm.jsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {deletePolicy, newPolicy, uniquePolicyName, updatePolicy} from "../api/in
99
import {isEmpty} from "../utils/Utils.js";
1010
import ErrorIndicator from "../components/ErrorIndicator.jsx";
1111
import SelectField from "../components/SelectField.jsx";
12-
import {defaultAttributes, flatMapByValues} from "../utils/Policy.js";
12+
import {defaultAttributes, flatMapByValues, policyDesscription} from "../utils/Policy.js";
1313
import TrashIcon from "@surfnet/sds/icons/functional-icons/bin.svg";
1414
import ConfirmationDialog from "../components/ConfirmationDialog.jsx";
1515

@@ -61,6 +61,16 @@ export const PolicyForm = ({policy, setPolicy, isExistingPolicy, originalName, r
6161
const promise = isExistingPolicy ? updatePolicy : newPolicy;
6262
//We need to destructure the attributes with multiple values, to single attribute / value pairs
6363
policy.data.attributes = flatMapByValues([...policy.data.attributes]);
64+
policy.data.description = policyDesscription(
65+
allowedAttributes,
66+
policy,
67+
I18n.t(`appAccess.breakdown.${policy.data.denyRule ? "when" : "if"}`).toLowerCase(),
68+
I18n.t("forms.or"),
69+
I18n.t(`forms.${policy.data.allAttributesMustMatch ? "and" : "or"}`),
70+
I18n.t(`appAccess.breakdown.${policy.data.denyRule ? "deny" : "allow"}DescriptionPrefix`, {
71+
idp: policy.data.identityProviderIds[0].name, sp: policy.data.serviceProviderIds[0].name
72+
})
73+
);
6474
promise(policy)
6575
.then(res => {
6676
setFlash(I18n.t(`appAccess.flash.${isExistingPolicy ? "updated" : "created"}`, {name: res.data.name}));
@@ -154,18 +164,6 @@ export const PolicyForm = ({policy, setPolicy, isExistingPolicy, originalName, r
154164
<ErrorIndicator adjustMargin={true}
155165
msg={I18n.t("appAccess.duplicateName", {name: policy.data.name})}/>}
156166

157-
<InputField name={I18n.t("appAccess.description")}
158-
value={policy.data.description}
159-
required={true}
160-
multiline={true}
161-
error={!initial && isEmpty(policy.data.description)}
162-
placeholder={I18n.t("appAccess.placeholderDescription")}
163-
onChange={e => internalUpdatePolicy({description: e.target.value})}
164-
/>
165-
{(!initial && isEmpty(policy.data.description)) &&
166-
<ErrorIndicator adjustMargin={true}
167-
msg={I18n.t("forms.required", {name: I18n.t("appAccess.description")})}/>}
168-
169167
<div className="row">
170168
<div className="row-item">
171169
<span className="label standalone">{I18n.t("appAccess.allowDeny")}

client/src/utils/Policy.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ export const policyBreakDowwn = (allowedAttributes, policy, prefix, orSeparator,
4545
const policyRules = grouped.map(attribute => {
4646
const name = attributeName(allowedAttributes, attribute);
4747
const values = splitListSemantically(attribute.value.map(val => `'${val.label}'`), orSeparator)
48-
return `${prefix} '${name}' = ${values}`;
48+
return `${prefix} ${name} = ${values}`;
4949
});
5050
return policyRules.flatMap((item, index) =>
5151
index < policyRules.length - 1 ? [item, attributeSeparator] : [item]
5252
);
5353
}
5454

55+
export const policyDesscription = (allowedAttributes, policy, prefix, orSeparator, attributeSeparator, prefixDescription) => {
56+
const breakDown = policyBreakDowwn(allowedAttributes, policy, prefix, orSeparator, attributeSeparator);
57+
return `${prefixDescription} ${breakDown.join(" ")}.`;
58+
}
59+
5560
export const flatMapByValues = attributes => {
5661
return attributes.flatMap(attribute =>
5762
attribute.value.map(val => ({

0 commit comments

Comments
 (0)