Skip to content

Commit

Permalink
fix: changed access level rank for resolving a comment to content
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 6658dbc471d98131cab6c65c66c0e746ea942f21
  • Loading branch information
abbas-nazar authored and actions-user committed Jan 9, 2025
1 parent 9b79734 commit e8e743a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
10 changes: 6 additions & 4 deletions platform/wab/src/wab/client/components/comments/CommentPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {
} from "@/wab/client/plasmic/plasmic_kit_comments/PlasmicCommentPost";
import PlasmicReactionButton from "@/wab/client/plasmic/plasmic_kit_comments/PlasmicReactionButton";
import {
isUserProjectEditor,
isUserProjectContentEditor,
isUserProjectOwner,
useStudioCtx,
} from "@/wab/client/studio-ctx/StudioCtx";
import { StandardMarkdown } from "@/wab/client/utils/StandardMarkdown";
import { OnClickAway } from "@/wab/commons/components/OnClickAway";
import { ApiCommentReaction, CommentId } from "@/wab/shared/ApiSchema";
import { fullName } from "@/wab/shared/ApiSchemaUtil";
import { ensure, ensureString, maybe, spawn } from "@/wab/shared/common";
import { StandardMarkdown } from "@/wab/client/utils/StandardMarkdown";
import { HTMLElementRefOf } from "@plasmicapp/react-web";
import { Menu, Tooltip } from "antd";
import Popover from "antd/lib/popover";
Expand Down Expand Up @@ -112,7 +112,7 @@ function CommentMenuOptions(props: {
const appCtx = useAppCtx();
const api = appCtx.api;

const isEditor = isUserProjectEditor(
const isContentEditor = isUserProjectContentEditor(
appCtx.selfInfo,
studioCtx.siteInfo,
studioCtx.siteInfo.perms
Expand All @@ -130,7 +130,9 @@ function CommentMenuOptions(props: {
<Menu>
<Menu.Item
key="change-status"
disabled={!isEditor}
disabled={
!(isContentEditor || appCtx.selfInfo?.id === comment.createdById)
}
onClick={async () => {
await api.editComment(projectId, branchId, comment.id, {
resolved: !comment.resolved,
Expand Down
8 changes: 8 additions & 0 deletions platform/wab/src/wab/client/studio-ctx/StudioCtx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6853,6 +6853,14 @@ export function checkAccessLevelRank(
);
}

export function isUserProjectContentEditor(
user: ApiUser | null,
project: ApiProject,
perms: ApiPermission[]
) {
return checkAccessLevelRank(user, project, perms, "content");
}

export function isUserProjectEditor(
user: ApiUser | null,
project: ApiProject,
Expand Down
12 changes: 11 additions & 1 deletion platform/wab/src/wab/server/db/DbMgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9651,7 +9651,17 @@ export class DbMgr implements MigrationDbMgr {
id: commentId,
});

this.checkUserIdIsSelf(comment.createdById ?? undefined);
if (!this.isUserIdSelf(comment.createdById ?? undefined)) {
if ("body" in data) {
throw new ForbiddenError("Can only do this for self.");
}
await this.checkProjectPerms(
comment.projectId,
"content",
"resolve a comment",
true
);
}

Object.assign(comment, this.stampUpdate(), data);
await this.entMgr.save(comment);
Expand Down

0 comments on commit e8e743a

Please sign in to comment.