Adding Comment Approval/Moderation Feature #1975
Open
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.
This PR adds a comment moderation mechanism with an approval phase. When enabled, new comments require admin approval before becoming visible to other users. Admins can see all comments (both approved and unapproved), while regular users only see approved comments.
Features
NEED_APPROVALsetting: When set totrue, enables comment moderationUnapproved boolfield (defaults tofalse) so existing comments remain visible after upgradeConfiguration
--need-approvalNEED_APPROVALfalseBackend Changes
Store Layer (
backend/app/store/)comment.go: AddedUnapproved boolfield toCommentstructcomment_test.go: Added test for JSON serialization of unapproved fieldService Layer (
backend/app/store/service/)service.go:NeedApproval booltoDataStorestructprepareNewComment(): SetsUnapproved = truefor new comments whenNeedApprovalis enabledSetApproved(): New method to approve/disapprove commentsfilterUnapproved(): Filters out unapproved comments for non-admin usersGet(),Last(), andFind()to filter unapproved commentsservice_test.go: Added comprehensive tests for approval functionalityAPI Layer (
backend/app/rest/api/)rest.go:NeedApprovalto config endpoint responsePUT /api/v1/admin/approve/{id}?site=...&url=...admin.go: AddedsetApprovedCtrlhandler for approval endpointServer Configuration (
backend/app/cmd/)server.go: Added--need-approval/NEED_APPROVALCLI flagFrontend Changes
Types & API (
frontend/apps/remark42/app/common/)types.ts: Addedunapproved?: booleantoCommenttype,need_approval: booleantoConfigtypeapi.ts: AddedapproveComment()anddisapproveComment()API functionsstatic-store.ts: Addedneed_approvaldefault valueRedux Store (
frontend/apps/remark42/app/store/comments/)actions.ts: AddedsetApprovalState()action creatoractions.test.ts: Added tests for approval actionsUI Components (
frontend/apps/remark42/app/components/comment/)comment.tsx: Added visual indicator for unapproved comments, passesneedApprovalconfig to actionscomment-actions.tsx: Added Approve/Disapprove button (only shown whenneedApprovalistrueand user is admin)connected-comment.tsx: ConnectedsetApprovalStateaction to componentcomment.test.tsxandcomment-actions.spec.tsxwith approval testsPackages (
frontend/packages/api/)clients/public.ts: Addedapproveanddisapprovemethods toPublicClientDocumentation
site/src/docs/configuration/parameters/index.md: Addedneed-approval/NEED_APPROVALparameter documentationDesign Decisions
Unapproved boolvsApproved bool: UsedUnapprovedso that Go's defaultfalsevalue means comments are approved. This ensures existing comments remain visible after migration without requiring a database update.Config-driven UI: The approval button only appears when both
need_approvalistrueAND the user is an admin. This keeps the UI clean when moderation is disabled.Comment visibility: The comment author can always see their own unapproved comments. Other non-admin users cannot see unapproved comments at all.
Testing
cd backend/app && go test ./...cd frontend/apps/remark42 && pnpm test