feat(blog): add revision history and rollback workflow for blog posts - #50
Merged
Conversation
RsbhThakur
force-pushed
the
feature/blog-revision-history
branch
2 times, most recently
from
September 5, 2026 11:14
144a4df to
3f5d040
Compare
RsbhThakur
marked this pull request as ready for review
September 5, 2026 11:23
Contributor
|
…elpers Add BlogPostRevision Mongoose schema to store historical snapshots of published blog posts. Implement recordRevisionSnapshot domain helper with version sequencing and legacy post fallback, along with unit tests.
… endpoints Record revision snapshots on blog publish, direct admin edits, and revision approvals. Cascade delete revisions on post deletion. Add endpoints for admins and authors to list revision history and restore versions.
Generalize RevisionDiffViewer with custom labels. Add RevisionHistoryModal with timeline, diff comparison modes, and restore workflows. Connect revision history trigger to admin and member blog edit toolbars.
…n history Cover initial publication, direct admin edits, revision approval, version listing and details, admin live restore, author draft restore, RBAC, and cascade deletion.
RsbhThakur
force-pushed
the
feature/blog-revision-history
branch
from
September 5, 2026 20:25
37c5497 to
8778fa9
Compare
Contributor
Author
|
Thanks for the review @maydayv7! Fixed all three points:
Also added tests covering all three cases. Let me know if everything looks good to merge! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #32.
Follows up on #28 and #39 to implement a complete Blog Revision History system. Published posts now maintain an immutable, chronological snapshot history of every version across direct admin edits, approved member revisions, and rollbacks. Both administrators and member authors can inspect visual diffs against live content or previous versions, and restore historical snapshots with strict RBAC guarantees.
Key Changes
1. Data Model & Storage Strategy
BlogPostRevision):BlogPostRevisioncollection rather than an unbounded subdocument array onBlogPost, preventing document bloat, fragmentation, and the 16MB BSON limit.postId,slug,version,title,content,excerpt,coverImage,coverFocalPoint,tags,authors,editor,approvedBy,source("initial_publish" | "admin_edit" | "approved_revision" | "rollback"),restoredFromVersion,changeSummary, andcreatedAt.{ postId: 1, version: -1 }guarantees atomic version sequences, with secondary indexes on{ slug: 1, createdAt: -1 }.recordRevisionSnapshotautomatically synthesizes and seeds a Version 1 baseline snapshot for legacy published posts on their next edit, ensuring seamless upgrades with zero downtime or database backfills.2. Mutation Integration & Snapshot Capture
POST /api/admin/blog: Automatically records Version 1 when a post is created directly aspublished.PATCH /api/admin/blog/[slug]: Records Version 1 when transitioning a draft topublished, or increments the version snapshot on direct admin content changes.POST /api/admin/blog/[slug]/revision: Records a version snapshot upon admin approval of a member edit, attributing the author aseditorand the approving admin asapprovedBy.DELETE /api/admin/blog/[slug]: Cascades deletion to remove all associated historical snapshots when a post is permanently deleted.3. API Endpoints & Role-Based Restores
/api/admin/blog/[slug]/revisions):GET: Lists version summaries (omits heavy Markdown bodies) or retrieves a specific version's full content.POST /api/admin/blog/[slug]/revisions/[version]/restore: Reverts the live post directly to an earlier snapshot, records a"rollback"snapshot in history, writes a fail-closed audit log, and invalidates the edge cache./api/internal/blog/[slug]/revisions):GET: Lists version summaries for posts authored by the requesting user (isBlogAuthor).POST /api/internal/blog/[slug]/revisions/[version]/restore: Restores historical content into the staged draft (pendingRevision) without modifying live content, strictly preserving the review and approval safeguards introduced in PR feat(blog): allow members to edit published posts with approval workflow #39.4. UI & Visual Diffing
BlogEditorToolbar):/admin/blog/[slug]/editand/internal/blog/[slug]/edit.RevisionHistoryModal):live), with Previous (vN-1), or view raw markdown.