issue-7: add moderation flow#65
Conversation
📝 WalkthroughWalkthroughAdds a moderation subsystem: frontend JS for moderation actions, backend Go moderation repository and HTTP handlers, DB migrations for moderation_status and moderation_actions, template updates for moderation UI and profile admin controls, and wiring in main.go to expose moderation routes and admin checks. Changes
Sequence DiagramssequenceDiagram
participant Admin as Admin (Browser)
participant UI as Frontend JS
participant API as Moderation API
participant Repo as Moderation Repo
participant DB as PostgreSQL
Admin->>UI: Click Approve/Reject
activate UI
UI->>UI: disable buttons, show spinner
UI->>API: POST /api/v1/moderation/{id} {action}
deactivate UI
activate API
API->>API: authenticate & verify admin
API->>API: validate UUID, parse action
API->>Repo: SetRecordStatus(recordId, status)
activate Repo
Repo->>DB: UPDATE records SET moderation_status = ?
DB-->>Repo: OK
Repo->>DB: INSERT INTO moderation_actions(...)
DB-->>Repo: OK
Repo-->>API: success
deactivate Repo
API-->>UI: 200 {status}
deactivate API
activate UI
UI->>UI: show toast, reload after toast
deactivate UI
sequenceDiagram
participant Admin as Admin (Browser)
participant Handler as Moderation Handler
participant Repo as Moderation Repo
participant RecordRepo as Record Repository
participant DB as PostgreSQL
participant Template as Template Engine
Admin->>Handler: GET /moderation?page=1
activate Handler
Handler->>Handler: authenticate & verify admin
Handler->>Repo: GetPendingRecords(limit, offset)
activate Repo
Repo->>DB: SELECT records WHERE moderation_status='pending_review'
DB-->>Repo: rows
Repo->>RecordRepo: enrich records (categories, ror)
activate RecordRepo
RecordRepo->>DB: JOIN queries
DB-->>RecordRepo: related data
RecordRepo-->>Repo: enriched records
deactivate RecordRepo
Repo-->>Handler: []records, total
deactivate Repo
Handler->>Repo: GetRecentModerationHistory(limit)
activate Repo
Repo->>DB: SELECT FROM moderation_actions ORDER BY created_at DESC
DB-->>Repo: history
Repo-->>Handler: []history entries
deactivate Repo
Handler->>Template: render moderation.html (records, history, pagination)
Template-->>Handler: HTML
Handler-->>Admin: 200 OK (HTML)
deactivate Handler
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Free 📒 Files selected for processing (1)
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
| @@ -0,0 +1,19 @@ | |||
| -- Add moderation status to records table | |||
| ALTER TABLE records ADD COLUMN moderation_status VARCHAR(20) DEFAULT 'approved'; | |||
There was a problem hiding this comment.
how about moderation_status with 0 for pending approval, -1 for reject and 1 for approved. Instead of a varchar, unless there are other status? Or good reasons to use an english string value?
There was a problem hiding this comment.
We can change to number, it's just convention for human friendly. But we need a mapping from number -> status when change to using number
|
thanks! |
Closes #7 :
Add new moderation link on profile for Admin
Only show approved record on browse screen
Displaying the record status on My Profile
Displaying record in queue and history
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.