diff --git a/src/slices/eventDetailsSlice.ts b/src/slices/eventDetailsSlice.ts index 89a75b5044..ed0d16cfbe 100644 --- a/src/slices/eventDetailsSlice.ts +++ b/src/slices/eventDetailsSlice.ts @@ -844,25 +844,36 @@ export const fetchAccessPolicies = createAppAsyncThunk('eventDetails/fetchAccess let accessPolicies = await policyData.data; let policies: TransformedAcl[] = []; - 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]; + // By default, allow is true + policy.allow ??= true; + 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) { + newPolicies[policy.role].actions.push(policy.action); } - policies = policyRoles.map((role) => newPolicies[role]); } + policies = policyRoles.map((role) => newPolicies[role]); + return policies; });