mirror of
https://github.com/usememos/memos.git
synced 2024-12-26 07:01:17 +08:00
chore: fix user role checks
This commit is contained in:
parent
7a9f61967d
commit
40d59fc47a
3 changed files with 9 additions and 3 deletions
|
@ -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: Props) => {
|
|||
const memoContentContainerRef = useRef<HTMLDivElement>(null);
|
||||
const [showCompactMode, setShowCompactMode] = useState<boolean>(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(() => {
|
||||
|
|
|
@ -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: 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.
|
||||
|
|
5
web/src/utils/user.ts
Normal file
5
web/src/utils/user.ts
Normal file
|
@ -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;
|
||||
};
|
Loading…
Reference in a new issue