feat: comments marked as decisions, on top of the ticket and searchable
Whoever can change the ticket flags a comment as a decision (new event
CommentDecisionMarkedEvent on the comment). The ticket page lists its
decisions above the description, with a link to the comment in the
conversation (`?comment=<id>` scrolls to it and points at it), and the
search palette finds them by their text across my projects.
API: markDecision / PUT-DELETE /api/comments/{id}/decision; Issue.decisions
and GET /api/issues/{issue}/decisions; decisions(projectId?, search) and
GET /api/projects/{project}/decisions, GET /api/me/decisions. MCP:
mark_decision, search_decisions, and get_issue includes them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ReactToCommentCommandHandler } from './react-to-comment.command-handler';
|
||||
import { MarkDecisionCommandHandler } from './mark-decision.command-handler';
|
||||
import { VoteIssueCommandHandler } from './vote-issue.command-handler';
|
||||
import { CreateProjectCommandHandler } from './create-project.command-handler';
|
||||
import { UpdateProjectCommandHandler } from './update-project.command-handler';
|
||||
@@ -46,6 +47,7 @@ import {
|
||||
export const COMMAND_HANDLERS = [
|
||||
VoteIssueCommandHandler,
|
||||
ReactToCommentCommandHandler,
|
||||
MarkDecisionCommandHandler,
|
||||
CreateProjectCommandHandler,
|
||||
UpdateProjectCommandHandler,
|
||||
UpdateProjectSettingsCommandHandler,
|
||||
|
||||
@@ -77,6 +77,7 @@ import { UserDirectory } from '../ports/user-directory';
|
||||
import { AttachmentStorage } from '../ports/attachment-storage';
|
||||
import { AddCommentCommand } from './add-comment.command';
|
||||
import { ReactToCommentCommand } from './react-to-comment.command';
|
||||
import { MarkDecisionCommand } from './mark-decision.command';
|
||||
import { UpdateProjectCommand } from './update-project.command';
|
||||
import { VoteIssueCommand } from './vote-issue.command';
|
||||
import { AddProjectMemberCommand } from './add-project-member.command';
|
||||
@@ -916,6 +917,32 @@ describe('tracker commands (event sourced)', () => {
|
||||
).rejects.toThrow(ForbiddenError);
|
||||
});
|
||||
|
||||
it('lets the team mark a comment as a decision, and only the team', async () => {
|
||||
const { run, rehydrator } = await setup();
|
||||
const projectId = await projectWithTeam(run);
|
||||
const issue = await run(
|
||||
new CreateIssueCommand('dev', projectId, IssueType.TASK, 'Caché', {}),
|
||||
);
|
||||
const comment = await run(
|
||||
new AddCommentCommand('qa', issue.id, 'Usamos Redis'),
|
||||
);
|
||||
await run(new MarkDecisionCommand('dev', comment.id, true));
|
||||
// Twice is still once.
|
||||
const again = await run(new MarkDecisionCommand('dev', comment.id, true));
|
||||
expect(again.version).toBe(2);
|
||||
expect((await rehydrator.rehydrate(comment.id, Comment)).decision).toBe(
|
||||
true,
|
||||
);
|
||||
// A viewer reads the decisions but does not make them.
|
||||
await expect(
|
||||
run(new MarkDecisionCommand('pm', comment.id, false)),
|
||||
).rejects.toThrow(ForbiddenError);
|
||||
await run(new MarkDecisionCommand('owner', comment.id, false));
|
||||
expect((await rehydrator.rehydrate(comment.id, Comment)).decision).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('takes votes from members, and from anyone once it is public', async () => {
|
||||
const { run, rehydrator } = await setup();
|
||||
const projectId = await projectWithTeam(run);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { CommandResult, ack } from './command-result';
|
||||
import { MarkDecisionCommand } from './mark-decision.command';
|
||||
import { WriteAccess } from './write-access';
|
||||
|
||||
/** The team decides: whoever can change the ticket marks its decisions. */
|
||||
@CommandHandler(MarkDecisionCommand)
|
||||
export class MarkDecisionCommandHandler
|
||||
implements ICommandHandler<MarkDecisionCommand>
|
||||
{
|
||||
constructor(private readonly access: WriteAccess) {}
|
||||
|
||||
async execute(command: MarkDecisionCommand): Promise<CommandResult> {
|
||||
const comment = await this.access.comment(command.commentId);
|
||||
await this.access.issueForContributor(comment.issueId, command.actorId);
|
||||
comment.markDecision(command.actorId, command.on);
|
||||
await comment.commitAndWait();
|
||||
return ack(comment);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Command } from '@nestjs/cqrs';
|
||||
import { CommandResult } from './command-result';
|
||||
|
||||
/** Marks a comment as a decision of its ticket (`on`) or unmarks it. */
|
||||
export class MarkDecisionCommand extends Command<CommandResult> {
|
||||
constructor(
|
||||
public readonly actorId: string,
|
||||
public readonly commentId: string,
|
||||
public readonly on: boolean,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,22 @@
|
||||
import { CommandRunner } from '@task-stream/api/shared/application';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { QueryBus } from '@nestjs/cqrs';
|
||||
import { CommentReadModel } from '@task-stream/api/tracker/domain';
|
||||
import {
|
||||
CommentReadModel,
|
||||
DecisionReadModel,
|
||||
} from '@task-stream/api/tracker/domain';
|
||||
import { AddCommentCommand } from './commands/add-comment.command';
|
||||
import { CommandResult } from './commands/command-result';
|
||||
import { DeleteCommentCommand } from './commands/delete-comment.command';
|
||||
import { EditCommentCommand } from './commands/edit-comment.command';
|
||||
import { ReactToCommentCommand } from './commands/react-to-comment.command';
|
||||
import { MarkDecisionCommand } from './commands/mark-decision.command';
|
||||
import { Page } from './ports/find-issues.repository';
|
||||
import { GetCommentsQuery } from './queries/get-comments.query';
|
||||
import {
|
||||
GetIssueDecisionsQuery,
|
||||
SearchDecisionsQuery,
|
||||
} from './queries/decisions.query';
|
||||
|
||||
@Injectable()
|
||||
export class CommentsService {
|
||||
@@ -50,6 +58,35 @@ export class CommentsService {
|
||||
);
|
||||
}
|
||||
|
||||
/** Marks it as a decision of its ticket (`on`) or unmarks it: the team does. */
|
||||
markDecision(
|
||||
actorId: string,
|
||||
commentId: string,
|
||||
on: boolean,
|
||||
): Promise<CommandResult> {
|
||||
return this.commands.execute(
|
||||
new MarkDecisionCommand(actorId, commentId, on),
|
||||
);
|
||||
}
|
||||
|
||||
/** A ticket's decisions, oldest first. */
|
||||
decisions(
|
||||
viewerId: string | null,
|
||||
issueId: string,
|
||||
): Promise<CommentReadModel[]> {
|
||||
return this.queryBus.execute(new GetIssueDecisionsQuery(viewerId, issueId));
|
||||
}
|
||||
|
||||
/** Decisions by their text: of a project, or of all mine without one. */
|
||||
searchDecisions(
|
||||
viewerId: string | null,
|
||||
filter: { projectId?: string; search?: string; limit?: number },
|
||||
): Promise<DecisionReadModel[]> {
|
||||
return this.queryBus.execute(
|
||||
new SearchDecisionsQuery(viewerId, { limit: 20, ...filter }),
|
||||
);
|
||||
}
|
||||
|
||||
delete(actorId: string, commentId: string): Promise<CommandResult> {
|
||||
return this.commands.execute(new DeleteCommentCommand(actorId, commentId));
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ export class CommentAddedEventHandler
|
||||
replyTo: comment.replyTo ?? null,
|
||||
deleted: false,
|
||||
reactions: [],
|
||||
decision: false,
|
||||
decidedBy: null,
|
||||
decidedAt: null,
|
||||
createdAt: comment.createdAt,
|
||||
editedAt: null,
|
||||
version: versionOf(event),
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||
import { CommentDecisionMarkedEvent } from '@task-stream/api/tracker/domain';
|
||||
import { UpsertMaterializedCommentRepository } from '../ports/upsert-materialized-comment.repository';
|
||||
import { UserDirectory } from '../ports/user-directory';
|
||||
import { ReadModelNotifier, versionOf } from './read-model-notifier';
|
||||
|
||||
@EventsHandler(CommentDecisionMarkedEvent)
|
||||
export class CommentDecisionMarkedEventHandler
|
||||
implements IEventHandler<CommentDecisionMarkedEvent>
|
||||
{
|
||||
constructor(
|
||||
private readonly upsertMaterializedCommentRepository: UpsertMaterializedCommentRepository,
|
||||
private readonly users: UserDirectory,
|
||||
private readonly notifier: ReadModelNotifier,
|
||||
) {}
|
||||
|
||||
async handle(event: CommentDecisionMarkedEvent) {
|
||||
const refs = await this.users.refs([event.actorId]);
|
||||
await this.upsertMaterializedCommentRepository.upsert({
|
||||
id: event.aggregateId,
|
||||
decision: event.decision,
|
||||
decidedBy: event.decision ? refs.of(event.actorId) : null,
|
||||
decidedAt: event.decision ? event.occurredAt : null,
|
||||
version: versionOf(event),
|
||||
});
|
||||
await this.notifier.comment(event.aggregateId, event.issueId, event);
|
||||
// The ticket shows its decisions on top: its page reloads them.
|
||||
await this.notifier.issue(event.issueId, event);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { CommentAddedEventHandler } from './comment-added.event-handler';
|
||||
import { CommentDeletedEventHandler } from './comment-deleted.event-handler';
|
||||
import { CommentEditedEventHandler } from './comment-edited.event-handler';
|
||||
import { CommentReactedEventHandler } from './comment-reacted.event-handler';
|
||||
import { CommentDecisionMarkedEventHandler } from './comment-decision-marked.event-handler';
|
||||
import { IssueVotedEventHandler } from './issue-voted.event-handler';
|
||||
import { IssueAssignedEventHandler } from './issue-assigned.event-handler';
|
||||
import { IssueCreatedEventHandler } from './issue-created.event-handler';
|
||||
@@ -50,6 +51,7 @@ export const EVENT_HANDLERS = [
|
||||
CommentDeletedEventHandler,
|
||||
CommentEditedEventHandler,
|
||||
CommentReactedEventHandler,
|
||||
CommentDecisionMarkedEventHandler,
|
||||
IssueVotedEventHandler,
|
||||
IssueAssignedEventHandler,
|
||||
IssueCreatedEventHandler,
|
||||
|
||||
@@ -11,4 +11,14 @@ export abstract class FindCommentsRepository {
|
||||
/** Comments still standing (deleted ones kept for their replies do not count). */
|
||||
abstract countByIssue(issueId: string): Promise<number>;
|
||||
abstract countReplies(commentId: string): Promise<number>;
|
||||
/**
|
||||
* Comments marked as decisions (not deleted): of one ticket, or of some
|
||||
* projects, oldest first for a ticket and most recent first otherwise.
|
||||
*/
|
||||
abstract findDecisions(filter: {
|
||||
issueId?: string;
|
||||
projectIds?: string[];
|
||||
search?: string;
|
||||
limit: number;
|
||||
}): Promise<CommentReadModel[]>;
|
||||
}
|
||||
|
||||
112
libs/api/tracker/application/src/lib/queries/decisions.query.ts
Normal file
112
libs/api/tracker/application/src/lib/queries/decisions.query.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { IQueryHandler, Query, QueryHandler } from '@nestjs/cqrs';
|
||||
import {
|
||||
CommentReadModel,
|
||||
DecisionReadModel,
|
||||
} from '@task-stream/api/tracker/domain';
|
||||
import { FindCommentsRepository } from '../ports/find-comments.repository';
|
||||
import { FindIssuesRepository } from '../ports/find-issues.repository';
|
||||
import { FindProjectsRepository } from '../ports/find-projects.repository';
|
||||
import { ReadAccess } from './read-access';
|
||||
|
||||
/** The decisions of a ticket, oldest first (shown above its conversation). */
|
||||
export class GetIssueDecisionsQuery extends Query<CommentReadModel[]> {
|
||||
constructor(
|
||||
/** Null: anonymous (public projects only). */
|
||||
public readonly viewerId: string | null,
|
||||
public readonly issueId: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decisions by their text, most recently decided first: of one project, or
|
||||
* (without one) of every project the viewer belongs to.
|
||||
*/
|
||||
export class SearchDecisionsQuery extends Query<DecisionReadModel[]> {
|
||||
constructor(
|
||||
public readonly viewerId: string | null,
|
||||
public readonly filter: {
|
||||
projectId?: string;
|
||||
search?: string;
|
||||
limit: number;
|
||||
},
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
@QueryHandler(GetIssueDecisionsQuery)
|
||||
export class GetIssueDecisionsQueryHandler
|
||||
implements IQueryHandler<GetIssueDecisionsQuery, CommentReadModel[]>
|
||||
{
|
||||
constructor(
|
||||
private readonly findIssues: FindIssuesRepository,
|
||||
private readonly findComments: FindCommentsRepository,
|
||||
private readonly access: ReadAccess,
|
||||
) {}
|
||||
|
||||
async execute(query: GetIssueDecisionsQuery): Promise<CommentReadModel[]> {
|
||||
const issue = this.access.assertFound(
|
||||
await this.findIssues.findById(query.issueId),
|
||||
'Issue',
|
||||
query.issueId,
|
||||
);
|
||||
await this.access.assertCanViewIssue(issue, query.viewerId);
|
||||
return this.findComments.findDecisions({ issueId: issue.id, limit: 50 });
|
||||
}
|
||||
}
|
||||
|
||||
@QueryHandler(SearchDecisionsQuery)
|
||||
export class SearchDecisionsQueryHandler
|
||||
implements IQueryHandler<SearchDecisionsQuery, DecisionReadModel[]>
|
||||
{
|
||||
constructor(
|
||||
private readonly findProjects: FindProjectsRepository,
|
||||
private readonly findIssues: FindIssuesRepository,
|
||||
private readonly findComments: FindCommentsRepository,
|
||||
private readonly access: ReadAccess,
|
||||
) {}
|
||||
|
||||
async execute(query: SearchDecisionsQuery): Promise<DecisionReadModel[]> {
|
||||
const { filter, viewerId } = query;
|
||||
let projectIds: string[];
|
||||
if (filter.projectId) {
|
||||
await this.access.assertCanView(filter.projectId, viewerId);
|
||||
projectIds = [filter.projectId];
|
||||
} else {
|
||||
if (!viewerId) return [];
|
||||
projectIds = (await this.findProjects.findByMember(viewerId)).map(
|
||||
(p) => p.id,
|
||||
);
|
||||
}
|
||||
if (projectIds.length === 0) return [];
|
||||
const limit = Math.min(filter.limit, 100);
|
||||
// Read a few more: some may sit in the trash or, for a guest, in
|
||||
// tickets they do not take part in.
|
||||
const comments = await this.findComments.findDecisions({
|
||||
projectIds,
|
||||
search: filter.search?.trim().slice(0, 200) || undefined,
|
||||
limit: limit * 2,
|
||||
});
|
||||
const issues = new Map(
|
||||
(
|
||||
await this.findIssues.findByIds([
|
||||
...new Set(comments.map((c) => c.issueId)),
|
||||
])
|
||||
).map((issue) => [issue.id, issue]),
|
||||
);
|
||||
const found: DecisionReadModel[] = [];
|
||||
for (const comment of comments) {
|
||||
const issue = issues.get(comment.issueId);
|
||||
if (!issue || issue.trashedAt) continue;
|
||||
if (!(await this.access.canViewIssue(issue, viewerId))) continue;
|
||||
found.push({
|
||||
comment,
|
||||
issue: { id: issue.id, key: issue.key, title: issue.title },
|
||||
});
|
||||
if (found.length === limit) break;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,10 @@ import { GetReleaseNotesDraftQueryHandler } from './get-release-notes-draft.quer
|
||||
import { GetTrashQueryHandler } from './get-trash.query';
|
||||
import { GetShowcaseQueryHandler } from './get-showcase.query';
|
||||
import { SearchMyIssuesQueryHandler } from './search-my-issues.query-handler';
|
||||
import {
|
||||
GetIssueDecisionsQueryHandler,
|
||||
SearchDecisionsQueryHandler,
|
||||
} from './decisions.query';
|
||||
|
||||
export const QUERY_HANDLERS = [
|
||||
GetPublicProjectsQueryHandler,
|
||||
@@ -33,6 +37,8 @@ export const QUERY_HANDLERS = [
|
||||
GetActivityQueryHandler,
|
||||
GetBoardQueryHandler,
|
||||
GetCommentsQueryHandler,
|
||||
GetIssueDecisionsQueryHandler,
|
||||
SearchDecisionsQueryHandler,
|
||||
GetIssueQueryHandler,
|
||||
GetIssuesByIdsQueryHandler,
|
||||
GetMyProjectsQueryHandler,
|
||||
|
||||
Reference in New Issue
Block a user