fix(whiteboard): Update shape restriction logic (#21111)

* restrict local access to shapes for viewers to their own

* unlock / lock shapes when presenter or moderator role changes
This commit is contained in:
KDSBrowne 2024-09-16 09:55:10 -04:00 committed by GitHub
parent d8a0e9bd8e
commit b6cacbe0f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -49,27 +49,37 @@ const WhiteboardContainer = (props) => {
const layoutContextDispatch = layoutDispatch();
const { shapes } = props;
const hasShapeAccess = (id) => {
const owner = shapes[id]?.userId;
const shape = shapes[id];
const owner = shape?.userId;
const isBackgroundShape = id?.includes('slide-background');
const isPollsResult = shapes[id]?.name?.includes('poll-result');
const hasAccess =
(!isBackgroundShape && !isPollsResult) ||
(isPresenter &&
((owner && owner === currentUser?.userId) ||
!owner ||
isPresenter ||
isModerator));
const isPollsResult = shape?.name?.includes('poll-result');
return hasAccess;
};
// set shapes as locked for those who aren't allowed to edit it
Object.entries(shapes).forEach(([shapeId, shape]) => {
if (!shape.isLocked && !hasShapeAccess(shapeId) && !shape.name?.includes('poll-result')) {
const modShape = shape;
modShape.isLocked = true;
// Only the presenter has access to poll result shapes
if (isPollsResult) {
return isPresenter;
}
});
// No one should have access to background shapes
if (isBackgroundShape) {
return false;
}
// Viewers can only access their own shapes
// Presenters and moderators have access to all shapes
return (!owner || owner === currentUser?.userId) || isPresenter || isModerator;
};
React.useEffect(() => {
Object.entries(shapes).forEach(([shapeId, shape]) => {
if (!hasShapeAccess(shapeId)) {
shape.isLocked = true;
} else {
shape.isLocked = false;
}
});
}, [shapes, isPresenter, isModerator]);
return (
<Whiteboard