Skip to content

Commit

Permalink
Fix undefined error in empty access policies
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis531 committed Jul 25, 2024
1 parent ea0a526 commit ace958b
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/slices/eventDetailsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,25 +855,34 @@ export const fetchAccessPolicies = createAppAsyncThunk('eventDetails/fetchAccess
let accessPolicies = await policyData.data;

let policies: TransformedAcls = [];
if (!!accessPolicies.episode_access) {
const json = JSON.parse(accessPolicies.episode_access.acl).acl.ace;
let newPolicies: { [key: string]: TransformedAcl } = {};
let policyRoles: string[] = [];
for (let i = 0; i < json.length; i++) {
const policy: Ace = json[i];
if (!newPolicies[policy.role]) {
newPolicies[policy.role] = createPolicy(policy.role);
policyRoles.push(policy.role);
}
if (policy.action === "read" || policy.action === "write") {
newPolicies[policy.role][policy.action] = policy.allow;
} else if (policy.allow === true) { //|| policy.allow === "true") {
newPolicies[policy.role].actions.push(policy.action);
}

if (!accessPolicies.episode_access) {
return policies;
}

const json = JSON.parse(accessPolicies.episode_access.acl).acl.ace;
if (json === undefined) {
return policies;
}

let newPolicies: { [key: string]: TransformedAcl } = {};
let policyRoles: string[] = [];

for (let i = 0; i < json.length; i++) {
const policy: Ace = json[i];
if (!newPolicies[policy.role]) {
newPolicies[policy.role] = createPolicy(policy.role);
policyRoles.push(policy.role);
}
if (policy.action === "read" || policy.action === "write") {
newPolicies[policy.role][policy.action] = policy.allow;
} else if (policy.allow === true) { //|| policy.allow === "true") {
newPolicies[policy.role].actions.push(policy.action);
}
policies = policyRoles.map((role) => newPolicies[role]);
}

policies = policyRoles.map((role) => newPolicies[role]);

return policies;
});

Expand Down

0 comments on commit ace958b

Please sign in to comment.