Skip to content

feat(blog): allow members to edit published posts with approval workflow - #39

Merged
maydayv7 merged 17 commits into
devfrom
feat/blog-revisions
Sep 4, 2026
Merged

feat(blog): allow members to edit published posts with approval workflow#39
maydayv7 merged 17 commits into
devfrom
feat/blog-revisions

Conversation

@RsbhThakur

@RsbhThakur RsbhThakur commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Closes #28.

Implements an editorial workflow allowing member authors to stage edits on their published blog posts without immediately modifying live content. Staged updates can be saved incrementally, previewed, withdrawn, or submitted to administrators for review. Administrators receive notifications, can inspect an inline line-by-line visual diff comparing the live post against proposed changes, and can approve or reject revisions with automatic cache invalidation and author notifications.


Key Changes

1. Data Schema & Access Control

  • BlogPost Schema: Added pendingRevision subdocument storing staged revision content (title, content, excerpt, coverImage, coverFocalPoint, tags, updatedAt, submittedAt, submittedBy).
  • RBAC: Expanded canEditBlogDraft and exported isBlogAuthor / canAccessBlogEditor so authors can access the editor for their published posts while maintaining strict non-author protection.

2. Member Revision Flow

  • PATCH /api/internal/blog/[slug]:
    • Automatically routes published post edits to pendingRevision (staging).
    • Supports requestApproval: true to submit for admin review.
    • Supports cancelApproval: true to withdraw review requests back to draft staging without losing work.
    • Supports DELETE to discard staged revisions and revert to live content.
  • UI & Dashboard:
    • Added "Edit Article" pencil button in the public blog header for authors/admins.
    • Enhanced Member Dashboard (/internal/dashboard) with "My Blogs" list, direct edit links, and contextual status badges (published · draft changes saved, published · changes pending approval).

3. Admin Review & Diff Inspector

  • POST /api/admin/blog/[slug]/revision: Endpoint supporting approve (atomically applies revision to live fields and clears staging) and reject (discards revision) with cache and Next.js path revalidations.
  • Inline Diff Inspector (RevisionDiffViewer):
    • Displays field-by-field comparison for Title, Excerpt, Tags, and Cover Image.
    • Features an inline unified diff viewer showing added (+ green) and deleted (- red) lines with line numbers.
    • Renders the complete BlogEditor directly below for live preview and admin adjustments.

4. Notifications & Audit Logging

  • Notifications:
    • Added "blog_revision" to NOTIFICATION_TYPES.
    • Automatically notifies all Heads/Admins upon revision submission.
    • Automatically notifies the author upon approval or rejection.
  • Audit Logging: Recorded operations for blog.revision.update, blog.revision.submit, blog.revision.withdraw, blog.revision.approve, and blog.revision.reject.

Verification & Testing

  • Automated Integration Tests:
    • tests/integration/blog-admin.test.ts (approval and rejection flows, cache invalidation, audit trails).
    • tests/integration/blog-member-drafts.test.ts (revision creation, submission, and author RBAC).
    • tests/integration/blog-images.test.ts (author image uploads against published post revisions).
  • Typecheck: pnpm typecheck (tsc --noEmit) passes with 0 errors.
  • Manual E2E Testing: Verified member staging, review withdrawal, admin diff inspector, live updates, and notification delivery.

Screenshots

image image image

@RsbhThakur

Copy link
Copy Markdown
Contributor Author

Usage note for admin: The admin need to go to the edit page of the blog they want to reject/aprove edit requests and on that page they can view the diff and approve/reject the changes.

Also a natural follow up to this PR would be to send notifications to the admins for newly requested changes on blogs and to the authors on the admin's decisions. Opening a seperate issue for it as it is out of scope of the current PR.

@RsbhThakur
RsbhThakur marked this pull request as ready for review September 3, 2026 22:40
@RsbhThakur RsbhThakur changed the title Feat/blog revisions feat(blog): allow members to edit published posts with approval workflow Sep 3, 2026
Introduce IBlogRevision schema and pendingRevision subdocument in BlogPost model. Update blog access control helper to allow authors to access editor and stage revisions on published posts.
Support staged revisions in PATCH /api/internal/blog/[slug] with requestApproval flag, revision discard via DELETE, and create POST /api/admin/blog/[slug]/revision endpoint for approving or rejecting staged revisions with cache purging.
Extend BlogEditor with customizable action buttons. Update member dashboard and edit pages to support published blog revisions with status banners, approval submission, and revision discarding. Add direct edit article button on public blog headers for authors.
Add review banners and diff toggles with approve/reject actions to admin blog pages. Add integration tests covering member revision lifecycle, approval request, admin approval/rejection, and cache revalidation.
…blished posts

Update admin revision audit actor access assertion to Head and update blog-images tests to verify authors can upload images to published posts while non-authors are forbidden.
Support matching author userId across ObjectId and string types, and improve edit button visibility and z-index on dashboard blog cards.
…ions

Allow authors to withdraw pending review requests back to draft staging without losing their work, and provide distinct contextual actions for discarding drafts vs discarding submitted proposals.
… notifications

Replace the two-tab review toggle with an inline RevisionDiffViewer component showing metadata and line-by-line Markdown changes with green additions and red deletions, and automatically dispatch in-app and push notifications to admins when revisions are submitted and to authors upon approval/rejection.
@maydayv7
maydayv7 force-pushed the feat/blog-revisions branch from 27475f7 to 5ba2846 Compare September 3, 2026 23:21
Comment thread src/lib/audit/index.ts
Comment thread src/app/api/internal/blog/[slug]/route.ts
Comment thread src/app/api/admin/blog/[slug]/revision/route.ts
Comment thread src/app/api/admin/blog/[slug]/revision/route.ts
Comment thread src/app/api/admin/blog/route.ts
Comment thread src/app/(protected)/internal/dashboard/page.tsx
Comment thread src/app/api/admin/blog/[slug]/revision/route.ts
Comment thread src/app/(public)/blog/[slug]/page.tsx Outdated
@RsbhThakur
RsbhThakur requested a review from maydayv7 September 4, 2026 12:10
@maydayv7
maydayv7 dismissed their stale review September 4, 2026 16:18

All comments addressed

@maydayv7
maydayv7 merged commit fe569d5 into dev Sep 4, 2026
1 check passed
@maydayv7
maydayv7 deleted the feat/blog-revisions branch September 4, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow members to edit published blogs

2 participants