From de344ccea979a08a8cd0c3efdb9e1f1d9ab300e3 Mon Sep 17 00:00:00 2001 From: Tagaishi Date: Tue, 14 Nov 2023 20:02:24 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Remove=20notebook=20edit=20butto?= =?UTF-8?q?n=20for=20non=20admins=20(#1634)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 Remove permission to modify text to non admins * 🐛 notebook read only checks admin only Fixed by @Tagaishi --- src/widgets/notebook/NotebookEditor.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/widgets/notebook/NotebookEditor.tsx b/src/widgets/notebook/NotebookEditor.tsx index b52c4899c..63ca61310 100644 --- a/src/widgets/notebook/NotebookEditor.tsx +++ b/src/widgets/notebook/NotebookEditor.tsx @@ -49,9 +49,9 @@ import TextStyle from '@tiptap/extension-text-style'; import Underline from '@tiptap/extension-underline'; import { BubbleMenu, useEditor } from '@tiptap/react'; import StarterKit from '@tiptap/starter-kit'; +import { useSession } from 'next-auth/react'; import { useTranslation } from 'next-i18next'; import { Dispatch, SetStateAction, useState } from 'react'; -import { useEditModeStore } from '~/components/Dashboard/Views/useEditModeStore'; import { useConfigContext } from '~/config/provider'; import { useConfigStore } from '~/config/store'; import { api } from '~/utils/api'; @@ -63,7 +63,8 @@ export function Editor({ widget }: { widget: INotebookWidget }) { const [content, setContent] = useState(widget.properties.content); const [toSaveContent, setToSaveContent] = useState(content); - const { enabled } = useEditModeStore(); + const { data: sessionData } = useSession(); + const enabled = !!sessionData?.user.isAdmin; const [isEditing, setIsEditing] = useState(false); const { config, name: configName } = useConfigContext(); @@ -119,11 +120,12 @@ export function Editor({ widget }: { widget: INotebookWidget }) { TaskItem.configure({ nested: true, onReadOnlyChecked: (node, checked) => { - if (widget.properties.allowReadOnlyCheck) { + if (widget.properties.allowReadOnlyCheck && enabled) { const event = new CustomEvent('onReadOnlyCheck', { detail: { node, checked } }); dispatchEvent(event); + return true; } - return widget.properties.allowReadOnlyCheck; + return false; }, }), TaskList.configure({ itemTypeName: 'taskItem' }), @@ -327,7 +329,7 @@ export function Editor({ widget }: { widget: INotebookWidget }) { - {!enabled && ( + {enabled && ( <>