🐛 Remove notebook edit button for non admins (#1634)

* 🐛 Remove permission to modify text to non admins

* 🐛 notebook read only checks admin only

Fixed by @Tagaishi
This commit is contained in:
Tagaishi
2023-11-14 20:02:24 +01:00
committed by GitHub
parent b05152abb1
commit de344ccea9

View File

@@ -49,9 +49,9 @@ import TextStyle from '@tiptap/extension-text-style';
import Underline from '@tiptap/extension-underline'; import Underline from '@tiptap/extension-underline';
import { BubbleMenu, useEditor } from '@tiptap/react'; import { BubbleMenu, useEditor } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit'; import StarterKit from '@tiptap/starter-kit';
import { useSession } from 'next-auth/react';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import { Dispatch, SetStateAction, useState } from 'react'; import { Dispatch, SetStateAction, useState } from 'react';
import { useEditModeStore } from '~/components/Dashboard/Views/useEditModeStore';
import { useConfigContext } from '~/config/provider'; import { useConfigContext } from '~/config/provider';
import { useConfigStore } from '~/config/store'; import { useConfigStore } from '~/config/store';
import { api } from '~/utils/api'; import { api } from '~/utils/api';
@@ -63,7 +63,8 @@ export function Editor({ widget }: { widget: INotebookWidget }) {
const [content, setContent] = useState(widget.properties.content); const [content, setContent] = useState(widget.properties.content);
const [toSaveContent, setToSaveContent] = useState(content); const [toSaveContent, setToSaveContent] = useState(content);
const { enabled } = useEditModeStore(); const { data: sessionData } = useSession();
const enabled = !!sessionData?.user.isAdmin;
const [isEditing, setIsEditing] = useState(false); const [isEditing, setIsEditing] = useState(false);
const { config, name: configName } = useConfigContext(); const { config, name: configName } = useConfigContext();
@@ -119,11 +120,12 @@ export function Editor({ widget }: { widget: INotebookWidget }) {
TaskItem.configure({ TaskItem.configure({
nested: true, nested: true,
onReadOnlyChecked: (node, checked) => { onReadOnlyChecked: (node, checked) => {
if (widget.properties.allowReadOnlyCheck) { if (widget.properties.allowReadOnlyCheck && enabled) {
const event = new CustomEvent('onReadOnlyCheck', { detail: { node, checked } }); const event = new CustomEvent('onReadOnlyCheck', { detail: { node, checked } });
dispatchEvent(event); dispatchEvent(event);
return true;
} }
return widget.properties.allowReadOnlyCheck; return false;
}, },
}), }),
TaskList.configure({ itemTypeName: 'taskItem' }), TaskList.configure({ itemTypeName: 'taskItem' }),
@@ -327,7 +329,7 @@ export function Editor({ widget }: { widget: INotebookWidget }) {
<RichTextEditor.Content /> <RichTextEditor.Content />
</ScrollArea> </ScrollArea>
</RichTextEditor> </RichTextEditor>
{!enabled && ( {enabled && (
<> <>
<ActionIcon <ActionIcon
title={isEditing ? t('common:save') : t('common:edit')} title={isEditing ? t('common:save') : t('common:edit')}