Skip to content

Commit

Permalink
Make archive buttons only accessible by admins (#187)
Browse files Browse the repository at this point in the history
* Make archiving only available to admins
  • Loading branch information
elouiestudent authored Nov 19, 2022
1 parent e3511cd commit 928945d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
33 changes: 17 additions & 16 deletions client/src/components/EditItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ function EditItem(props: {
);
};

const isAdmin = props.user?.permissions.some((value) =>
value.includes(PermissionType.ADMIN)
);

return (
<Grid columns={1}>
<Grid.Column>
Expand Down Expand Up @@ -426,28 +430,25 @@ function EditItem(props: {
<DeleteButton
id={props.id}
fetchItems={props.fetchItems}
disabled={
props.item.approved &&
!props.user.permissions.some((value) =>
value.includes(PermissionType.ADMIN)
)
}
disabled={props.item.approved && !isAdmin}
/>
<div
style={{
width: "10px",
}}
/>
<ArchiveButton
id={props.id}
fetchItems={props.fetchItems}
disabled={
props.item.approved &&
!props.user.permissions.some((value) =>
value.includes(PermissionType.ADMIN)
)
}
/>
{isAdmin ? (
<ArchiveButton
id={props.id}
fetchItems={props.fetchItems}
disabled={
props.item.approved &&
!props.user.permissions.some((value) =>
value.includes(PermissionType.ADMIN)
)
}
/>
) : null}
</div>
<div
style={{
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/TableWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ const TableWidget = (props: {
`${BuildingType.ALL}:${PermissionType.ADMIN}`
) ?? false;

const isAdmin = props.user?.permissions.some((value) =>
value.includes(PermissionType.ADMIN)
);

return (
<div>
<div className="table-buttons">
Expand All @@ -81,7 +85,7 @@ const TableWidget = (props: {
fetchItems={props.fetchItems}
items={props.fixedItems}
/>
{!props.isArchivedItems ? (
{!props.isArchivedItems && isAdmin ? (
<BulkArchiveButton
fetchItems={props.fetchItems}
></BulkArchiveButton>
Expand Down

0 comments on commit 928945d

Please sign in to comment.