Skip to content

Commit

Permalink
Guard delete-image with DELETE_IMAGES role
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverroick committed Oct 23, 2023
1 parent b29ee42 commit f185097
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/auth/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const WRITE_DEPLOYMENTS_ROLES = [MANAGER];
export const WRITE_AUTOMATION_RULES_ROLES = [MANAGER];
export const WRITE_CAMERA_REGISTRATION_ROLES = [MANAGER];
export const QUERY_WITH_CUSTOM_FILTER = [MANAGER];
export const DELETE_IMAGES = [MANAGER, MEMBER];

export const hasRole = (currRoles, targetRoles = []) => (
currRoles && (currRoles.includes(SUPER_USER) || currRoles.some((role) => targetRoles.includes(role)))
Expand Down
40 changes: 22 additions & 18 deletions src/features/loupe/FullSizeImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useResizeObserver } from '../../app/utils';
import { styled } from '../../theme/stitches.config';
// import { CircleSpinner, SpinnerOverlay } from '../../components/Spinner';
import { selectUserUsername, selectUserCurrentRoles } from '../user/userSlice';
import { hasRole, WRITE_OBJECTS_ROLES, WRITE_IMAGES_ROLES } from '../../auth/roles';
import { hasRole, WRITE_OBJECTS_ROLES, DELETE_IMAGES } from '../../auth/roles';
import { drawBboxStart, selectIsDrawingBbox} from './loupeSlice';
import { selectWorkingImages, labelsValidated, markedEmpty } from '../review/reviewSlice';
import { deleteImages } from '../images/imagesSlice';
Expand Down Expand Up @@ -195,7 +195,7 @@ const FullSizeImage = ({ image, focusIndex }) => {
</ContextMenuItemIconLeft>
Mark empty
</ContextMenuItem>
{hasRole(userRoles, WRITE_IMAGES_ROLES) &&
{hasRole(userRoles, DELETE_IMAGES) &&
<ContextMenuItem
onSelect={handleDeleteButtonClick}
>
Expand All @@ -210,25 +210,29 @@ const FullSizeImage = ({ image, focusIndex }) => {
<ShareImage>
<ShareImageButton imageId={image._id}/>
</ShareImage>
{hasRole(userRoles, WRITE_OBJECTS_ROLES) &&
<EditObjectButtons>
<EditObjectButtons>
{hasRole(userRoles, DELETE_IMAGES) &&
<EditObjectButton onClick={handleDeleteButtonClick}>
<TrashIcon /> Delete
</EditObjectButton>
<EditObjectButton onClick={handleMarkEmptyButtonClick}>
<Cross2Icon /> Mark empty
</EditObjectButton>
<EditObjectButton
onClick={handleAddObjectButtonClick}
css={{
color: '$loContrast',
backgroundColor: '$hiContrast',
}}
>
<PlusIcon /> Add object
</EditObjectButton>
</EditObjectButtons>
}
}
{hasRole(userRoles, WRITE_OBJECTS_ROLES) &&
<>
<EditObjectButton onClick={handleMarkEmptyButtonClick}>
<Cross2Icon /> Mark empty
</EditObjectButton>
<EditObjectButton
onClick={handleAddObjectButtonClick}
css={{
color: '$loContrast',
backgroundColor: '$hiContrast',
}}
>
<PlusIcon /> Add object
</EditObjectButton>
</>
}
</EditObjectButtons>
</ImageWrapper>
);
};
Expand Down

0 comments on commit f185097

Please sign in to comment.