From f9dadf554803b210b3ae6a5b45c2e267bbb6c4d1 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 2 Jul 2024 07:52:21 -0400 Subject: [PATCH] fix: Comment resolution control visible to non-editors --- app/actions/definitions/comments.tsx | 8 ++++++-- app/scenes/Document/components/Comments.tsx | 10 +++------- app/stores/CommentsStore.ts | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/actions/definitions/comments.tsx b/app/actions/definitions/comments.tsx index 9a89393d2..0ed6206eb 100644 --- a/app/actions/definitions/comments.tsx +++ b/app/actions/definitions/comments.tsx @@ -46,7 +46,9 @@ export const resolveCommentFactory = ({ analyticsName: "Resolve thread", section: DocumentSection, icon: , - visible: () => stores.policies.abilities(comment.id).resolve, + visible: () => + stores.policies.abilities(comment.id).resolve && + stores.policies.abilities(comment.documentId).update, perform: async ({ t }) => { await comment.resolve(); @@ -72,7 +74,9 @@ export const unresolveCommentFactory = ({ analyticsName: "Unresolve thread", section: DocumentSection, icon: , - visible: () => stores.policies.abilities(comment.id).unresolve, + visible: () => + stores.policies.abilities(comment.id).unresolve && + stores.policies.abilities(comment.documentId).update, perform: async () => { await comment.unresolve(); diff --git a/app/scenes/Document/components/Comments.tsx b/app/scenes/Document/components/Comments.tsx index cf5675e37..31c5ca84e 100644 --- a/app/scenes/Document/components/Comments.tsx +++ b/app/scenes/Document/components/Comments.tsx @@ -12,7 +12,6 @@ import Empty from "~/components/Empty"; import Flex from "~/components/Flex"; import Scrollable from "~/components/Scrollable"; import Tooltip from "~/components/Tooltip"; -import useCurrentUser from "~/hooks/useCurrentUser"; import useFocusedComment from "~/hooks/useFocusedComment"; import useKeyDown from "~/hooks/useKeyDown"; import usePersistedState from "~/hooks/usePersistedState"; @@ -27,7 +26,6 @@ import Sidebar from "./SidebarLayout"; function Comments() { const { ui, comments, documents } = useStores(); const { t } = useTranslation(); - const user = useCurrentUser(); const location = useLocation(); const history = useHistory(); const match = useRouteMatch<{ documentSlug: string }>(); @@ -64,11 +62,9 @@ function Comments() { return null; } - const threads = ( - viewingResolved - ? resolvedThreads - : comments.unresolvedThreadsInDocument(document.id) - ).filter((thread) => thread.createdById === user.id); + const threads = viewingResolved + ? resolvedThreads + : comments.unresolvedThreadsInDocument(document.id); const hasComments = threads.length > 0; const toggleViewingResolved = () => { diff --git a/app/stores/CommentsStore.ts b/app/stores/CommentsStore.ts index 2ada84fe0..33b38ee9b 100644 --- a/app/stores/CommentsStore.ts +++ b/app/stores/CommentsStore.ts @@ -60,7 +60,7 @@ export default class CommentsStore extends Store { */ unresolvedThreadsInDocument(documentId: string): Comment[] { return this.threadsInDocument(documentId).filter( - (comment: Comment) => comment.isResolved === false + (comment: Comment) => comment.isResolved !== true ); }