Skip to content
17 linesCodeBlameRaw
1import type { Comment } from "@g1t/contracts";
2
3/**
4 * Whether the viewer may edit or delete a comment: its author may, and so
5 * may someone with the Maintain role or higher (`canModerate`). Notes of
6 * what happened are nobody's to change, and a review's verdict stays, so a
7 * review can be edited but not deleted. The work service decides; this
8 * only says which buttons to show.
9 */
10export function mayChangeComment(
11 comment: Pick<Comment, "kind" | "verdict"> & { author: { id: string } },
12 viewerId: string | null | undefined,
13 canModerate: boolean,
14): { edit: boolean; delete: boolean } {
15 const allowed = comment.kind === "comment" && viewerId != null && (comment.author.id === viewerId || canModerate);
16 return { edit: allowed, delete: allowed && comment.verdict == null };
17}