feat: forum, polymorphic comments, custom tiers, multi-invite, secrets encryption
Big feature batch driven by the super-audit findings and the user's follow-up requests. Schema migration 021 (folded into schema.sql Section 13): - forum_threads + polymorphic comments table keyed on (entity_type, entity_id). Entity types: forum_thread, proposal, incident, policy. Trigger maintains forum_threads.comment_count and last_comment_at. - space_tiers per-space with monthly_price_cents, billing_cadence, is_system, sort_order. Trigger seeds plus/basic/associate on every space INSERT and backfills existing spaces. space_members.tier_id FK added and backfilled from the legacy enum value. - space_role_labels (rename/recolor built-in roles per space). space_custom_roles + space_member_custom_roles for non-privileged extra labels. RLS gates by admin/board. - space_invites: multi-code invites with expires_at, max_uses, uses_count, is_enabled. Legacy spaces.invite_code backfilled as a permanent enabled invite. - secrets.encrypted_value bytea + encryption_version. Secrets RLS tightened. New comms_channels INSERT policy: any member can create; default channels are protected from deletion. - knowledge_base.render_markdown boolean (default true). Secrets encryption-at-rest: - AES-256-GCM in lib/secrets/crypto.ts. Master key from SECRETS_ENCRYPTION_KEY env (64 hex chars). - New revealSecret(id) server action: only path to plaintext, writes secret.revealed to activity_log. - /ops/page.tsx no longer selects value or encrypted_value on the list endpoint - the original screenshot bug where ciphertext was already in the page bundle before "Reveal" is fixed. UI: - /forum index, /forum/new, /forum/[id]. Pin/lock/delete actions for admin/board. - CommentThread component embedded on /proposals/[id], /incidents/[id], /policies/[slug]. Markdown rendering via react-markdown + remark-gfm. - /comms sidebar: inline "+ New channel" form. - /ops KB: row click opens markdown-rendering viewer modal. - /settings: new Tiers tab and Invites tab. Inline price edit and archive/delete on tiers; copy/enable/disable/delete on invites. - AtlasLogo replaces the terminal icon on the landing nav and footer. public/logo.svg wired as the favicon in app/layout.tsx metadata. - Sidebar has a Forum nav link. Server actions added: - lib/actions/forum.ts, comms.ts, tiers.ts, roles.ts, invites.ts. - lib/actions/secrets.ts rewritten with updateSecret + revealSecret. Auth flow: - joinSpace honors codes from space_invites first (enabled, expiry, use cap), falls back to legacy spaces.invite_code, increments uses_count on success. Env: - SECRETS_ENCRYPTION_KEY documented in .env.example and set on the Droplet's /opt/hackerspace-ops/.env.production. README: live site link added (https://hackerspace.sh). 266/266 unit tests pass. Production build clean. Migration 021 will be applied on the next deploy via /opt/hackerspace-ops/deploy.sh's idempotent migration runner.
This commit is contained in:
@@ -160,6 +160,14 @@ export const createSecretSchema = z.object({
|
||||
icon: z.string().max(10).optional().nullable(),
|
||||
})
|
||||
|
||||
export const updateSecretSchema = z.object({
|
||||
title: z.string().min(1).max(200).optional(),
|
||||
value: z.string().min(1).max(5000).optional(),
|
||||
description: z.string().max(500).optional().nullable(),
|
||||
area: z.string().max(100).optional().nullable(),
|
||||
icon: z.string().max(10).optional().nullable(),
|
||||
})
|
||||
|
||||
// ─── Payments ────────────────────────────────────────────────────────────────
|
||||
|
||||
export const logCashPaymentSchema = z.object({
|
||||
@@ -363,6 +371,97 @@ export const updateAreaSchema = z.object({
|
||||
is_archived: z.boolean().optional(),
|
||||
})
|
||||
|
||||
// ─── Forum, comments, tiers, roles, invites ──────────────────────────────────
|
||||
|
||||
export const createForumThreadSchema = z.object({
|
||||
title: z.string().min(1, 'Title is required').max(200),
|
||||
body: z.string().max(20000).optional().nullable(),
|
||||
category: z.string().min(1).max(50).optional(),
|
||||
})
|
||||
|
||||
export const updateForumThreadSchema = z.object({
|
||||
title: z.string().min(1).max(200).optional(),
|
||||
body: z.string().max(20000).optional().nullable(),
|
||||
category: z.string().min(1).max(50).optional(),
|
||||
pinned: z.boolean().optional(),
|
||||
locked: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const commentEntityTypeSchema = z.enum(['forum_thread', 'proposal', 'incident', 'policy'])
|
||||
|
||||
export const createCommentSchema = z.object({
|
||||
entity_type: commentEntityTypeSchema,
|
||||
entity_id: z.string().uuid('Invalid entity ID'),
|
||||
body: z.string().min(1, 'Comment is required').max(10000),
|
||||
parent_id: z.string().uuid().optional().nullable(),
|
||||
})
|
||||
|
||||
export const updateCommentSchema = z.object({
|
||||
body: z.string().min(1).max(10000),
|
||||
})
|
||||
|
||||
export const createTierSchema = z.object({
|
||||
slug: z.string().min(1).max(50).regex(/^[a-z0-9][a-z0-9_-]{0,49}$/, 'Slug must be lowercase letters, numbers, _ or -'),
|
||||
name: z.string().min(1).max(100),
|
||||
description: z.string().max(2000).optional().nullable(),
|
||||
monthly_price_cents: z.number().int().min(0).max(100_000_000),
|
||||
billing_cadence: z.enum(['monthly', 'quarterly', 'annual', 'one_time', 'custom']).default('monthly'),
|
||||
sort_order: z.number().int().min(0).max(100000).optional(),
|
||||
})
|
||||
|
||||
export const updateTierSchema = z.object({
|
||||
name: z.string().min(1).max(100).optional(),
|
||||
description: z.string().max(2000).optional().nullable(),
|
||||
monthly_price_cents: z.number().int().min(0).max(100_000_000).optional(),
|
||||
billing_cadence: z.enum(['monthly', 'quarterly', 'annual', 'one_time', 'custom']).optional(),
|
||||
sort_order: z.number().int().min(0).max(100000).optional(),
|
||||
is_archived: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const upsertRoleLabelSchema = z.object({
|
||||
role: z.enum(['admin', 'board', 'treasurer', 'member', 'associate']),
|
||||
display_name: z.string().max(100).optional().nullable(),
|
||||
description: z.string().max(500).optional().nullable(),
|
||||
color: z.string().max(20).optional().nullable(),
|
||||
sort_order: z.number().int().min(0).max(100000).optional(),
|
||||
})
|
||||
|
||||
export const createCustomRoleSchema = z.object({
|
||||
slug: z.string().min(1).max(50).regex(/^[a-z0-9][a-z0-9_-]{0,49}$/, 'Slug must be lowercase letters, numbers, _ or -'),
|
||||
name: z.string().min(1).max(100),
|
||||
description: z.string().max(500).optional().nullable(),
|
||||
color: z.string().max(20).optional().nullable(),
|
||||
sort_order: z.number().int().min(0).max(100000).optional(),
|
||||
})
|
||||
|
||||
export const updateCustomRoleSchema = z.object({
|
||||
name: z.string().min(1).max(100).optional(),
|
||||
description: z.string().max(500).optional().nullable(),
|
||||
color: z.string().max(20).optional().nullable(),
|
||||
sort_order: z.number().int().min(0).max(100000).optional(),
|
||||
})
|
||||
|
||||
export const createInviteSchema = z.object({
|
||||
code: z.string().min(4).max(32).regex(/^[A-Z0-9-]+$/, 'Code must be uppercase letters, numbers, or hyphens').optional(),
|
||||
label: z.string().max(100).optional().nullable(),
|
||||
expires_at: flexibleDateTime(),
|
||||
max_uses: z.number().int().min(1).max(100000).optional().nullable(),
|
||||
is_enabled: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const updateInviteSchema = z.object({
|
||||
label: z.string().max(100).optional().nullable(),
|
||||
expires_at: flexibleDateTime(),
|
||||
max_uses: z.number().int().min(1).max(100000).optional().nullable(),
|
||||
is_enabled: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const createChannelSchema = z.object({
|
||||
name: z.string().min(1).max(50).regex(/^[a-z0-9][a-z0-9-]{0,49}$/, 'Channel names must be lowercase letters, numbers, or hyphens'),
|
||||
description: z.string().max(500).optional().nullable(),
|
||||
channel_type: z.enum(['general', 'area', 'ops', 'project']).default('general'),
|
||||
})
|
||||
|
||||
// ─── Generic ID schemas ──────────────────────────────────────────────────────
|
||||
|
||||
export const uuidSchema = z.string().uuid('Invalid ID format')
|
||||
|
||||
Reference in New Issue
Block a user