diff --git a/CHANGELOG.md b/CHANGELOG.md index 89298e7..f280c18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,63 @@ they reach Production with a separate, approved promotion of DOS.Me `main`. ### Design system and screens +- Co-organizers (campaign editors), single-use invites, workspace guards and + public team block: `/me/campaigns/[id]?tab=team` (`TeamTab`, + `CreateInviteForm`, `member-actions.ts`) lets the owning organizer create + single-use expiring invite links (raw 64-char hex token shown once on + creation, never logged or re-displayed), revoke pending invites and remove + accepted editors, while explicitly keeping money, receiving accounts, + statements, refunds, fulfillment, monthly plans, analytics, lifecycle + transitions and team management owner-only (`notFound()` for editors/staff). + `/invites/[token]` sets `Referrer-Policy: no-referrer`, + `Cache-Control: private, no-store` and `X-Robots-Tag: noindex, nofollow`, + prompts guests to sign in without leaking draft titles or touching + `dbService()`, and previews/accepts pending invites via `dbAs(token)` with + already-member shortcuts. `/me/campaigns` lists both owned and accepted + editor campaigns (badged `"Đồng tổ chức"`), `/me/campaigns/[id]` lets + accepted editors manage content, cover, YouTube pitch video, milestones, + reward tiers and own updates under strict server guards, and public + `/campaigns/[slug]` pages render `CampaignTeam` (`"Đội ngũ tổ chức"`) when + a campaign has accepted editors, backed by `DOS/Give#264` (`DOS/DOS.Me#1856`) + with Vitest suites (#253 / #298). +- Public organizer profile page and `/me` handle/bio editor: `/u/[handle]` + renders public organizer profiles (`handle`, `bio`, `OrganizerAvatar` with + safe `https://` validation and 4px-radius initials fallback, verification + badge and public campaigns with ledger totals) strictly through anonymous + `dbAs()` calls to `give.public_organizer_profile` and + `give.list_organizer_public_campaigns`. `/me` (`PublicProfileForm`, + `actions.ts`, wired into `MePage` and `SiteHeader`) lets signed-in organizers + edit only `(handle, bio)` with live `give.vn/u/` URL preview, + 3–40-char regex and 96-word reserved-handle validation matching + `DOS/Give#261` (`DOS/DOS.Me#1851`), Vietnamese error mappings and preserved + `verification_status`, while `/campaigns/[slug]` and `CampaignCard` link the + organizer name to `/u/` when set, with Vitest suites (#251 / #297). +- Campaign comments with one reply level, moderation and comment reports queue: + public `/campaigns/[slug]` pages add the `#binh-luan` tab and + `CampaignComments` (plain-text comments and 1-level replies with newest roots + first and oldest replies first, `"Người tổ chức"` badge, `"(đã chỉnh sửa)"` + indicator, deleted-account neutral fallback, `?comments_page=` pagination, + authenticated post/reply/edit/delete/report, organizer hide, and staff + `?show_hidden=1` inline moderation with self-review guards via `dbAs(token)`). + `/admin/reports` gains a `TabNav` (`"Báo cáo chiến dịch"` / `"Báo cáo bình +luận"`) leading to `/admin/reports/comments` with status/campaign filters, + `list_comment_moderation_history` audit disclosure and deleted-comment + snapshot handling, backed by `DOS/Give#262` (`DOS/DOS.Me#1853`) with Vitest + suites (#250 / #296). +- Organizer campaign analytics and `Thống kê` tab: `POST /api/analytics/event` + (excluded from `proxy.ts` session rotation) validates same-origin / + `Sec-Fetch-Site`, enforces JSON/size bounds, silently filters bot User-Agents + while allowing Zalo/Facebook in-app browsers and Cốc Cốc, applies ephemeral + HMAC-hashed rate limiting, strips referrer paths/queries and normalizes + same-origin hosts to `null`, and calls `dbService().rpc("record_campaign_event")`. + `CampaignViewBeacon` deduplicates views to once per campaign per Vietnam + calendar day per browser (`sendBeacon` with `keepalive` `fetch` fallback, + suppressed on previews/prerenders) and `ShareButtons` records `share_click` + events. `/me/campaigns/[id]?tab=analytics` (`AnalyticsTab`, `TabNav` and + 7/30/90-day `SegmentedNav`) reads `give.get_campaign_analytics` via + `dbAs(token)` to render KPIs, daily views trend, responsive breakdown and + referrer bars, backed by `DOS/Give#263` (`DOS/DOS.Me#1852`) with Vitest + suites (#252 / #295). - Organizer campaign status and review history: `/me/campaigns/[id]` loads `listStatusEventsByCampaign(db, [campaign.id])` inside `Promise.all` with `.catch(() => new Map())` resilience and renders `` inside @@ -559,6 +616,15 @@ trang"` gating, `"Quản lý"`, and `changes_requested` review notes), ### Platform +- Parallel PO configuration (CC-PO v2.18.0): `docs/product-owner-config.md` + assigns Antigravity `Campaigns Product Owner` (`acc0`) to `line:campaigns` + (replacing paused Qwen Code sessions), enforces `po:agy` / `po:claude` + mutual-exclusion `po_labels`, keeps Production (`main` / `give.vn`), + `line:money` and `line:platform` exclusively under Claude Code + `Give Product Owner` (`promotion_po: claude`), records JOY's authorization + for Antigravity PO to pick up unclaimed `DOS/DOS.Me` prerequisites + `#261`–`#264`, and adds CC-PO v2.18.0 gatekeeper and context-compaction keys + (#292 / #293). - Email throttling hold: the SMTP transport stays on AWS SES (host, port, login and key from env). When SES answers 454 "Daily message quota exceeded" (a quota shared with DOS.Me), the email is now held instead of @@ -614,6 +680,51 @@ trang"` gating, `"Quản lý"`, and `changes_requested` review notes), ### Database (DOS.Me) +- Co-organizers and single-use invites: `give.campaign_members` (editors only, + blocking owner self-membership) and `give.campaign_member_invites` (32-byte + SHA-256 token hashes only, zero direct table grants), 9 `SECURITY DEFINER` + RPCs (`create_campaign_member_invite`, `revoke_campaign_member_invite`, + `preview_campaign_member_invite`, `accept_campaign_member_invite`, + `remove_campaign_member`, `list_campaign_members`, + `list_campaign_member_invites`, `my_campaign_roles`, `campaign_public_team`), + editor RLS helpers and concurrent-removal lock triggers + (`campaigns_check_editor_on_update`, `campaign_children_lock_campaign`, + `campaign_children_verify_insert_auth`), while keeping all money, receiving + accounts, statements, refunds, fulfillment, monthly plans, draft deletion, + `transition_campaign` and team management strictly owner-only, with 172 pgTAP + assertions (#264 / DOS/DOS.Me#1856, on Beta). Migration + `20261129170000_give_campaign_members`. +- Organizer public profile handle and bio: adds `handle` (unique, 3–40-char + lowercase slug with reserved-word check) and `bio` (`<= 500` chars) to + `give.organizers` with authenticated column grants and unchanged + `organizers_reset_verification` so editing `handle`/`bio` preserves + `verification_status`; extends `give.public_organizer` and + `give.public_campaign_organizers` with `handle` and adds + `give.public_organizer_profile` (joining active non-deleted DOS ID avatar) + and `give.list_organizer_public_campaigns` (public campaigns only), with 57 + pgTAP assertions (#261 / DOS/DOS.Me#1851, on Beta). Migration + `20261129160000_give_organizer_public_profile`. +- Campaign comments and comment reporting: `give.campaign_comments` (plain-text + 1–2000 chars, composite FK enforcing one-level replies within the same + campaign) and `give.comment_reports` (6 reason codes, 1 open report per + reporter/comment, 20/24h limit), privacy-safe RLS omitting raw user IDs and + withholding replies under hidden parents from non-moderators, and 10 + `SECURITY DEFINER` RPCs (`list_campaign_comments`, `create_campaign_comment`, + `edit_campaign_comment`, `delete_campaign_comment`, `hide_campaign_comment`, + `report_campaign_comment`, `moderate_campaign_comment`, + `resolve_comment_report`, `list_comment_reports`, + `list_comment_moderation_history`) with rate limiting, self-review guards and + `give.audit_log` entries, with 171 pgTAP assertions (#262 / DOS/DOS.Me#1853, + on Beta). Migration `20261129150000_give_campaign_comments`. +- Privacy-safe daily campaign analytics: zero-PII `give.campaign_daily_analytics` + counters keyed by `(campaign_id, metric_date, event_type, referrer_bucket)`, + `give.normalize_referrer_bucket` (5 fixed buckets with anti-spoofing checks), + service-role `give.record_campaign_event` (public campaigns only) and + authenticated organizer/staff `give.get_campaign_analytics` (zero-filled + daily series, referrer breakdown and ledger-derived conversion/contributions + with cross-day split-payment deduplication), with 99 pgTAP assertions + (#263 / DOS/DOS.Me#1852, on Beta). Migration + `20261129120000_give_campaign_analytics`. - Monthly donation plans A: `give.donation_plans`, `give.plan_stop_tokens`, `campaigns.allow_monthly` (needs `ends_at`), plan donations as ordinary contributions (`plan_id`, `plan_period`, one per month), RPCs diff --git a/README.md b/README.md index 7df092e..9f45285 100644 --- a/README.md +++ b/README.md @@ -117,25 +117,30 @@ links already sent (60 days), set the old value as ## Routes -| Route | Who | What | -| ----------------------------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `/` | everyone | New campaigns and categories. | -| `/campaigns` | everyone | Discovery: filter by type and category, search title and summary. | -| `/campaigns/[slug]` | everyone | Public campaign page with reporting for signed-in visitors (hidden on previews and the organizer’s own campaign); the organizer and staff also see a preview before it is published. | -| `/start` | signed in | Organizer profile, then a new draft. | -| `/me/campaigns` | signed in | The organizer's campaigns. | -| `/me/campaigns/[id]` | the organizer | Editor: content, milestones, cover, submit, cancel, delete draft, updates. | -| `/me/campaigns/[id]/fulfillment` | the owning organizer | Fulfillment for back projects; paid pledges and delivery updates are available only after the project has succeeded. | -| `/admin` | moderators, admins | Review queue (approve, request changes) and organizer verification. | -| `/admin/reports` | moderators, admins | Campaign report queue: ask the organizer, dismiss reports, suspend campaigns or stop payment requests; no self-review. | -| `/api/cron/activate` | Vercel Cron | Activates scheduled campaigns. | -| `/api/cron/finalize-ended` | Vercel Cron | Closes ended give campaigns. | -| `/api/cron/reprocess-inbound` | Vercel Cron | Retries pending inbound events. | -| `/api/cron/issue-plan-donations` | Vercel Cron | Monthly plans: issues each plan's donation for the month (once) and ends plans past the campaign's end; expires past months' unpaid plan donations. | -| `/api/cron/plan-notices` | Vercel Cron | Monthly plans: tells each donor once when a plan ends; second reminders where the account allows them. | -| `/plans/stop`, `/api/plans/stop` | – | Stop link of monthly plan reminders: the page asks first (GET changes nothing); POST, or the one-click `List-Unsubscribe` (RFC 8058), stops the plan. | -| `/media/public/...`, `/media/private/...` | – | Cover images from the private `give-media` bucket, after a visibility check. | -| `/auth/login`, `/auth/callback`, `/auth/logout` | – | DOS.Me login flow. | +| Route | Who | What | +| ----------------------------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `/` | everyone | New campaigns and categories. | +| `/campaigns` | everyone | Discovery: filter by type and category, search title and summary. | +| `/campaigns/[slug]` | everyone | Public campaign page with comments (1-level replies and reporting), public team block when co-organizers are present, and campaign reporting for signed-in visitors (hidden on previews and the organizer’s own campaign); the organizer, accepted co-organizers and staff also see a preview before it is published. | +| `/u/[handle]` | everyone | Public organizer profile (bio, avatar, verification status and public campaigns). | +| `/start` | signed in | Organizer profile, then a new draft. | +| `/me` | signed in | Organizer public profile editor (`handle` and `bio`, preserving verification status). | +| `/me/campaigns` | signed in | The organizer's owned campaigns and accepted co-organizer (editor) campaigns. | +| `/me/campaigns/[id]` | owner / co-organizer | Editor (content, cover, pitch video, milestones, reward tiers, updates); owner-only tabs for `Thống kê` analytics (`?tab=analytics`), `Đội ngũ` co-organizer invites (`?tab=team`), lifecycle actions and money surfaces. | +| `/me/campaigns/[id]/fulfillment` | the owning organizer | Fulfillment for back projects; paid pledges and delivery updates are available only after the project has succeeded. | +| `/invites/[token]` | signed in | Single-use co-organizer invite preview and acceptance (`no-referrer`, `no-store`, `noindex`; guests are prompted to sign in). | +| `/admin` | moderators, admins | Review queue (approve, request changes) and organizer verification. | +| `/admin/reports` | moderators, admins | Campaign report queue: ask the organizer, dismiss reports, suspend campaigns or stop payment requests; no self-review. | +| `/admin/reports/comments` | moderators, admins | Reported campaign comments queue: hide/unhide comments, dismiss reports and view moderation history; no self-review. | +| `/api/analytics/event` | everyone (POST) | Privacy-safe same-origin campaign view and share-click event ingestion (bot-filtered, referrer-sanitized, rate-limited). | +| `/api/cron/activate` | Vercel Cron | Activates scheduled campaigns. | +| `/api/cron/finalize-ended` | Vercel Cron | Closes ended give campaigns. | +| `/api/cron/reprocess-inbound` | Vercel Cron | Retries pending inbound events. | +| `/api/cron/issue-plan-donations` | Vercel Cron | Monthly plans: issues each plan's donation for the month (once) and ends plans past the campaign's end; expires past months' unpaid plan donations. | +| `/api/cron/plan-notices` | Vercel Cron | Monthly plans: tells each donor once when a plan ends; second reminders where the account allows them. | +| `/plans/stop`, `/api/plans/stop` | – | Stop link of monthly plan reminders: the page asks first (GET changes nothing); POST, or the one-click `List-Unsubscribe` (RFC 8058), stops the plan. | +| `/media/public/...`, `/media/private/...` | – | Cover images from the private `give-media` bucket, after a visibility check. | +| `/auth/login`, `/auth/callback`, `/auth/logout` | – | DOS.Me login flow. | ## Security model diff --git a/apps/web/src/lib/analytics.test.ts b/apps/web/src/lib/analytics.test.ts index 2cc8d99..2fd4cc7 100644 --- a/apps/web/src/lib/analytics.test.ts +++ b/apps/web/src/lib/analytics.test.ts @@ -143,6 +143,9 @@ describe("analytics formatting and query helpers", () => { expect(referrerLabel("google")).toBe("Google") expect(referrerLabel("other")).toBe("Nguồn khác") expect(referrerLabel("unknown-bucket")).toBe("Nguồn khác") + expect(referrerLabel("toString")).toBe("Nguồn khác") + expect(referrerLabel("constructor")).toBe("Nguồn khác") + expect(referrerLabel("__proto__")).toBe("Nguồn khác") }) it("parses and fetches campaign analytics payload via get_campaign_analytics RPC", async () => { diff --git a/apps/web/src/lib/analytics.ts b/apps/web/src/lib/analytics.ts index e3d9d62..b24639a 100644 --- a/apps/web/src/lib/analytics.ts +++ b/apps/web/src/lib/analytics.ts @@ -117,7 +117,7 @@ export function formatAnalyticsShortDate(dateStr: string): string { } export function referrerLabel(bucket: string): string { - if (bucket in REFERRER_LABELS) return REFERRER_LABELS[bucket as ReferrerBucket] + if (Object.hasOwn(REFERRER_LABELS, bucket)) return REFERRER_LABELS[bucket as ReferrerBucket] return REFERRER_LABELS.other } diff --git a/apps/web/src/lib/campaign-members.test.ts b/apps/web/src/lib/campaign-members.test.ts index 0b09b4a..7b72152 100644 --- a/apps/web/src/lib/campaign-members.test.ts +++ b/apps/web/src/lib/campaign-members.test.ts @@ -57,14 +57,19 @@ describe("campaign-members pure helpers", () => { expect(isInvitableStatus("suspended")).toBe(false) }) - it("neutralizes missing, blank, or DB 'Co-organizer' fallback display names", () => { + it("neutralizes missing, blank, or DB 'Organizer' / 'Co-organizer' fallback display names", () => { expect(memberDisplayName("Minh Anh", "editor")).toBe("Minh Anh") expect(memberDisplayName("Co-organizer", "editor")).toBe(CO_ORGANIZER_FALLBACK_NAME) expect(memberDisplayName(" co-organizer ", "editor")).toBe(CO_ORGANIZER_FALLBACK_NAME) + expect(memberDisplayName("Organizer", "owner")).toBe(OWNER_FALLBACK_NAME) + expect(memberDisplayName(" organizer ", "owner")).toBe(OWNER_FALLBACK_NAME) + expect(memberDisplayName("ORGANIZER", "owner")).toBe(OWNER_FALLBACK_NAME) + expect(memberDisplayName("Organizer", "editor")).toBe(CO_ORGANIZER_FALLBACK_NAME) expect(memberDisplayName(null, "editor")).toBe(CO_ORGANIZER_FALLBACK_NAME) expect(memberDisplayName(" ", "owner")).toBe(OWNER_FALLBACK_NAME) expect(memberInitial("đặng văn bình", "editor")).toBe("Đ") expect(memberInitial(null, "editor")).toBe("Đ") + expect(memberInitial("Organizer", "owner")).toBe("N") }) it("allows only clean public https:// avatar URLs without credentials, private hosts, IP literals, or control chars", () => { diff --git a/apps/web/src/lib/campaign-members.ts b/apps/web/src/lib/campaign-members.ts index 442457f..6002ee6 100644 --- a/apps/web/src/lib/campaign-members.ts +++ b/apps/web/src/lib/campaign-members.ts @@ -136,11 +136,12 @@ export function invitePath(token: string): string { /** * Neutral Vietnamese display name fallback. The database suppresses deleted or - * inactive accounts to `'Co-organizer'` or `NULL` so zero PII leaks. + * inactive accounts to `'Organizer'`, `'Co-organizer'`, or `NULL` so zero PII leaks. */ export function memberDisplayName(displayName: string | null | undefined, role: CampaignMemberRole = "editor"): string { const trimmed = displayName?.trim() - if (!trimmed || trimmed.toLowerCase() === "co-organizer") { + const lower = trimmed?.toLowerCase() + if (!trimmed || lower === "co-organizer" || lower === "organizer") { return role === "owner" ? OWNER_FALLBACK_NAME : CO_ORGANIZER_FALLBACK_NAME } return trimmed