feat: public projects, project deletion and sagas
Public projects:
- Project.isPublic (create/update, owners and admins). Anyone can read a
public project without a token: project, board, tickets, comments,
history, releases, activity, tracking and statistics, over GraphQL and
REST. Writes stay for members (401 anonymous, 403 outsiders).
- @OptionalAuth() / @ApiOptionalPireonAuth(): anonymous callers allowed,
invalid tokens still rejected. ReadAccess lets anonymous viewers read
public projects only; linked tickets are filtered by visibility.
- publicProjects (GraphQL) and GET /api/explore/projects (REST).
- Web: «Explorar» page, project pages open without a session (read-only
notice, sign-in hints), public badge, visibility switch in settings,
no realtime subscriptions without a session.
Project deletion:
- Owner only, confirming the key (deleteProject / DELETE
/api/projects/{project}?confirm=KEY). The key is freed; the read model
drops the project and members are notified (web goes home).
Sagas (run by the EventsBridge after projections, durable and ordered):
- ProjectDeletionSaga: project deleted → delete its tickets and releases;
ticket deleted → purge its comments and drop links from other tickets.
- ReleaseArchivedSaga: unfinished tickets leave an archived release.
- UserDeactivatedSaga: the Pireon webhook records UserDeactivatedEvent in
the event store (EventRecorder); the tracker unassigns that user's open
tickets as the system actor.
- Internal idempotent commands; domain refusals are logged and skipped,
concurrency conflicts retried. Affected streams come from the event store
(TrackerStreamsRepository).
Tests: domain lifecycle specs, saga specs run like the bridge, facade
tests, e2e for public access, cascade deletion, archived releases and
deactivation webhook. Docs, READMEs, schema.gql/openapi.json and Word/PDF
updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,13 @@ import { CreateReleaseCommandHandler } from './create-release.command-handler';
|
||||
import { UpdateReleaseCommandHandler } from './update-release.command-handler';
|
||||
import { PublishReleaseCommandHandler } from './publish-release.command-handler';
|
||||
import { ArchiveReleaseCommandHandler } from './archive-release.command-handler';
|
||||
import { DeleteProjectCommandHandler } from './delete-project.command-handler';
|
||||
import { DeleteIssueCommandHandler } from './delete-issue.command-handler';
|
||||
import { DeleteReleaseCommandHandler } from './delete-release.command-handler';
|
||||
import { PurgeCommentCommandHandler } from './purge-comment.command-handler';
|
||||
import { DropLinksToIssueCommandHandler } from './drop-links-to-issue.command-handler';
|
||||
import { DetachIssueFromReleaseCommandHandler } from './detach-issue-from-release.command-handler';
|
||||
import { UnassignIssueCommandHandler } from './unassign-issue.command-handler';
|
||||
|
||||
export const COMMAND_HANDLERS = [
|
||||
CreateProjectCommandHandler,
|
||||
@@ -40,4 +47,12 @@ export const COMMAND_HANDLERS = [
|
||||
UpdateReleaseCommandHandler,
|
||||
PublishReleaseCommandHandler,
|
||||
ArchiveReleaseCommandHandler,
|
||||
DeleteProjectCommandHandler,
|
||||
// Emitted by sagas only (cascades and reactions to other aggregates).
|
||||
DeleteIssueCommandHandler,
|
||||
DeleteReleaseCommandHandler,
|
||||
PurgeCommentCommandHandler,
|
||||
DropLinksToIssueCommandHandler,
|
||||
DetachIssueFromReleaseCommandHandler,
|
||||
UnassignIssueCommandHandler,
|
||||
];
|
||||
|
||||
@@ -19,6 +19,7 @@ export class CreateProjectCommandHandler
|
||||
key: command.key,
|
||||
name: command.name,
|
||||
description: command.description,
|
||||
isPublic: command.isPublic,
|
||||
ownerId: command.actorId,
|
||||
});
|
||||
await this.projectKeys.reserve(project.key, project.id);
|
||||
|
||||
@@ -7,6 +7,7 @@ export class CreateProjectCommand extends Command<CommandResult> {
|
||||
public readonly key: string,
|
||||
public readonly name: string,
|
||||
public readonly description?: string | null,
|
||||
public readonly isPublic = false,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { Issue } from '@task-stream/api/tracker/domain';
|
||||
import { DeleteIssueCommand } from './delete-issue.command';
|
||||
import { WriteAccess } from './write-access';
|
||||
|
||||
@CommandHandler(DeleteIssueCommand)
|
||||
export class DeleteIssueCommandHandler
|
||||
implements ICommandHandler<DeleteIssueCommand>
|
||||
{
|
||||
constructor(private readonly access: WriteAccess) {}
|
||||
|
||||
async execute(command: DeleteIssueCommand): Promise<void> {
|
||||
const issue = await this.access.live(command.issueId, Issue);
|
||||
if (!issue) return;
|
||||
issue.delete(command.actorId);
|
||||
await issue.commitAndWait();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Command } from '@nestjs/cqrs';
|
||||
|
||||
/** Saga only: deletes a ticket of a deleted project. */
|
||||
export class DeleteIssueCommand extends Command<void> {
|
||||
constructor(
|
||||
public readonly actorId: string,
|
||||
public readonly issueId: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { ProjectKeysRepository } from '../ports/project-keys.repository';
|
||||
import { CommandResult, ack } from './command-result';
|
||||
import { DeleteProjectCommand } from './delete-project.command';
|
||||
import { WriteAccess } from './write-access';
|
||||
|
||||
/** Tickets, comments and releases follow through ProjectDeletionSaga. */
|
||||
@CommandHandler(DeleteProjectCommand)
|
||||
export class DeleteProjectCommandHandler
|
||||
implements ICommandHandler<DeleteProjectCommand>
|
||||
{
|
||||
constructor(
|
||||
private readonly access: WriteAccess,
|
||||
private readonly projectKeys: ProjectKeysRepository,
|
||||
) {}
|
||||
|
||||
async execute(command: DeleteProjectCommand): Promise<CommandResult> {
|
||||
const project = await this.access.project(command.projectId);
|
||||
project.delete(command.actorId, command.confirmKey);
|
||||
await project.commitAndWait();
|
||||
// The key can be used again by a new project.
|
||||
await this.projectKeys.release(project.key, project.id);
|
||||
return ack(project);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Command } from '@nestjs/cqrs';
|
||||
import { CommandResult } from './command-result';
|
||||
|
||||
/** The owner deletes a project, typing its key to confirm. */
|
||||
export class DeleteProjectCommand extends Command<CommandResult> {
|
||||
constructor(
|
||||
public readonly actorId: string,
|
||||
public readonly projectId: string,
|
||||
public readonly confirmKey: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { Release } from '@task-stream/api/tracker/domain';
|
||||
import { DeleteReleaseCommand } from './delete-release.command';
|
||||
import { WriteAccess } from './write-access';
|
||||
|
||||
@CommandHandler(DeleteReleaseCommand)
|
||||
export class DeleteReleaseCommandHandler
|
||||
implements ICommandHandler<DeleteReleaseCommand>
|
||||
{
|
||||
constructor(private readonly access: WriteAccess) {}
|
||||
|
||||
async execute(command: DeleteReleaseCommand): Promise<void> {
|
||||
const release = await this.access.live(command.releaseId, Release);
|
||||
if (!release) return;
|
||||
release.delete(command.actorId);
|
||||
await release.commitAndWait();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Command } from '@nestjs/cqrs';
|
||||
|
||||
/** Saga only: deletes a release of a deleted project. */
|
||||
export class DeleteReleaseCommand extends Command<void> {
|
||||
constructor(
|
||||
public readonly actorId: string,
|
||||
public readonly releaseId: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { Issue, Project } from '@task-stream/api/tracker/domain';
|
||||
import { DetachIssueFromReleaseCommand } from './detach-issue-from-release.command';
|
||||
import { WriteAccess } from './write-access';
|
||||
|
||||
@CommandHandler(DetachIssueFromReleaseCommand)
|
||||
export class DetachIssueFromReleaseCommandHandler
|
||||
implements ICommandHandler<DetachIssueFromReleaseCommand>
|
||||
{
|
||||
constructor(private readonly access: WriteAccess) {}
|
||||
|
||||
async execute(command: DetachIssueFromReleaseCommand): Promise<void> {
|
||||
const issue = await this.access.live(command.issueId, Issue);
|
||||
if (!issue || issue.releaseId !== command.releaseId) return;
|
||||
const project = await this.access.live(issue.projectId, Project);
|
||||
// Finished tickets stay: they are what the release shipped.
|
||||
if (!project || project.workflow.isFinished(issue.status)) return;
|
||||
issue.setRelease(command.actorId, null);
|
||||
await issue.commitAndWait();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Command } from '@nestjs/cqrs';
|
||||
|
||||
/** Saga only: takes an unfinished ticket out of an archived release. */
|
||||
export class DetachIssueFromReleaseCommand extends Command<void> {
|
||||
constructor(
|
||||
public readonly actorId: string,
|
||||
public readonly issueId: string,
|
||||
public readonly releaseId: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { Issue, Project } from '@task-stream/api/tracker/domain';
|
||||
import { DropLinksToIssueCommand } from './drop-links-to-issue.command';
|
||||
import { WriteAccess } from './write-access';
|
||||
|
||||
@CommandHandler(DropLinksToIssueCommand)
|
||||
export class DropLinksToIssueCommandHandler
|
||||
implements ICommandHandler<DropLinksToIssueCommand>
|
||||
{
|
||||
constructor(private readonly access: WriteAccess) {}
|
||||
|
||||
async execute(command: DropLinksToIssueCommand): Promise<void> {
|
||||
const issue = await this.access.live(command.issueId, Issue);
|
||||
// Gone, or about to be (its project was deleted too): nothing to tidy.
|
||||
if (!issue || !(await this.access.live(issue.projectId, Project))) return;
|
||||
issue.unlinkAllTo(command.actorId, command.targetIssueId);
|
||||
await issue.commitAndWait();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Command } from '@nestjs/cqrs';
|
||||
|
||||
/** Saga only: removes the links of `issueId` that point to a deleted ticket. */
|
||||
export class DropLinksToIssueCommand extends Command<void> {
|
||||
constructor(
|
||||
public readonly actorId: string,
|
||||
public readonly issueId: string,
|
||||
public readonly targetIssueId: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -19,3 +19,10 @@ export * from './update-issue.command';
|
||||
export * from './update-project.command';
|
||||
export * from './update-project-settings.command';
|
||||
export * from './update-release.command';
|
||||
export * from './delete-project.command';
|
||||
export * from './delete-issue.command';
|
||||
export * from './delete-release.command';
|
||||
export * from './purge-comment.command';
|
||||
export * from './drop-links-to-issue.command';
|
||||
export * from './detach-issue-from-release.command';
|
||||
export * from './unassign-issue.command';
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { Comment } from '@task-stream/api/tracker/domain';
|
||||
import { PurgeCommentCommand } from './purge-comment.command';
|
||||
import { WriteAccess } from './write-access';
|
||||
|
||||
@CommandHandler(PurgeCommentCommand)
|
||||
export class PurgeCommentCommandHandler
|
||||
implements ICommandHandler<PurgeCommentCommand>
|
||||
{
|
||||
constructor(private readonly access: WriteAccess) {}
|
||||
|
||||
async execute(command: PurgeCommentCommand): Promise<void> {
|
||||
const comment = await this.access.live(command.commentId, Comment);
|
||||
if (!comment || comment.deleted) return;
|
||||
comment.delete(command.actorId, true);
|
||||
await comment.commitAndWait();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Command } from '@nestjs/cqrs';
|
||||
|
||||
/** Saga only: deletes a comment of a deleted ticket. */
|
||||
export class PurgeCommentCommand extends Command<void> {
|
||||
constructor(
|
||||
public readonly actorId: string,
|
||||
public readonly commentId: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
||||
import { Issue } from '@task-stream/api/tracker/domain';
|
||||
import { UnassignIssueCommand } from './unassign-issue.command';
|
||||
import { WriteAccess } from './write-access';
|
||||
|
||||
@CommandHandler(UnassignIssueCommand)
|
||||
export class UnassignIssueCommandHandler
|
||||
implements ICommandHandler<UnassignIssueCommand>
|
||||
{
|
||||
constructor(private readonly access: WriteAccess) {}
|
||||
|
||||
async execute(command: UnassignIssueCommand): Promise<void> {
|
||||
const issue = await this.access.live(command.issueId, Issue);
|
||||
// Someone may have reassigned it meanwhile: only undo our user's assignment.
|
||||
if (!issue || issue.assigneeId !== command.userId) return;
|
||||
issue.assign(command.actorId, null);
|
||||
await issue.commitAndWait();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Command } from '@nestjs/cqrs';
|
||||
|
||||
/** Saga only: unassigns a ticket if it is still assigned to `userId` (deactivated in Pireon). */
|
||||
export class UnassignIssueCommand extends Command<void> {
|
||||
constructor(
|
||||
public readonly actorId: string,
|
||||
public readonly issueId: string,
|
||||
public readonly userId: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,11 @@ export class UpdateProjectCommand extends Command<CommandResult> {
|
||||
constructor(
|
||||
public readonly actorId: string,
|
||||
public readonly projectId: string,
|
||||
public readonly changes: { name?: string; description?: string | null },
|
||||
public readonly changes: {
|
||||
name?: string;
|
||||
description?: string | null;
|
||||
isPublic?: boolean;
|
||||
},
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ import {
|
||||
} from '@task-stream/api/tracker/domain';
|
||||
import { UserDirectory } from '../ports/user-directory';
|
||||
|
||||
type Aggregate = VersionedAggregateRoot & {
|
||||
createdAt?: string;
|
||||
deleted?: boolean;
|
||||
};
|
||||
|
||||
/** Loads aggregates from the event store, failing with domain errors. */
|
||||
@Injectable()
|
||||
export class WriteAccess {
|
||||
@@ -78,13 +83,31 @@ export class WriteAccess {
|
||||
}
|
||||
}
|
||||
|
||||
private async load<T extends VersionedAggregateRoot & { createdAt?: string }>(
|
||||
/**
|
||||
* For saga commands, which must be idempotent: the aggregate, or null when
|
||||
* it does not exist or was deleted (nothing left to do).
|
||||
*/
|
||||
async live<T extends Aggregate>(
|
||||
id: string,
|
||||
AggregateCls: Type<T>,
|
||||
): Promise<T | null> {
|
||||
try {
|
||||
return await this.load(id, AggregateCls);
|
||||
} catch (error) {
|
||||
if (error instanceof NotFoundError) return null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private async load<T extends Aggregate>(
|
||||
id: string,
|
||||
AggregateCls: Type<T>,
|
||||
): Promise<T> {
|
||||
const aggregate = await this.rehydrator.rehydrate(id, AggregateCls);
|
||||
// The stream exists but belongs to another kind of aggregate.
|
||||
if (!aggregate.createdAt) throw new NotFoundError(AggregateCls.name, id);
|
||||
// The stream exists but belongs to another kind of aggregate, or the
|
||||
// aggregate was deleted: same answer, it is not there.
|
||||
if (!aggregate.createdAt || aggregate.deleted)
|
||||
throw new NotFoundError(AggregateCls.name, id);
|
||||
return aggregate;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user