Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dagl and regna bug in policy editor #12247

Merged
13 commits merged into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion frontend/packages/policy-editor/src/PolicyEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ export const PolicyEditor = ({
const policyEditorRules: PolicyRule[] = rules.map((pr) =>
mapPolicyRuleToPolicyRuleBackendObject(
subjects,
actions,
pr,
`${resourceType}:${usageType === 'app' ? 'example' : resourceId}:ruleid:${pr.ruleId}`, // TODO - find out if ID should be hardcoded. Issue: #10893
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ describe('PolicyEditorUtils', () => {
it('should map a policy rule card to a policy rule backend object', () => {
const result = mapPolicyRuleToPolicyRuleBackendObject(
mockSubjects,
mockActions,
mockPolicyRuleCard1,
mockRuleId1,
);
Expand Down
12 changes: 5 additions & 7 deletions frontend/packages/policy-editor/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,22 @@ export const mapSubjectTitleToSubjectString = (
const subject: PolicySubject = subjectOptions.find(
(s) => s.subjectTitle.toLowerCase() === subjectTitle.toLowerCase(),
);
return `urn:${subject.subjectSource}:${subject.subjectId}`;
if (subject === undefined) return;
return `urn:${subject?.subjectSource}:${subject?.subjectId}`;
This conversation was marked as resolved.
Show resolved Hide resolved
};

/**
* Maps a policy rule object used on the policy cards to a policy rule object
* to be sent to backend where all fields are strings.
*
* @param subjectOptions the possible subjects to select from
* @param actionOptions the possible actions to select from
* @param policyRule the policy rule to map
* @param ruleId the id of the rule
*
* @returns a mapped object ready to be sent to backend
*/
export const mapPolicyRuleToPolicyRuleBackendObject = (
subjectOptions: PolicySubject[],
actionOptions: PolicyAction[],
policyRule: PolicyRuleCard,
ruleId: string,
): PolicyRule => {
Expand All @@ -141,8 +140,8 @@ export const mapPolicyRuleToPolicyRuleBackendObject = (
.map((r) => (r.type.startsWith('urn:') ? `${r.type}:${r.id}` : `urn:${r.type}:${r.id}`)),
);

const subject: string[] = policyRule.subject.map((s) =>
mapSubjectTitleToSubjectString(subjectOptions, s),
const subject: string[] = policyRule.subject.map(
(s) => s && mapSubjectTitleToSubjectString(subjectOptions, s),
);
This conversation was marked as resolved.
Show resolved Hide resolved

return {
Expand Down Expand Up @@ -231,8 +230,7 @@ export const mergeSubjectsFromPolicyWithSubjectOptions = (
rules.forEach((rule) => {
rule.subject.forEach((subjectString) => {
const subjectId = convertSubjectStringToSubjectId(subjectString);

if (!existingSubjectIds.includes(subjectId)) {
if (!existingSubjectIds.includes(subjectId?.toLowerCase())) {
This conversation was marked as resolved.
Show resolved Hide resolved
const newSubject: PolicySubject = createNewSubjectFromSubjectString(subjectString);
copiedSubjects.push(newSubject);
existingSubjectIds.push(subjectId);
Expand Down
Loading