Skip to content

Commit

Permalink
Merge branch 'master' into feat/guardrails
Browse files Browse the repository at this point in the history
  • Loading branch information
soumik12345 authored Jan 17, 2025
2 parents bccc336 + 8d71115 commit 5661b1a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const ObjectVersionPageInner: React.FC<{
return data.result?.[0] ?? {};
}, [data.loading, data.result]);

const showDeleteButton = useShowDeleteButton();
const showDeleteButton = useShowDeleteButton(entityName);

const viewerDataAsObject = useMemo(() => {
const dataIsPrimitive =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const OpVersionPageInner: React.FC<{
// that data available yet.
return true;
}, []);
const showDeleteButton = useShowDeleteButton();
const showDeleteButton = useShowDeleteButton(entity);

return (
<SimplePageLayoutWithHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ export const DeleteModal: React.FC<DeleteModalProps> = ({
);
};

export const useShowDeleteButton = () => {
const viewerInfo = useViewerInfo();
return viewerInfo.loading ? false : viewerInfo.userInfo?.admin;
export const useShowDeleteButton = (entity: string) => {
const {loading: loadingUserInfo, userInfo} = useViewerInfo();
const viewerInfo = loadingUserInfo ? null : userInfo;
const viewer = viewerInfo ? viewerInfo.id : null;
const isReadonly = !viewer || !viewerInfo?.teams.includes(entity);
return !isReadonly;
};

const Dialog = styled(MaterialDialog)`
Expand Down

0 comments on commit 5661b1a

Please sign in to comment.