Skip to content

Commit

Permalink
Move acl formatting function outside button wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
owi92 committed Sep 6, 2023
1 parent 898cf44 commit b6b72e4
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions frontend/src/routes/manage/Video/Access.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,38 +154,10 @@ const ButtonWrapper: React.FC<ButtonWrapper> = ({ aclSelectRef }) => {
|| acl.writeRoles.includes("ROLE_USER");
};

const ocAcl = (selections: ACL) => {
type ocACL = {
allow: true;
action: Action;
role: string;
}

const ocACL: ocACL[] = [];

selections.readRoles.forEach(role => ocACL.push(
{
allow: true,
action: "read",
role: role,
}
));

selections.writeRoles.forEach(role => ocACL.push(
{
allow: true,
action: "write",
role: role,
}
));

return ocACL;
};

const submit = async (acl: ACL) => {
// TODO: Actually save new ACL.
// eslint-disable-next-line no-console
console.log(acl);
console.log(ocAcl(acl));
};

return <div css={{ display: "flex", gap: 8, alignSelf: "flex-start", marginTop: 40 }}>
Expand Down Expand Up @@ -905,6 +877,36 @@ const getSelections = ({ groupsRef, usersRef }: Selections): ACL => {
return acl;
};

// Formats a selection of read- and write roles
// into the ACL format needed for the Opencast API.
const ocAcl = (selection: ACL) => {
type ocACL = {
allow: true;
action: Action;
role: string;
}

const ocACL: ocACL[] = [];

selection.readRoles.forEach(role => ocACL.push(
{
allow: true,
action: "read",
role: role,
}
));

selection.writeRoles.forEach(role => ocACL.push(
{
allow: true,
action: "write",
role: role,
}
));

return ocACL;
};


export const getUserRole = (user: UserState) => {
const userRole = isRealUser(user) && user.roles.find(role => /^ROLE_USER\w+/.test(role));
Expand Down

0 comments on commit b6b72e4

Please sign in to comment.