Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Training PDF Guides and External Certificates — implementation plan
Spec / source: .ai/specs/2026-10-14-training-pdf-guides-and-external-certificates.md
Branch: feat/external-training-certificates
Progress
- Task 1: Install dependencies
- Task 2: Add the migration
- Task 3: Apply the migration and regenerate types
- Task 4: Validators, path check and services
- Task 5: Bulk update route accepts the new fields
- Task 6: Training page — PDF guide and External switch
- Task 7: Employee wizard — guide viewer and certificate step
- Task 8: Assignments page — certificate modal, view link, remove completion
- Task 9: Person trainings card — view link
- Task 10: Lingui, MCP digest, module docs
- Task 11: Lint, typecheck, tests
- Task 12: End-to-end check in the browser
Execution notes
Certificates upload through the server (
uploadTrainingCertificate), not from the browser:/sharehas no browser storage client. Tasks 7 and 8 post the file, not a key.Removing a completion needs
delete: resources(thetrainingCompletionrule inauthz/manifest.ts), notdelete: people.After review: one
recordTrainingCompletionhelper replaces the three completion copies; the training page became a card stack with header-only status changes.
Dependencies
Task 2 needs Task 1. Task 3 needs Task 2. Task 4 needs Task 3. Tasks 5–9 need Task 4 and are independent of each other. Task 10 needs Tasks 5–9. Task 11 needs Task 10. Task 12 needs Task 11.
Shared facts
- The private file URL for a storage key is
getPrivateUrl(path)from@carbon/files/media. It returns/file/preview/private/{path}. - Uploads use
storage(carbon).company(companyId).upload(key, file)from@carbon/files. Precedent:apps/erp/app/modules/sales/ui/Customer/CustomerTaxForm.tsx:54-75. FileDropzone(apps/erp/app/components/FileDropzone.tsx) converts HEIC to JPEG beforeonDrop. Use it for every dropzone.PdfViewer(apps/erp/app/modules/documents/ui/Documents/PdfViewer.tsx) is a default export. Load it withlazy(() => import(...))inside<Suspense>, asDocumentView.tsx:21,55does.- Every new user-facing string uses
useLingui().tor<Trans>.
Task 1: Install dependencies
Depends on: none Files: none
Steps:
- Check free memory with
vm_stat. Run nothing else heavy at the same time. - Run
pnpm installin the worktree root.
Verify:
ls node_modules/.pnpm | head -1
# Expected: one directory name
Out of scope: dependency upgrades.
Task 2: Add the migration
Depends on: 1 Files:
- Create:
packages/database/supabase/migrations/{timestamp}_training-guides-and-certificates.sql(made by the command)
Steps:
- Run
pnpm db:migrate:new training-guides-and-certificates. - Write this SQL into the new file:
ALTER TABLE "training"
ADD COLUMN "guidePath" TEXT,
ADD COLUMN "isExternal" BOOLEAN NOT NULL DEFAULT false;
ALTER TABLE "trainingCompletion"
ADD COLUMN "certificatePath" TEXT;
Verify:
ls packages/database/supabase/migrations | grep training-guides-and-certificates
# Expected: one file name
Out of scope: RPC functions, RLS policies.
Task 3: Apply the migration and regenerate types
Depends on: 2 Files:
- Modify (generated):
packages/database/src/types.tsand the other filesgenerate:typeswrites
Steps:
- If the local stack for this worktree is not running, STOP and ask the user. Do not rebuild the database.
- Run
pnpm db:migrate. - Run
pnpm run generate:types.
Verify:
grep -c "certificatePath\|guidePath\|isExternal" packages/database/src/types.ts
# Expected: a number of 6 or more
Out of scope: hand edits to generated types.
Task 4: Validators, path check and services
Depends on: 3 Files:
- Modify:
apps/erp/app/modules/resources/resources.models.ts - Modify:
apps/erp/app/modules/resources/resources.service.ts - Modify:
apps/erp/app/modules/resources/resources.models.test.ts
Steps:
- In
resources.models.ts, addcertificatePath: zfd.text(z.string().optional())totrainingCompletionValidator. - Add these helpers next to it:
export function trainingGuideKeyPrefix(companyId: string, trainingId: string) {
return `${companyId}/training/${trainingId}/`;
}
export function trainingCertificateKeyPrefix(
companyId: string,
trainingAssignmentId: string,
employeeId: string
) {
return `${companyId}/training-certificates/${trainingAssignmentId}/${employeeId}/`;
}
export function isValidTrainingFileKey(key: string, prefix: string) {
return (
key.startsWith(prefix) &&
key.length > prefix.length &&
!key.slice(prefix.length).includes("/") &&
!isUnsafeStoragePath(key)
);
}
Import isUnsafeStoragePath from @carbon/files.
3. In resources.service.ts:
- Add
certificatePath?: string | nullto theinsertTrainingCompletionargument type. - Add
guidePath, isExternalto thetraining(...)select ingetTrainingAssignmentForCompletion. - Add
deleteTrainingCompletion(client, id: number, companyId): delete fromtrainingCompletionwhereidandcompanyIdmatch. Mark it/** @mcp delete */. - Add
getTrainingCertificatePaths(client, companyId, completionIds: number[]). If the list is empty, return{ data: {}, error: null }. Else selectid, certificatePathwith.in("id", completionIds)and.eq("companyId", companyId). Return{ data: Record<number, string>, error }with only the rows that have a path. - In
resources.models.test.ts, add tests forisValidTrainingFileKey: acceptsc1/training-certificates/a1/u1/x.pdf; refuses a different company, a nested folder,..segments, and the bare prefix.
Verify:
cd apps/erp && pnpm exec vitest run app/modules/resources/resources.models.test.ts
# Expected: all tests pass
Out of scope: the RPC functions.
Task 5: Bulk update route accepts the new fields
Depends on: 4 Files:
- Modify:
apps/erp/app/routes/x+/training+/update.tsx
Steps:
- Add
case "isExternal": writevalue === "on"toisExternal. - Add
case "guidePath":- Read the training rows for
idswithstatus, companyId. - If any row is not Draft, return
{ error: { message: "The guide can only change on a Draft training" }, data: null }. - If
valueis not empty and failsisValidTrainingFileKey(value, trainingGuideKeyPrefix(companyId, id)), return an error. Only allow one id for this field. - Write
guidePath: value === "" ? null : value.
- Read the training rows for
- Use
companyIdfromrequirePermissions.
Verify:
pnpm exec turbo run typecheck --filter=erp
# Expected: no errors in update.tsx
Out of scope: the other fields.
Task 6: Training page — PDF guide and External switch
Depends on: 4 Files:
- Create:
apps/erp/app/modules/resources/ui/Training/TrainingGuide.tsx - Modify:
apps/erp/app/modules/resources/ui/Training/index.ts— exportTrainingGuide - Modify:
apps/erp/app/routes/x+/training+/$id.tsx— renderTrainingGuideaboveTrainingEditor; passexploreronly when!training.isExternal - Modify:
apps/erp/app/modules/resources/ui/Training/TrainingProperties.tsx— External switch - Copy from (precedent):
apps/erp/app/modules/sales/ui/Customer/CustomerTaxForm.tsx(upload),apps/erp/app/modules/items/ui/Parts/PartProperties.tsx:780(Booleanproperty)
Steps:
TrainingGuideprops:trainingId,guidePath,canEdit.- If
guidePathis set, showPdfViewerwithgetPrivateUrl(guidePath)in a horizontally scrollable box. - If
canEdit, show aFileDropzonewithaccept={{ "application/pdf": [".pdf"] }}andmultiple={false}. - On drop, upload to
trainingGuideKeyPrefix(companyId, trainingId) + nanoid() + ".pdf". Then postfield=guidePathtopath.to.bulkUpdateTrainingwithuseAction. - If
canEditand a guide exists, show a Remove PDF button. It postsguidePathwith an empty value.
- If
canEdit=permissions.can("update", "people") && training.status === "Draft". This is the editor's rule ($id.tsx).- In
TrainingProperties, add"isExternal"to theonUpdatefield union. Add aBooleannamedisExternal, labelt\External`, after Frequency.onChangecallsonUpdate("isExternal", value ? "on" : "off"). Read-only withoutupdate: people`.
Verify:
pnpm exec turbo run typecheck --filter=erp
# Expected: no errors
Out of scope: multiple PDFs, a PDF block inside the editor.
Task 7: Employee wizard — guide viewer and certificate step
Depends on: 4 Files:
- Modify:
apps/erp/app/routes/share+/training.$id.tsx
Steps:
- Loader: return
guidePath,isExternalandcompanyIdof the assignment intraining. IfisExternal, returnquestions: []. ContentStep: ifguidePathis set, show the lazyPdfViewerabove the typed content. Change the empty text to show only when there is no guide and no typed content.- Wizard: if
training.isExternal:- Total steps = 2: reading step, then a
CertificateStep. CertificateStepshows aFileDropzonewith PDF and image types (copy theacceptmap fromCustomerTaxForm.tsx:153-156) andmultiple={false}.- On drop, upload to
trainingCertificateKeyPrefix(companyId, assignmentId, userId) + nanoid() + "." + ext. Keep the key in state. Show the file name with a Change file option before submit. - The last button is Submit Certificate, disabled until a key exists and while the submit runs. It posts
intent=certificateandcertificatePath.
- Total steps = 2: reading step, then a
- Action: if
intent === "certificate":- Load the authorized assignment (
getAuthorizedAssignment). If the training is not External, return 400. - If
isValidTrainingFileKey(certificatePath, trainingCertificateKeyPrefix(assignment.companyId, id, userId))is false, log and return 400. - Get the period with
get_current_training_period. Insert the completion withcertificatePath. If the insert fails, log and return 500. - Run the same ability restamp as the quiz path.
- Return
{ passed: true, score: 1, totalQuestions: 0, userAnswers: {}, correctAnswers: 0 }soResultsViewshows the success state.
- Load the authorized assignment (
- The quiz action refuses an External training with 400.
Verify:
pnpm exec turbo run typecheck --filter=erp
# Expected: no errors
Out of scope: existing untranslated strings in this file.
Task 8: Assignments page — certificate modal, view link, remove completion
Depends on: 4 Files:
- Modify:
apps/erp/app/routes/x+/resources+/assignments.$trainingId.tsx - Modify:
apps/erp/app/routes/x+/resources+/assignments.complete.tsx - Create:
apps/erp/app/routes/x+/resources+/assignments.uncomplete.tsx - Modify:
apps/erp/app/utils/path.ts— addmarkTrainingIncomplete: \${x}/resources/assignments/uncomplete`` - Copy from (precedent):
apps/erp/app/routes/x+/resources+/assignments.complete.tsx
Steps:
- Loader: collect
completionIdvalues. CallgetTrainingCertificatePathsonce. ReturncertificatePaths. AssignmentListItemgetsisExternal,certificatePath,canRemoveprops.- If
isExternaland the row can be completed, Mark Complete opens aModalwith aFileDropzone(same types as Task 7). On upload it submits the existing form withcertificatePath. The submit button disables while the fetcher runs. - If
certificatePathis set, show a View Certificate link togetPrivateUrl(certificatePath)withtarget="_blank". - If the row is Completed and
canRemove, show Remove Completion. It opens aConfirmthat says: "The employee keeps any ability this training granted. Remove it on their Abilities page if needed." On confirm it postscompletionIdtopath.to.markTrainingIncomplete. canRemove=permissions.can("delete", "people").
- If
assignments.complete.tsx: readcertificatePath. Read the training'sisExternalthrough the assignment. If External and the key failsisValidTrainingFileKey(...), return 400 with a flash error. PasscertificatePathtoinsertTrainingCompletion.assignments.uncomplete.tsx:assertIsPost.requirePermissions(request, { delete: "people" }). CalldeleteTrainingCompletion. Flash success or error. Log the error first.
Verify:
pnpm exec turbo run typecheck --filter=erp
# Expected: no errors
Out of scope: removing the granted ability.
Task 9: Person trainings card — view link
Depends on: 4 Files:
- Modify:
apps/erp/app/routes/x+/person+/$personId.abilities.tsx - Modify:
apps/erp/app/modules/people/ui/Person/PersonTrainings.tsx
Steps:
- Loader: after the trainings load, call
getTrainingCertificatePathswith theircompletionIdvalues. ReturncertificatePaths. PersonTrainingstakescertificatePaths. If a row has a path, show a View Certificate link next to the date.
Verify:
pnpm exec turbo run typecheck --filter=erp
# Expected: no errors
Out of scope: other person tabs.
Task 10: Lingui, MCP digest, module docs
Depends on: 5, 6, 7, 8, 9 Files:
- Modify:
packages/locale/locales/*/erp.po(generated) - Modify: MCP generated files (generated)
- Modify:
apps/erp/app/modules/resources/AGENTS.md— Training concept, data model and service list
Steps:
- Run
pnpm lingui:extract. - Run
pnpm lingui:clean. - Run
pnpm run generate:mcp. - Update the Training line in
AGENTS.md: PDF guide, External trainings, certificate keys, the two new services.
Verify:
grep -c "Submit Certificate" packages/locale/locales/en/erp.po
# Expected: 1
Out of scope: pnpm translate.
Task 11: Lint, typecheck, tests
Depends on: 10 Steps:
- Run
pnpm exec turbo run typecheck --filter=erp. - Run
pnpm exec biome checkon the changed files. - Run
cd apps/erp && pnpm exec vitest run app/modules/resources. - Run
pnpm --filter @carbon/checks license-headersfor the new files.
Verify:
pnpm exec turbo run typecheck --filter=erp
# Expected: exit 0
Task 12: End-to-end check in the browser
Depends on: 11 Steps:
- Ask the user before you drive the browser.
- Walk the 12 acceptance criteria in the spec. Record each result.
Verify: every acceptance criterion passes, or the failure is reported.