Merge pull request #23673 from overleaf/em-reviewer-role-delete-replies

Let reviewers delete their own comments

GitOrigin-RevId: bd5341a917a3e886dc573d7e42d12343da6700cd
This commit is contained in:
Eric Mc Sween
2025-02-19 09:05:21 +00:00
committed by Copybot
parent a34ebd3c7e
commit 79bb2e3d40
6 changed files with 82 additions and 2 deletions
@@ -12,6 +12,7 @@ import {
ThreadId,
} from '../../../../../types/review-panel/review-panel'
import { useModalsContext } from '@/features/ide-react/context/modals-context'
import { usePermissionsContext } from '@/features/ide-react/context/permissions-context'
import { useTranslation } from 'react-i18next'
import { debugConsole } from '@/utils/debugging'
@@ -29,11 +30,13 @@ export const ReviewPanelComment = memo<{
resolveThread,
editMessage,
deleteMessage,
deleteOwnMessage,
deleteThread,
addMessage,
} = useThreadsActionsContext()
const { showGenericMessageModal } = useModalsContext()
const { t } = useTranslation()
const permissions = usePermissionsContext()
const [processing, setProcessing] = useState(false)
@@ -74,7 +77,13 @@ export const ReviewPanelComment = memo<{
async (commentId: CommentId) => {
setProcessing(true)
try {
await deleteMessage(comment.op.t, commentId)
if (permissions.write) {
// Owners and editors can delete any message
await deleteMessage(comment.op.t, commentId)
} else {
// Reviewers can only delete their own messages
await deleteOwnMessage(comment.op.t, commentId)
}
} catch (err) {
debugConsole.error(err)
showGenericMessageModal(
@@ -85,7 +94,14 @@ export const ReviewPanelComment = memo<{
setProcessing(false)
}
},
[comment.op.t, deleteMessage, showGenericMessageModal, t]
[
comment.op.t,
deleteMessage,
deleteOwnMessage,
showGenericMessageModal,
t,
permissions.write,
]
)
const handleDeleteThread = useCallback(
@@ -38,6 +38,7 @@ type ThreadsActions = {
content: string
) => Promise<void>
deleteMessage: (threadId: ThreadId, commentId: CommentId) => Promise<void>
deleteOwnMessage: (threadId: ThreadId, commentId: CommentId) => Promise<void>
}
const ThreadsActionsContext = createContext<ThreadsActions | undefined>(
@@ -288,6 +289,11 @@ export const ThreadsProvider: FC = ({ children }) => {
`/project/${projectId}/thread/${threadId}/messages/${commentId}`
)
},
async deleteOwnMessage(threadId: ThreadId, commentId: CommentId) {
await deleteJSON(
`/project/${projectId}/thread/${threadId}/own-messages/${commentId}`
)
},
}),
[currentDocument, projectId]
)