Start every Rule private, with a rotating link and files that follow its readers.
New Rules stay off lists until the person who holds the pen turns on a share link, or the team features one. Uploaded files are readable only by those readers, stripped of location metadata, and deleted with the Rule, draft, or account.
This commit is contained in:
1 parent
642551064c
commit
5cbda35e32
50 files changed
+2429
-219
No files matched your search
@@ -0,0 +1,112 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "RuleVisibility" AS ENUM ('private', 'shared_by_link', 'public_and_featured');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "PublishedRule" ADD COLUMN "visibility" "RuleVisibility" NOT NULL DEFAULT 'private';
|
||||
ALTER TABLE "PublishedRule" ADD COLUMN "shareSlug" TEXT;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "PublishedRule_shareSlug_key" ON "PublishedRule"("shareSlug");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "PublishedRule_visibility_updatedAt_idx" ON "PublishedRule"("visibility", "updatedAt");
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "PublishedRule" DROP CONSTRAINT "PublishedRule_userId_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "PublishedRule" ADD CONSTRAINT "PublishedRule_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- Pilot Rules with written consent are public and featured; every other Rule stays private.
|
||||
UPDATE "PublishedRule"
|
||||
SET visibility = 'public_and_featured'
|
||||
WHERE title IN (
|
||||
'Mutual Aid Colorado',
|
||||
'Food Not Bombs Boulder',
|
||||
'Boulder Street Medics'
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Upload" (
|
||||
"id" TEXT NOT NULL,
|
||||
"mimeType" TEXT NOT NULL,
|
||||
"byteLength" INTEGER NOT NULL,
|
||||
"purpose" TEXT NOT NULL,
|
||||
"userId" TEXT,
|
||||
"draftId" TEXT,
|
||||
"ruleId" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "Upload_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Upload_ruleId_idx" ON "Upload"("ruleId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Upload_draftId_idx" ON "Upload"("draftId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Upload_userId_idx" ON "Upload"("userId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Upload" ADD CONSTRAINT "Upload_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Upload" ADD CONSTRAINT "Upload_draftId_fkey" FOREIGN KEY ("draftId") REFERENCES "RuleDraft"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Upload" ADD CONSTRAINT "Upload_ruleId_fkey" FOREIGN KEY ("ruleId") REFERENCES "PublishedRule"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- Backfill upload rows from links already stored in published documents.
|
||||
INSERT INTO "Upload" ("id", "mimeType", "byteLength", "purpose", "ruleId", "createdAt")
|
||||
SELECT DISTINCT
|
||||
lower(m[1]),
|
||||
'application/octet-stream',
|
||||
0,
|
||||
'backfill',
|
||||
r.id,
|
||||
CURRENT_TIMESTAMP
|
||||
FROM "PublishedRule" r,
|
||||
LATERAL regexp_matches(
|
||||
r.document::text,
|
||||
'/api/uploads/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})',
|
||||
'g'
|
||||
) AS m
|
||||
ON CONFLICT ("id") DO UPDATE SET
|
||||
"ruleId" = EXCLUDED."ruleId";
|
||||
|
||||
-- Backfill upload rows from links already stored in drafts (skip ids already tied to a Rule).
|
||||
INSERT INTO "Upload" ("id", "mimeType", "byteLength", "purpose", "draftId", "createdAt")
|
||||
SELECT DISTINCT
|
||||
lower(m[1]),
|
||||
'application/octet-stream',
|
||||
0,
|
||||
'backfill',
|
||||
d.id,
|
||||
CURRENT_TIMESTAMP
|
||||
FROM "RuleDraft" d,
|
||||
LATERAL regexp_matches(
|
||||
d.payload::text,
|
||||
'/api/uploads/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})',
|
||||
'g'
|
||||
) AS m
|
||||
ON CONFLICT ("id") DO NOTHING;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "AdminRuleReadLog" (
|
||||
"id" TEXT NOT NULL,
|
||||
"ruleId" TEXT NOT NULL,
|
||||
"adminEmail" TEXT NOT NULL,
|
||||
"adminUserId" TEXT,
|
||||
"path" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "AdminRuleReadLog_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AdminRuleReadLog_ruleId_createdAt_idx" ON "AdminRuleReadLog"("ruleId", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AdminRuleReadLog_adminEmail_createdAt_idx" ON "AdminRuleReadLog"("adminEmail", "createdAt");
|
||||
+47
-1
@@ -16,6 +16,7 @@ model User {
|
||||
sessions Session[]
|
||||
draft RuleDraft?
|
||||
rules PublishedRule[]
|
||||
uploads Upload[]
|
||||
/// At most one pending verified email change (CR-103).
|
||||
emailChangeToken EmailChangeToken?
|
||||
/// Rules this user was invited to as a stakeholder (after accepting invite).
|
||||
@@ -68,12 +69,19 @@ model RuleDraft {
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
payload Json
|
||||
updatedAt DateTime @updatedAt
|
||||
uploads Upload[]
|
||||
}
|
||||
|
||||
enum RuleVisibility {
|
||||
private
|
||||
shared_by_link
|
||||
public_and_featured
|
||||
}
|
||||
|
||||
model PublishedRule {
|
||||
id String @id @default(cuid())
|
||||
userId String?
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
title String
|
||||
summary String?
|
||||
document Json
|
||||
@@ -82,10 +90,48 @@ model PublishedRule {
|
||||
/// Hashed one-time secret so the publishing browser can claim this row on sign-in.
|
||||
/// Null for owned publishes and after a successful claim.
|
||||
claimTokenHash String? @unique
|
||||
/// Who can read this Rule. New rows start private.
|
||||
visibility RuleVisibility @default(private)
|
||||
/// Rotating public path `/r/{shareSlug}`. Null while private. Replaced when a link is turned back on.
|
||||
shareSlug String? @unique
|
||||
|
||||
stakeholders RuleStakeholder[]
|
||||
uploads Upload[]
|
||||
|
||||
@@index([userId])
|
||||
@@index([visibility, updatedAt])
|
||||
}
|
||||
|
||||
/// File written under UPLOAD_ROOT. Readers follow the linked Rule or draft.
|
||||
model Upload {
|
||||
id String @id
|
||||
mimeType String
|
||||
byteLength Int
|
||||
purpose String
|
||||
userId String?
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
||||
draftId String?
|
||||
draft RuleDraft? @relation(fields: [draftId], references: [id], onDelete: Cascade)
|
||||
ruleId String?
|
||||
rule PublishedRule? @relation(fields: [ruleId], references: [id], onDelete: Cascade)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([ruleId])
|
||||
@@index([draftId])
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
/// Named-admin reads of Rules they do not already hold the pen for or belong to.
|
||||
model AdminRuleReadLog {
|
||||
id String @id @default(cuid())
|
||||
ruleId String
|
||||
adminEmail String
|
||||
adminUserId String?
|
||||
path String
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([ruleId, createdAt])
|
||||
@@index([adminEmail, createdAt])
|
||||
}
|
||||
|
||||
/// Invite + access for a published rule: email invite at publish; userId set after magic-link-style accept.
|
||||
|
||||
Reference in new issue
Block a user