mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-06 22:59:20 +01:00
🐛 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:
@@ -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 }) {
|
||||
<RichTextEditor.Content />
|
||||
</ScrollArea>
|
||||
</RichTextEditor>
|
||||
{!enabled && (
|
||||
{enabled && (
|
||||
<>
|
||||
<ActionIcon
|
||||
title={isEditing ? t('common:save') : t('common:edit')}
|
||||
|
||||
Reference in New Issue
Block a user