8.5 KiB
Approval & Publishing Workflow Plan
Summary
This plan covers the implementation of approval, publishing, scheduling, preview, versioning, audit logging, and notification support for:
announcementsonline-lessons
The goal is to extend the current simple draft/published/archived model into a controlled workflow without breaking the project's existing Auth.js, Drizzle, route-handler, and TanStack Query patterns.
Current Repo Reality
Announcements
- Current status model:
draft | published | archived - Employee visibility is currently based on:
status = publishedstart_date <= nowend_date is null or end_date >= now
- HRD and super admin can manage records through existing create/update/delete endpoints
- Publish and archive are currently direct status updates
- Notifications already exist for published announcements
- Audit logging already exists for create, update, publish, archive
Online Lessons
- Current status model:
draft | published | archived - Employee visibility is currently based on
is_published = true - Publish is currently a direct status change plus
isPublished/publishedAt - Audit logging and notifications are not yet as complete as announcements
Roles
- Current business roles in code:
ITHRDEMPLOYEE
- Current elevated system role:
super_admin
- There is no dedicated
HRD_MANAGERrole in the current schema or auth helper layer
Scheduler
- No existing publish scheduler or cron pattern was found in the repo
- Scheduled publish must therefore be introduced deliberately and in a way that matches deployment constraints
Key Gaps To Solve
- Status enums are too limited for the requested workflow.
- No first-class review metadata exists for announcements or online lessons.
- No versioning structure exists for either module.
- No
HRD Managercapability exists in the current role model. - No scheduled publish executor exists.
- Employee visibility rules differ between announcements and online lessons and need to be normalized around
Published + current version.
Proposed Design Decisions
1. Workflow status model
Use the same workflow vocabulary for both modules:
draftpending_approvalapprovedscheduledpublishedrejectedarchived
2. Versioning model
For both announcements and online_lessons, add:
versionparent_idis_current
Behavior:
- Records not yet published can be edited in place
- Once a record has been published, editing must create a new draft revision
- Only one version per logical record can be
is_current = true - Employee-facing queries must only show:
status = publishedis_current = true
3. Permission model
Use the current auth model as the base and extend it with app-owned permission checks instead of inventing client-only gates.
Recommended interpretation for implementation:
super_admin- full override for all workflow actions
HRD- current generic HRD behavior should be split by permission, not by a brand new auth system
Recommended incremental approach:
- keep existing
businessRolevalues - introduce fine-grained permission checks for content workflow actions
- model
HRD Manageras a permission-capable HRD user, not as a breaking replacement of the current role model
Suggested permission flags:
content:submitcontent:approvecontent:publishcontent:archivecontent:schedulecontent:manage_all
This avoids rewriting the entire auth model while still supporting the requested behavior.
4. Scheduled publish
Because no scheduler pattern currently exists, implement in two layers:
- data model and API support first
- a server-triggerable publish processor second
Recommended first implementation:
- add a reusable server function that publishes due scheduled records
- expose an internal route handler or job entrypoint for future cron integration
This keeps the business logic testable even before infrastructure automation is added.
Database Changes
Announcements
Extend announcements with:
versionparent_idis_currentsubmitted_bysubmitted_atapproved_byapproved_atrejected_byrejected_atrejected_reasonscheduled_publish_atpublished_bypublished_atunpublished_byunpublished_atarchived_byarchived_at
Replace enum values to support the workflow states.
Online Lessons
Extend online_lessons with the same workflow and versioning fields.
Review whether is_published should be retained temporarily as a derived compatibility field during migration or removed after full workflow migration.
Backend Work Plan
Phase 1. Shared workflow foundation
- add new enums to
src/db/schema.ts - add migration for announcements and online lessons
- add shared permission helpers for content workflow
- extend audit action constants
- extend notification service helpers
Phase 2. Announcement workflow backend
- update list/detail access rules
- update create/edit behavior
- add submit for approval action
- add approve/reject action
- add publish now action
- add schedule publish action
- add cancel schedule action
- add unpublish action
- add archive action
- add create revision action for published records
Phase 3. Online lesson workflow backend
- apply the same workflow actions and rules
- align employee visibility with
published + is_current
Phase 4. Scheduled publish processor
- create reusable processor for due announcements
- create reusable processor for due online lessons
- add internal route or task entrypoint for future cron wiring
Frontend Work Plan
Announcements
- refactor form actions:
Save DraftSubmit for ApprovalPreview
- remove direct publish/archive controls from HRD staff flows
- add manager/admin action controls based on status
- add revision flow for published records
- add preview route/view
Online Lessons
- refactor form actions to match announcement workflow
- replace direct publish/archive actions with workflow-aware actions
- add preview and revision behavior
HRD Manager Dashboard
Introduce a dedicated manager workflow page that groups both modules by status:
- pending approval
- approved waiting publish
- scheduled
- published
- rejected
- archived
Recommended implementation path:
- start with one page under dashboard
- use tabs or segmented sections
- reuse existing table/list patterns instead of inventing a new shell
API Surface To Add
Recommended route pattern:
POST /api/announcements/[id]/submitPOST /api/announcements/[id]/approvePOST /api/announcements/[id]/rejectPOST /api/announcements/[id]/publishPOST /api/announcements/[id]/schedulePOST /api/announcements/[id]/cancel-schedulePOST /api/announcements/[id]/unpublishPOST /api/announcements/[id]/archivePOST /api/announcements/[id]/revision
Mirror the same shape for online-lessons.
Keep these actions separate from generic PATCH to preserve explicit permission checks and status transitions.
Audit And Notification Plan
Audit
Extend audit coverage for both modules:
- submit
- approve
- reject
- publish
- schedule
- cancel schedule
- unpublish
- archive
- create revision
Notifications
Reuse the existing notification service.
Add notification types/messages for:
- submitted for approval
- approved
- rejected
- scheduled
- published
- unpublished
- archived
Risks
-
Role model ambiguity:
HRD Managerdoes not yet exist as a first-class role, so permission-based implementation is safer than role explosion. -
Scheduler infrastructure: automatic scheduled publish cannot be considered complete until deployment wiring is agreed.
-
Versioning migration: existing published records must be backfilled carefully so they become
version = 1andis_current = true. -
UI complexity: if both modules implement bespoke workflow UIs separately, the code may drift. Shared status/action utilities should be introduced where practical.
Implementation Order
- Add workflow plan document
- Add schema changes and migration
- Add shared workflow permission helpers
- Upgrade announcement backend
- Upgrade online lesson backend
- Add preview and revision flows
- Add manager dashboard
- Add scheduled publish processor entrypoint
- Add docs and implementation report
Immediate Next Step
Start with schema and contract design for:
- workflow statuses
- versioning columns
- approval metadata
- publish metadata
Then implement announcement backend first as the reference module, followed by online lessons.