Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
Let document owners delete comments they did not write (#7326)
Will Hutchinson1f6032ad3247
diff --git a/apps/web/src/features/block-md/comments/documentDiscussionSource.ts b/apps/web/src/features/block-md/comments/documentDiscussionSource.tsindex f7f50e6ef6..5dee77caa7 100644--- a/apps/web/src/features/block-md/comments/documentDiscussionSource.ts+++ b/apps/web/src/features/block-md/comments/documentDiscussionSource.ts@@ -107,6 +107,7 @@ export function createDocumentDiscussionSource(): DiscussionSource {return {threads,canEdit: permissions.canComment,+ canModerate: permissions.isOwner,currentUserId: userId,targetCommentId,targetRevision,diff --git a/apps/web/src/features/block-md/component/DocumentDiscussion.tsx b/apps/web/src/features/block-md/component/DocumentDiscussion.tsxindex 29bccde406..e629b8902a 100644--- a/apps/web/src/features/block-md/component/DocumentDiscussion.tsx+++ b/apps/web/src/features/block-md/component/DocumentDiscussion.tsx@@ -65,6 +65,7 @@ export function MessageDocumentDiscussion(props: {parent={parent()}targetId={discussionTarget()}canWrite={permissions.canComment()}+ canModerate={permissions.isOwner()}link={{ type: blockName, id }}label={props.label}floatingComposerOnTouch={props.floatingComposerOnTouch}diff --git a/apps/web/src/features/block-md/component/MessageDocumentDiscussion.test.tsx b/apps/web/src/features/block-md/component/MessageDocumentDiscussion.test.tsxindex 197292663b..37ab9e9803 100644--- a/apps/web/src/features/block-md/component/MessageDocumentDiscussion.test.tsx+++ b/apps/web/src/features/block-md/component/MessageDocumentDiscussion.test.tsx@@ -130,6 +130,7 @@ describe('mobile document discussion accessory behind the flag', () => {expect.objectContaining({parent: { type: 'document', id: 'document' },canWrite: true,+ canModerate: false,hideComposer: true,hideWhenEmpty: true,})diff --git a/apps/web/src/features/block-spreadsheet/SpreadsheetComments.test.tsx b/apps/web/src/features/block-spreadsheet/SpreadsheetComments.test.tsxindex 0ad4e91e2b..f5a6d0d6f3 100644--- a/apps/web/src/features/block-spreadsheet/SpreadsheetComments.test.tsx+++ b/apps/web/src/features/block-spreadsheet/SpreadsheetComments.test.tsx@@ -51,6 +51,7 @@ vi.mock('@solidjs/router', () => ({vi.mock('@core/context/user', () => ({ useUserId: () => () => 'me' }));vi.mock('@core/signal/permissions', () => ({useCanComment: () => () => mocks.canComment,+ useIsDocumentOwner: () => () => false,}));vi.mock('@core/util/url', () => ({ buildSimpleEntityUrl: () => 'link' }));vi.mock('@ui/components/Button', () => ({diff --git a/apps/web/src/features/block-spreadsheet/SpreadsheetComments.tsx b/apps/web/src/features/block-spreadsheet/SpreadsheetComments.tsxindex e85c0bf6c2..80cad282b2 100644--- a/apps/web/src/features/block-spreadsheet/SpreadsheetComments.tsx+++ b/apps/web/src/features/block-spreadsheet/SpreadsheetComments.tsx@@ -9,7 +9,7 @@ import {import { useUserId } from '@core/context/user';import { EntityDiscussion } from '@core/messages/EntityDiscussion';import { scrollToRenderedTarget } from '@core/messages/scroll-to-rendered-target';-import { useCanComment } from '@core/signal/permissions';+import { useCanComment, useIsDocumentOwner } from '@core/signal/permissions';import { buildSimpleEntityUrl } from '@core/util/url';import ChatIcon from '@phosphor/chat-circle.svg';import XIcon from '@phosphor/x.svg';@@ -75,6 +75,7 @@ export function SpreadsheetComments(props: {}) {const userId = useUserId();const canComment = useCanComment();+ const isOwner = useIsDocumentOwner();const params = useUrlParams(SPREADSHEET_COMMENT_PARAMS);const parent = () => ({ type: 'document' as const, id: props.documentId });const query = useMessageRootsQuery(parent);@@ -148,6 +149,7 @@ export function SpreadsheetComments(props: {<SpreadsheetCommentThreaddata={thread()}canWrite={canComment()}+ canModerate={isOwner()}targetId={target.rootId() === thread().id && clearedTarget() !== request()? target.messageId()@@ -473,6 +475,7 @@ export function SpreadsheetComments(props: {<EntityDiscussionparent={parent()}canWrite={canComment()}+ canModerate={isOwner()}link={{ type: 'spreadsheet', id: props.documentId }}targetId={discussionTarget()}label="Discussion"diff --git a/apps/web/src/features/block-spreadsheet/views/SpreadsheetCommentThread.tsx b/apps/web/src/features/block-spreadsheet/views/SpreadsheetCommentThread.tsxindex 6dd015fead..97e06b1175 100644--- a/apps/web/src/features/block-spreadsheet/views/SpreadsheetCommentThread.tsx+++ b/apps/web/src/features/block-spreadsheet/views/SpreadsheetCommentThread.tsx@@ -7,6 +7,7 @@ import { Show } from 'solid-js';export function SpreadsheetCommentThread(props: {data: MessageListItem;canWrite: boolean;+ canModerate?: boolean;targetId: string | null;onClearTarget: () => void;buildLink: (message: MessageData) => string;@@ -17,6 +18,7 @@ export function SpreadsheetCommentThread(props: {<MessageThreaddata={props.data}canWrite={props.canWrite}+ canModerate={props.canModerate}targetId={props.targetId}onClearTarget={props.onClearTarget}buildLink={props.buildLink}diff --git a/apps/web/src/features/channel/Channel/create-channel-message-actions.ts b/apps/web/src/features/channel/Channel/create-channel-message-actions.tsindex b6e4fabea8..7981183df8 100644--- a/apps/web/src/features/channel/Channel/create-channel-message-actions.ts+++ b/apps/web/src/features/channel/Channel/create-channel-message-actions.ts@@ -54,6 +54,11 @@ export type CreateChannelMessageActionsOptions = {parent: Accessor<MessageParent>;userId: Accessor<string | undefined>;canWrite?: (message: MessageData) => boolean;+ /**+ * Delete comments the caller did not write. Document owners set this; it+ * does not grant edit.+ */+ canModerate?: Accessor<boolean>;buildLink?: (message: MessageData) => string;deleteMessage: (input: DeleteMessageInput) => void;addReaction: (input: AddReactionInput) => void;@@ -106,7 +111,13 @@ export function createChannelMessageActions(const currentUserId = options.userId();const writable = options.canWrite?.(message) ?? true;const canEdit = writable && canEditMessage(message, currentUserId);- const canDelete = writable && canDeleteMessage(message, currentUserId);+ const canDelete =+ writable &&+ canDeleteMessage(+ message,+ currentUserId,+ options.canModerate?.() ?? false+ );const canReply = writable && canReplyToMessage(message);const isDeleted = !!message.deleted_at;diff --git a/apps/web/src/features/channel/Thread/tests/message-actions.test.ts b/apps/web/src/features/channel/Thread/tests/message-actions.test.tsindex de6c1bcc2e..f97c686e1d 100644--- a/apps/web/src/features/channel/Thread/tests/message-actions.test.ts+++ b/apps/web/src/features/channel/Thread/tests/message-actions.test.ts@@ -47,6 +47,30 @@ describe('message-actions helpers', () => {).toBe(false);});+ it('lets a document owner delete a comment they did not write', () => {+ expect(+ canDeleteMessage(+ { sender_id: 'user-2', deleted_at: null },+ 'user-1',+ true+ )+ ).toBe(true);+ expect(+ canDeleteMessage(+ { sender_id: 'user-2', deleted_at: null },+ 'user-1',+ false+ )+ ).toBe(false);+ expect(+ canDeleteMessage(+ { sender_id: 'user-2', deleted_at: '2026-02-25T00:00:00.000Z' },+ 'user-1',+ true+ )+ ).toBe(false);+ });+it('allows reply for non-deleted top-level messages and thread replies', () => {expect(canReplyToMessage({ thread_id: null, deleted_at: null })).toBe(true);expect(diff --git a/apps/web/src/features/channel/Thread/utils/message-actions.ts b/apps/web/src/features/channel/Thread/utils/message-actions.tsindex 2e5f1a1dac..42adcfee53 100644--- a/apps/web/src/features/channel/Thread/utils/message-actions.ts+++ b/apps/web/src/features/channel/Thread/utils/message-actions.ts@@ -42,11 +42,16 @@ export function canEditMessage(export function canDeleteMessage(message: Pick<ActionableMessage, 'sender_id' | 'deleted_at'>,- currentUserId: string | undefined+ currentUserId: string | undefined,+ /**+ * Document owners may delete comments they did not write. Channel members+ * leave this false; bot posts stay deletable without it.+ */+ canModerate = false): boolean {+ if (message.deleted_at) return false;return (- (isOwnMessage(message, currentUserId) || isBotMessage(message)) &&- !message.deleted_at+ canModerate || isOwnMessage(message, currentUserId) || isBotMessage(message));}diff --git a/apps/web/src/lib/core/comments/Thread.tsx b/apps/web/src/lib/core/comments/Thread.tsxindex 7e233292e5..71affbf5c6 100644--- a/apps/web/src/lib/core/comments/Thread.tsx+++ b/apps/web/src/lib/core/comments/Thread.tsx@@ -227,6 +227,7 @@ function MessageThreadBody(props: ThreadBodyProps) {parent={parent()}rootId={String(props.comment.threadId)}canWrite={context.canComment()}+ canModerate={context.isDocumentOwner()}monorailhideReplyInput={props.hideReplyInput}onEditingChange={context.setMessageEditing}diff --git a/apps/web/src/lib/core/comments/discussion/Discussion.tsx b/apps/web/src/lib/core/comments/discussion/Discussion.tsxindex 2bcb87e805..8519e8cc05 100644--- a/apps/web/src/lib/core/comments/discussion/Discussion.tsx+++ b/apps/web/src/lib/core/comments/discussion/Discussion.tsx@@ -273,7 +273,7 @@ export function DiscussionThreadView(props: {}: undefined,onDelete:- own && canEdit()+ (own || source.canModerate?.()) && canEdit()? async () => {try {await source.deleteComment(comment);diff --git a/apps/web/src/lib/core/comments/discussion/types.ts b/apps/web/src/lib/core/comments/discussion/types.tsindex 7b93878b22..dfbb15ac40 100644--- a/apps/web/src/lib/core/comments/discussion/types.ts+++ b/apps/web/src/lib/core/comments/discussion/types.ts@@ -44,6 +44,11 @@ export interface DiscussionSource {threads: Accessor<DiscussionThread[]>;/** Whether the current user may create/edit/delete here. */canEdit: Accessor<boolean>;+ /**+ * Delete comments the caller did not write. Document owners set this.+ * Editing stays limited to the author.+ */+ canModerate?: Accessor<boolean>;/** Current user id, for own-comment checks. */currentUserId: Accessor<string | undefined>;/** Comment id to highlight/scroll to (deep link), or null. */diff --git a/apps/web/src/lib/core/messages/EntityConversation.tsx b/apps/web/src/lib/core/messages/EntityConversation.tsxindex dd750ccaae..b24a937b6d 100644--- a/apps/web/src/lib/core/messages/EntityConversation.tsx+++ b/apps/web/src/lib/core/messages/EntityConversation.tsx@@ -56,6 +56,8 @@ export function EntityConversationComposer(props: {export function EntityConversation(props: {parent: MessageParent;canWrite: boolean;+ /** Delete comments the caller did not write. Document owners set this. */+ canModerate?: boolean;targetId?: string | null;/** The linked view stays around `targetId`, but its message is no longer highlighted. */targetCleared?: boolean;@@ -144,6 +146,7 @@ export function EntityConversation(props: {<MessageThreaddata={messagesById().get(id)!}canWrite={props.canWrite}+ canModerate={props.canModerate}targetId={target.rootId() === id && !props.targetCleared? target.messageId()diff --git a/apps/web/src/lib/core/messages/EntityDiscussion.tsx b/apps/web/src/lib/core/messages/EntityDiscussion.tsxindex 42a90bb80b..ed12667823 100644--- a/apps/web/src/lib/core/messages/EntityDiscussion.tsx+++ b/apps/web/src/lib/core/messages/EntityDiscussion.tsx@@ -49,6 +49,8 @@ function MobileMessageComposer(props: {export function EntityDiscussion(props: {parent: MessageParent;canWrite: boolean;+ /** Delete comments the caller did not write. Document owners set this. */+ canModerate?: boolean;/** Where copied message links open: the entity's block and id. */link: { type: string; id: string };label?: string;@@ -106,6 +108,7 @@ export function EntityDiscussion(props: {<EntityConversationparent={props.parent}canWrite={props.canWrite}+ canModerate={props.canModerate}targetId={commentId()}targetCleared={targetCleared()}onClearTarget={() => setClearedKey(scrollRequest()?.key)}diff --git a/apps/web/src/lib/core/messages/MessageThread.test.tsx b/apps/web/src/lib/core/messages/MessageThread.test.tsxindex 9098934384..e5e8e1d34f 100644--- a/apps/web/src/lib/core/messages/MessageThread.test.tsx+++ b/apps/web/src/lib/core/messages/MessageThread.test.tsx@@ -179,6 +179,36 @@ describe('document message touch actions', () => {});});+describe('document owner deletion', () => {+ const someoneElses = {+ ...message,+ sender_id: 'someone-else',+ state: { ...message.state, user_id: 'someone-else' },+ };++ it('offers delete, not edit, on a comment the owner did not write', () => {+ const view = render(() => (+ <MessageThread data={someoneElses} canWrite canModerate />+ ));+ openActions(view);+ expect(view.getByRole('button', { name: 'Delete' })).toBeTruthy();+ expect(view.queryByRole('button', { name: 'Edit' })).toBeNull();+ fireEvent.click(view.getByRole('button', { name: 'Delete' }));+ expect(mocks.remove).toHaveBeenCalledWith({+ parent: someoneElses.parent,+ messageID: 'root',+ threadID: undefined,+ });+ });++ it('hides delete on a comment the caller did not write', () => {+ const view = render(() => <MessageThread data={someoneElses} canWrite />);+ openActions(view);+ expect(view.queryByRole('button', { name: 'Delete' })).toBeNull();+ expect(view.queryByRole('button', { name: 'Edit' })).toBeNull();+ });+});+describe('document discussion controls', () => {// A document thread carries no thread-level controls of its own: resolve was// dead, and deleting a discussion is moving onto the root message's delete.diff --git a/apps/web/src/lib/core/messages/MessageThread.tsx b/apps/web/src/lib/core/messages/MessageThread.tsxindex d5a04d5391..7a918e057a 100644--- a/apps/web/src/lib/core/messages/MessageThread.tsx+++ b/apps/web/src/lib/core/messages/MessageThread.tsx@@ -40,6 +40,8 @@ export function threadListItem(thread: ThreadData): MessageListItem {type ThreadOptions = {canWrite: boolean;+ /** Delete comments the caller did not write. Document owners set this. */+ canModerate?: boolean;buildLink?: (message: MessageData) => string;targetId?: string | null;/** Releases the highlight on `targetId`; called when the linked message is clicked. */@@ -75,6 +77,7 @@ export function MessageThread(parent: () => props.data.parent,userId,canWrite: () => props.canWrite,+ canModerate: () => props.canModerate ?? false,buildLink: (message) =>message.parent?.type === 'channel'? buildMessageLink(message.parent.id, message.id, message.thread_id)diff --git a/crates/messages/src/domain/service.rs b/crates/messages/src/domain/service.rsindex ba94997a0a..7796dcfffb 100644--- a/crates/messages/src/domain/service.rs+++ b/crates/messages/src/domain/service.rs@@ -766,6 +766,11 @@ impl<R: MessageRepository, E: MessageEventPublisher> MessageService<R, E> {}}+/// Parent moderation beyond authorship.+///+/// A document owner may delete any comment on that document, including a+/// discussion they did not start. Channel admins and owners may moderate+/// channel messages the same way. Edit and comment access do not.fn can_moderate(permission: &EntityPermission) -> bool {permission.satisfies::<OwnerAccessLevel>() || permission.satisfies::<AdminParticipantRole>()}diff --git a/crates/messages/src/domain/service/test.rs b/crates/messages/src/domain/service/test.rsindex 569ccefbce..8bf497e518 100644--- a/crates/messages/src/domain/service/test.rs+++ b/crates/messages/src/domain/service/test.rs@@ -458,6 +458,32 @@ async fn a_reply_author_can_delete_their_reply_but_not_the_root_above_it() {));}+#[tokio::test]+async fn document_owner_can_delete_another_authors_reply() {+ let mut repo = fixture();+ repo.replies = vec![reply_from(&repo.message, 7, "macro|[email protected]")];+ let service = MessageService::new(repo.clone(), Events::default());+ let denied = service+ .delete(+ access("macro|[email protected]", "doc", AccessLevel::Edit),+ repo.replies[0].id,+ None,+ )+ .await;+ assert!(matches!(denied, Err(MessageError::Forbidden)));+ assert!(repo.deletes.lock().unwrap().is_empty());+ service+ .delete(+ access("macro|[email protected]", "doc", AccessLevel::Owner),+ repo.replies[0].id,+ None,+ )+ .await+ .unwrap();+ assert_eq!(*repo.deletes.lock().unwrap(), vec![repo.replies[0].id]);+ assert!(repo.thread_deletes.lock().unwrap().is_empty());+}+#[tokio::test]async fn other_commenter_cannot_delete_but_parent_owner_can_moderate() {let repo = fixture();