Context
The community hub (posts, course shares, likes, comments, profiles) is meant to stay academic. ADR-0034 let a post go public at once and granted points when it crossed an interaction threshold. That rewards popularity rather than quality, and spam or off-topic posts would show up before anyone could stop them. The team asked for every post to be approved by an admin first, with points for approval capped at once per day.
Decision
- A post is public only after an admin approves it. Its lifecycle is
DRAFT → PENDING_REVIEW → PUBLISHED | REJECTED, andREJECTED → PENDING_REVIEWwhen the author edits and resubmits. A rejection carries a reason the author sees. - Only the author and admins can see a post before approval. Anyone else gets a 404.
- Every decision names the version the admin read. A transition is one conditional update on
(id, status, version). Two admins deciding at once, or an author editing during review, leave exactly one outcome; the other caller gets409 POST_ALREADY_REVIEWED. - An admin never reviews their own post (
403 POST_SELF_REVIEW). - Anti-spam: at most 3 posts pending per author, plus a per-route rate limit on submit.
- Points are granted on approval, at most once per author per ICT day (#134). This replaces ADR-0034's interaction threshold. Likes earn no points.
- Comments are not pre-moderated. They appear at once and are handled through reports (#140), so admins are not swamped by every reply.
- Editing an approved post sends it back to review and hides it until it is approved again, with no new points (#139). An approved post cannot be turned into spam afterwards.
Alternatives considered
- Publish at once and moderate after reports (ADR-0034 as written): cheaper for admins, but spam is public until someone reports it, and points could be farmed by vote rings.
- Keep the approved version visible while an edit is reviewed: friendlier, but it needs a revision table for a capstone-sized benefit. Revisit if editing turns out to be common.
Consequences
- Admins have a review queue to work through; the queue is oldest first so no post waits forever.
PostStatusgainsPENDING_REVIEWandREJECTED;Postgainsversion,submittedAt,reviewedById,reviewedAtandrejectReason;NotificationKindgainsPOST_APPROVEDandPOST_REJECTED(migration20261121090000_community_post_review).- Post reward (#134): the approval, the first
publishedAtand the credit commit in one transaction. The ledger key ispost-approved:<authorId>:<ICT yyyy-mm-dd>, so the unique index is the daily cap even for two approvals at the same instant; only a post's first publication is eligible andpointsAwardedAtrecords the one that earned. The amount isCOMMUNITY_POST_APPROVED_POINTS(default 10,0turns it off). - Likes (#136): one row per member per item (the existing unique indexes), inserted with
ON CONFLICT DO NOTHINGor deleted, and the counter moves in the same transaction only when a row changed, so double clicks and retries are no-ops and the counter always equals the rows. Likes are rate-limited per address on the route and per member in the service (MemberThrottle, the throttler's own storage), because the global throttler runs before authentication. Public pages render without a session; the viewer's liked state is one/bff/community-social/likes/minequery after load. - Comments (#137): one level of replies (a reply to a reply attaches to the top-level comment); 1–2 000 characters of Markdown rendered with raw HTML skipped.
commentCountcounts live comments and replies and moves in the same transaction; a deleted comment with replies stays as a "Bình luận đã bị xoá" placeholder. A post that is not public refuses comments and locks existing ones (404). Notifications go to the post author (comment) or the replied-to author (reply), never to the actor, and fold into one unread notification per post within 10 minutes (NotificationsService.createCollapsing), linking to/blog/<slug>#comments. - Edit and delete (#139): an author may edit a pending, rejected or published post; each edit is the same conditional update on
(id, status, version), now also onhiddenAt IS NULLanddeletedAt IS NULL, and bumps the version. Editing a published post sets itPENDING_REVIEW, so it leaves the feed, and takes a review slot under the 3-pending cap; its firstpublishedAtandpointsAwardedAtare kept, so re-approval keeps the original date and earns nothing. A post a moderator hid cannot be edited (409 POST_NOT_EDITABLE). Delete is soft (deletedAt), in any state; comments and likes are only read through a public post, so they leave public view with it and need no write of their own. Points already earned stay.