All checks were successful
CD / Build and push images (push) Successful in 2m54s
CI / Lint, typecheck, test (push) Successful in 2m25s
CI / Auth e2e pack (push) Successful in 2m58s
CI / Build container images (push) Has been skipped
CD / Deploy to Test (push) Successful in 9s
CD / Smoke tests against Test (push) Successful in 1m12s
CD / Promote to Int (push) Successful in 12s
Every route now declares its access rule explicitly and is enforced through the shared resolution algorithm (permissions.md): - PermissionGuard + decorators (@RequiresPondRole, @RequiresPagePermission, @RequiresAttachmentPermission, @AuthenticatedOnly) applied to every route; a route-enumeration test proves full coverage alongside @Public()/Site-Admin-guarded routes. - 404/403 policy (documented in README conventions): denied reads answer 404 (existence hiding), denied writes on readable things answer 403; trash views need write capability (ADR 0013). - PermissionService resolves page/pond questions via the shared resolver, with an in-process pond-context cache (grants + label parents) that is invalidated on every grant/label-tree change and TTL-bounded as a multi-process safety net. Grant changes also fire pond_access_changed for collab revalidation (#39/#53). - shared: pond-scope resolution (hasPondRole, canSeePond) next to the page resolver; grant wire schemas + GrantView. - Owner Pond-Admin grants: migration backfill for all existing ponds, created transactionally with every new pond (shared + personal + seed). - Grant CRUD under /ponds/:id/grants (pond_admin-gated) with structural and referential validation, last-admin protection, audit logs. - InterimAccessService deleted; page lists, search, backlinks, phantom links, and trash listings are filtered per page through the resolver; collab tokens are now truly ro for readers. - Fixture-matrix e2e (reader/editor/pond admin/foreign, label-deny, authenticated-subject, revoke-then-immediate-deny cache test). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PGdhRiwU1WRL4XxJfZYipY
62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
import { Body, Controller, Get, Param, Post, Req } from '@nestjs/common';
|
|
import {
|
|
CreateVersionInput,
|
|
PageVersionContentView,
|
|
PageVersionView,
|
|
createVersionInputSchema,
|
|
} from '@dorfteich/shared';
|
|
|
|
import { AuthedRequest } from '../auth/auth.guard';
|
|
import { ZodValidationPipe } from '../common/zod-validation.pipe';
|
|
import { RequiresPagePermission } from '../permissions/permission.decorators';
|
|
import { VersionsService } from './versions.service';
|
|
|
|
/**
|
|
* Page version history (issue #41/#42, ADR 0013). Every route requires write
|
|
* access to the page — viewing history is gated like editing (permissions.md).
|
|
*/
|
|
@Controller()
|
|
export class VersionsController {
|
|
constructor(private readonly versions: VersionsService) {}
|
|
|
|
/** List the page's versions, newest first. */
|
|
@Get('pages/:id/versions')
|
|
@RequiresPagePermission('write', { idParam: 'id' }) // history = write (ADR 0013)
|
|
async list(@Param('id') id: string, @Req() request: AuthedRequest): Promise<PageVersionView[]> {
|
|
return this.versions.list(request.user!, id);
|
|
}
|
|
|
|
/** A single version rendered read-only, with Markdown for diffing. */
|
|
@Get('pages/:id/versions/:versionId')
|
|
@RequiresPagePermission('write', { idParam: 'id' })
|
|
async getContent(
|
|
@Param('id') id: string,
|
|
@Param('versionId') versionId: string,
|
|
@Req() request: AuthedRequest,
|
|
): Promise<PageVersionContentView> {
|
|
return this.versions.getContent(request.user!, id, versionId);
|
|
}
|
|
|
|
/** Create a named version of the page. */
|
|
@Post('pages/:id/versions')
|
|
@RequiresPagePermission('write', { idParam: 'id' })
|
|
async createNamed(
|
|
@Param('id') id: string,
|
|
@Body(new ZodValidationPipe(createVersionInputSchema)) input: CreateVersionInput,
|
|
@Req() request: AuthedRequest,
|
|
): Promise<PageVersionView> {
|
|
return this.versions.createNamed(request.user!, id, input);
|
|
}
|
|
|
|
/** Restore the page to an earlier version (creates a pre-restore snapshot). */
|
|
@Post('pages/:id/versions/:versionId/restore')
|
|
@RequiresPagePermission('write', { idParam: 'id' })
|
|
async restore(
|
|
@Param('id') id: string,
|
|
@Param('versionId') versionId: string,
|
|
@Req() request: AuthedRequest,
|
|
): Promise<PageVersionView> {
|
|
return this.versions.restore(request.user!, id, versionId);
|
|
}
|
|
}
|