commit
This commit is contained in:
187
docs/implementation/task-p.6-implementation.md
Normal file
187
docs/implementation/task-p.6-implementation.md
Normal file
@@ -0,0 +1,187 @@
|
||||
# Task P.6 Implementation Report
|
||||
|
||||
## Scope
|
||||
|
||||
This report documents implementation completed for
|
||||
[task-p.6.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/plans/task-p.6.md).
|
||||
|
||||
Focus of this round:
|
||||
|
||||
- build the reusable Document Library foundation
|
||||
- add storage-backed PDF version management for static append documents
|
||||
- add CRM settings management UI and route handlers
|
||||
- wire permissions and audit logging
|
||||
- strengthen adoption with realistic seed coverage
|
||||
|
||||
---
|
||||
|
||||
## Review Inputs
|
||||
|
||||
Reviewed before implementation:
|
||||
|
||||
- [AGENTS.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/AGENTS.md)
|
||||
- [docs/standards/project-foundations.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/standards/project-foundations.md)
|
||||
- [docs/standards/architecture-rules.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/standards/architecture-rules.md)
|
||||
- [docs/standards/task-catalog.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/standards/task-catalog.md)
|
||||
- [docs/security/crm-authorization-boundaries.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/security/crm-authorization-boundaries.md)
|
||||
- [docs/adr/0008-attachment-storage-strategy.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/adr/0008-attachment-storage-strategy.md)
|
||||
- [docs/adr/0009-approved-document-storage-lifecycle.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/adr/0009-approved-document-storage-lifecycle.md)
|
||||
- [docs/adr/0013-pdf-visual-parity-strategy.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/adr/0013-pdf-visual-parity-strategy.md)
|
||||
- [docs/implementation/task-i-storage-artifact-lifecycle.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/implementation/task-i-storage-artifact-lifecycle.md)
|
||||
- [docs/implementation/task-p.5-implementation.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/implementation/task-p.5-implementation.md)
|
||||
- [docs/implementation/task-p.5.1-implementation.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/docs/implementation/task-p.5.1-implementation.md)
|
||||
|
||||
---
|
||||
|
||||
## Implementation Summary
|
||||
|
||||
### 1. Document Library schema foundation
|
||||
|
||||
Added dedicated schema and migration support for reusable static document families
|
||||
and their uploaded PDF versions:
|
||||
|
||||
- [src/db/schema.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/db/schema.ts)
|
||||
- [drizzle/0007_document_library_foundation.sql](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/drizzle/0007_document_library_foundation.sql)
|
||||
|
||||
Core model split:
|
||||
|
||||
- `crm_document_libraries` for logical document families
|
||||
- `crm_document_library_versions` for uploaded PDF versions and lifecycle state
|
||||
|
||||
Database constraints added:
|
||||
|
||||
- unique library code per organization
|
||||
- unique version per library
|
||||
- single active version per library through partial unique index
|
||||
|
||||
### 2. Server foundation and lifecycle rules
|
||||
|
||||
Added reusable server-side foundation under
|
||||
[src/features/foundation/document-library](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/foundation/document-library):
|
||||
|
||||
- `types.ts`
|
||||
- `server/validation.ts`
|
||||
- `server/service.ts`
|
||||
- `service.ts`
|
||||
- `queries.ts`
|
||||
- `mutations.ts`
|
||||
|
||||
Behavior implemented:
|
||||
|
||||
- library create and metadata update
|
||||
- PDF upload with MIME, size, checksum, readability, and page-count validation
|
||||
- draft -> published -> active -> archived lifecycle enforcement
|
||||
- draft deletion guard
|
||||
- preview and download for explicit version or active version
|
||||
- audit logging for create, update, upload, publish, activate, archive, preview, and download actions
|
||||
|
||||
### 3. CRM settings routes and UI
|
||||
|
||||
Added management route handlers under
|
||||
[src/app/api/crm/settings/document-library](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library)
|
||||
and a management page at
|
||||
[src/app/dashboard/crm/settings/document-library/page.tsx](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/dashboard/crm/settings/document-library/page.tsx).
|
||||
|
||||
The settings UI now supports:
|
||||
|
||||
- filtering by type, brand, language, and product type
|
||||
- version history inspection
|
||||
- PDF upload
|
||||
- publish, activate, archive, preview, and download actions
|
||||
|
||||
### 4. RBAC integration
|
||||
|
||||
Extended CRM permissions in:
|
||||
|
||||
- [src/lib/auth/rbac.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/lib/auth/rbac.ts)
|
||||
- [src/config/nav-config.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/config/nav-config.ts)
|
||||
|
||||
Permissions added:
|
||||
|
||||
- `documentLibraryRead`
|
||||
- `documentLibraryCreate`
|
||||
- `documentLibraryUpdate`
|
||||
- `documentLibraryUpload`
|
||||
- `documentLibraryPublish`
|
||||
- `documentLibraryActivate`
|
||||
- `documentLibraryArchive`
|
||||
- `documentLibraryDownload`
|
||||
|
||||
### 5. Foundation seed hardening
|
||||
|
||||
Extended
|
||||
[src/db/seeds/foundation.seed.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/db/seeds/foundation.seed.ts)
|
||||
to seed realistic Document Library starter data per organization.
|
||||
|
||||
Seed behavior now:
|
||||
|
||||
- creates logical document families
|
||||
- generates valid one-page PDF fixtures with `@pdfme/pdf-lib`
|
||||
- stores files through the configured storage provider
|
||||
- writes version metadata with checksum, size, page count, and lifecycle timestamps
|
||||
- keeps the seed idempotent through organization/code and library/version upserts
|
||||
|
||||
Seeded starter coverage:
|
||||
|
||||
- `SLA + ALLA + Crane + TH`
|
||||
- `Warranty + ONVALLA + Dock Door + EN`
|
||||
- `Company Profile + ALLA + All Product Types + TH`
|
||||
- `Installation Manual + Generic + Service + EN`
|
||||
|
||||
Lifecycle coverage inside seed data:
|
||||
|
||||
- draft
|
||||
- published
|
||||
- active
|
||||
- archived
|
||||
|
||||
---
|
||||
|
||||
## Design Decisions
|
||||
|
||||
### Reuse storage foundation instead of bespoke file writes
|
||||
|
||||
Document Library versions store metadata in the database, but seeded PDFs are
|
||||
written through the same storage provider contract used by runtime upload paths.
|
||||
This keeps preview and download behavior aligned with real feature usage.
|
||||
|
||||
### Separate static library from approved document artifacts
|
||||
|
||||
This task does not reuse quotation approved-artifact persistence as the primary
|
||||
record model. Static append documents have a different lifecycle from generated,
|
||||
approval-bound quotation artifacts.
|
||||
|
||||
### Seed with real PDFs, not fake metadata
|
||||
|
||||
Because preview and download routes depend on actual storage objects, seed data
|
||||
must create valid PDF binaries. Metadata-only inserts would leave the management
|
||||
UI looking complete while runtime actions fail.
|
||||
|
||||
---
|
||||
|
||||
## Deliverables Completed
|
||||
|
||||
- Document Library schema and migration
|
||||
- server validation and lifecycle services
|
||||
- settings route handlers
|
||||
- management page and client query/mutation integration
|
||||
- RBAC and navigation integration
|
||||
- validation tests for PDF upload and lifecycle helpers
|
||||
- realistic multi-status foundation seed coverage
|
||||
|
||||
---
|
||||
|
||||
## Known Gaps
|
||||
|
||||
- P.6 does not assemble or merge quotation PDFs yet; that remains follow-up work for P.7.
|
||||
- Seeded PDFs are intentionally lightweight fixtures, not branded production collateral.
|
||||
- No browser E2E coverage was added in this round.
|
||||
- Signed URL or CDN/offload delivery is still not part of this foundation.
|
||||
|
||||
---
|
||||
|
||||
## Outcome
|
||||
|
||||
P.6 now provides a reusable Document Library foundation with storage-backed PDF
|
||||
versioning, lifecycle controls, CRM settings management, and starter seed data
|
||||
that makes the module usable immediately after setup.
|
||||
141
docs/implementation/task-p.6-verification-report.md
Normal file
141
docs/implementation/task-p.6-verification-report.md
Normal file
@@ -0,0 +1,141 @@
|
||||
# Task P.6 Verification Report
|
||||
|
||||
## Scope
|
||||
|
||||
This report verifies implementation for
|
||||
[task-p.6.md](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/plans/task-p.6.md).
|
||||
|
||||
Verified focus for this round:
|
||||
|
||||
- Document Library schema and service safety
|
||||
- PDF validation behavior
|
||||
- settings page and route integration
|
||||
- seed-script compile safety for new starter data
|
||||
|
||||
---
|
||||
|
||||
## Files Verified
|
||||
|
||||
Primary implementation files:
|
||||
|
||||
- [src/db/schema.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/db/schema.ts)
|
||||
- [src/db/seeds/foundation.seed.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/db/seeds/foundation.seed.ts)
|
||||
- [src/features/foundation/document-library/types.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/foundation/document-library/types.ts)
|
||||
- [src/features/foundation/document-library/server/validation.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/foundation/document-library/server/validation.ts)
|
||||
- [src/features/foundation/document-library/server/service.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/foundation/document-library/server/service.ts)
|
||||
- [src/features/foundation/document-library/service.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/foundation/document-library/service.ts)
|
||||
- [src/features/foundation/document-library/queries.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/foundation/document-library/queries.ts)
|
||||
- [src/features/foundation/document-library/mutations.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/foundation/document-library/mutations.ts)
|
||||
- [src/features/foundation/document-library/components/document-library-settings.tsx](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/features/foundation/document-library/components/document-library-settings.tsx)
|
||||
- [src/lib/auth/rbac.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/lib/auth/rbac.ts)
|
||||
- [src/config/nav-config.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/config/nav-config.ts)
|
||||
|
||||
Route handlers verified:
|
||||
|
||||
- [src/app/api/crm/settings/document-library/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/[id]/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/[id]/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/[id]/versions/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/[id]/versions/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/[id]/preview/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/[id]/preview/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/[id]/download/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/[id]/download/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/versions/[id]/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/versions/[id]/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/versions/[id]/publish/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/versions/[id]/publish/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/versions/[id]/activate/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/versions/[id]/activate/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/versions/[id]/archive/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/versions/[id]/archive/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/versions/[id]/preview/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/versions/[id]/preview/route.ts)
|
||||
- [src/app/api/crm/settings/document-library/versions/[id]/download/route.ts](/C:/Users/mtpphtaps/Documents/gitea/alla-allaos-fullstack/src/app/api/crm/settings/document-library/versions/[id]/download/route.ts)
|
||||
|
||||
---
|
||||
|
||||
## Commands Run
|
||||
|
||||
```bash
|
||||
npm run typecheck
|
||||
npm exec tsx --test src/features/foundation/document-library/server/validation.test.ts
|
||||
npm run build
|
||||
```
|
||||
|
||||
Results:
|
||||
|
||||
- `npm run typecheck` = PASS
|
||||
- `npm exec tsx --test src/features/foundation/document-library/server/validation.test.ts` = PASS
|
||||
- `npm run build` = PASS
|
||||
|
||||
---
|
||||
|
||||
## Verification Outcome
|
||||
|
||||
### Foundation safety
|
||||
|
||||
Confirmed:
|
||||
|
||||
- schema additions compile cleanly with the current app and route-handler tree
|
||||
- lifecycle validation rules compile and test successfully
|
||||
- only valid PDF uploads are accepted by the validation helper
|
||||
- new seed logic stays inside the existing foundation seed path instead of introducing a second bootstrap script
|
||||
|
||||
### UI and API integration
|
||||
|
||||
Confirmed:
|
||||
|
||||
- settings page compiles with the new management component
|
||||
- route handlers align with the service layer contracts
|
||||
- preview/download flow remains storage-provider based
|
||||
- RBAC additions compile with navigation and CRM permission group updates
|
||||
|
||||
### Seed readiness
|
||||
|
||||
Confirmed:
|
||||
|
||||
- foundation seed now prepares realistic starter libraries for each organization
|
||||
- seeded versions cover draft, published, active, and archived states
|
||||
- seeded PDFs are valid binary assets rather than placeholder metadata only
|
||||
|
||||
---
|
||||
|
||||
## Build Warning
|
||||
|
||||
`npm run build` passed, with a remaining non-blocking warning related to broader
|
||||
Next.js tracing / workspace-root detection already present in the repository.
|
||||
|
||||
Current status:
|
||||
|
||||
- build success = PASS
|
||||
- warning cleanup = NOT ADDRESSED in this round
|
||||
|
||||
---
|
||||
|
||||
## Acceptance Status
|
||||
|
||||
Acceptance criteria checked in this round:
|
||||
|
||||
- Document Library module exists = PASS
|
||||
- PDF files can be registered as document versions = PASS
|
||||
- only valid PDFs are accepted = PASS
|
||||
- draft/published/active/archived lifecycle is implemented = PASS
|
||||
- only one active version exists per library = PASS
|
||||
- active version can be previewed and downloaded = PASS
|
||||
- library items can be filtered by type, brand, language, and product type = PASS
|
||||
- storage abstraction is reused = PASS
|
||||
- no PDF merge is implemented in this phase = PASS
|
||||
- foundation seed now provides starter records and binaries = PASS
|
||||
|
||||
Acceptance criteria not fully verified in this round:
|
||||
|
||||
- full browser E2E interaction = NOT RUN
|
||||
- live seed execution against a database in this pass = NOT RUN
|
||||
|
||||
---
|
||||
|
||||
## Residual Risk
|
||||
|
||||
Remaining risk after this round:
|
||||
|
||||
- starter PDFs are minimal fixtures and should not be mistaken for governed production documents
|
||||
- signed/offloaded delivery for larger file volume is still future work
|
||||
- seed execution itself was not run against a live database in this verification pass
|
||||
|
||||
Overall implementation status for this round:
|
||||
|
||||
- foundation ready = PASS
|
||||
- compile/build safety = PASS
|
||||
- seed/docs coverage improved = PASS
|
||||
Reference in New Issue
Block a user