diff --git a/web/src/components/MemoContent/index.tsx b/web/src/components/MemoContent/index.tsx index f08a3828..0519db11 100644 --- a/web/src/components/MemoContent/index.tsx +++ b/web/src/components/MemoContent/index.tsx @@ -4,6 +4,7 @@ import useCurrentUser from "@/hooks/useCurrentUser"; import { useMemoStore } from "@/store/v1"; import { Node, NodeType } from "@/types/proto/api/v1/markdown_service"; import { useTranslate } from "@/utils/i18n"; +import { isSuperUser } from "@/utils/user"; import Renderer from "./Renderer"; import { RendererContext } from "./types"; @@ -33,7 +34,7 @@ const MemoContent: React.FC = (props: Props) => { const memoContentContainerRef = useRef(null); const [showCompactMode, setShowCompactMode] = useState(false); const memo = memoName ? memoStore.getMemoByName(memoName) : null; - const allowEdit = !props.readonly && memo && currentUser?.name === memo.creator; + const allowEdit = !props.readonly && memo && (currentUser?.name === memo.creator || isSuperUser(currentUser)); // Initial compact mode. useEffect(() => { diff --git a/web/src/components/MemoView.tsx b/web/src/components/MemoView.tsx index 5c0a8a95..cab4377a 100644 --- a/web/src/components/MemoView.tsx +++ b/web/src/components/MemoView.tsx @@ -8,11 +8,11 @@ import useNavigateTo from "@/hooks/useNavigateTo"; import { useUserStore, useWorkspaceSettingStore } from "@/store/v1"; import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service"; import { Memo, Visibility } from "@/types/proto/api/v1/memo_service"; -import { User_Role } from "@/types/proto/api/v1/user_service"; import { WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service"; import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting"; import { useTranslate } from "@/utils/i18n"; import { convertVisibilityToString } from "@/utils/memo"; +import { isSuperUser } from "@/utils/user"; import MemoActionMenu from "./MemoActionMenu"; import MemoContent from "./MemoContent"; import MemoEditor from "./MemoEditor"; @@ -54,7 +54,7 @@ const MemoView: React.FC = (props: Props) => { (relation) => relation.type === MemoRelation_Type.COMMENT && relation.relatedMemo === memo.name, ).length; const relativeTimeFormat = Date.now() - memo.displayTime!.getTime() > 1000 * 60 * 60 * 24 ? "datetime" : "auto"; - const readonly = memo.creator !== user?.name && user.role === User_Role.USER; + const readonly = memo.creator !== user?.name || isSuperUser(user); const isInMemoDetailPage = location.pathname.startsWith(`/m/${memo.uid}`); // Initial related data: creator. diff --git a/web/src/utils/user.ts b/web/src/utils/user.ts new file mode 100644 index 00000000..c2d8769f --- /dev/null +++ b/web/src/utils/user.ts @@ -0,0 +1,5 @@ +import { User, User_Role } from "@/types/proto/api/v1/user_service"; + +export const isSuperUser = (user: User) => { + return user.role === User_Role.ADMIN || user.role === User_Role.HOST; +};