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:
adilallo committed 2026-11-09 19:54:04 -07:00
1 parent 642551064c
commit 5cbda35e32
50 files changed
+2429 -219

No files matched your search

+22 -16
View File
@@ -8,9 +8,11 @@ import {
notFound,
unauthorized,
} from "../../../../lib/server/responses";
import { getPublicPublishedRuleById } from "../../../../lib/server/publishedRules";
import { getReadablePublishedRule } from "../../../../lib/server/publishedRules";
import { getSessionUser } from "../../../../lib/server/session";
import { apiRoute } from "../../../../lib/server/apiRoute";
import { deleteUploadsForRule } from "../../../../lib/server/uploads/deleteUploadedFiles";
import { linkUploadsToRule } from "../../../../lib/server/uploads/linkUploads";
import { publishRuleBodySchema } from "../../../../lib/server/validation/createFlowSchemas";
import { readLimitedJson } from "../../../../lib/server/validation/requestBody";
import { jsonFromZodError } from "../../../../lib/server/validation/zodHttp";
@@ -19,29 +21,27 @@ type RouteContext = { params: Promise<{ id: string }> };
export const GET = apiRoute<RouteContext>(
"rules.byId",
async (_request, context) => {
async (request, context) => {
if (!isDatabaseConfigured()) {
return dbUnavailable();
}
const { id } = await context.params;
const rule = await getPublicPublishedRuleById(id);
if (!rule) {
const user = await getSessionUser();
const resolved = await getReadablePublishedRule({
idOrSlug: id,
user,
viaShareSlug: false,
requestPath: request.nextUrl.pathname,
});
if (!resolved) {
return notFound();
}
const user = await getSessionUser();
let viewerIsOwner = false;
if (user) {
const ownerRow = await prisma.publishedRule.findUnique({
where: { id },
select: { userId: true },
});
viewerIsOwner = ownerRow?.userId === user.id;
}
return NextResponse.json({ rule, viewerIsOwner });
return NextResponse.json({
rule: resolved.rule,
viewerIsOwner: resolved.viewerIsOwner,
});
},
);
@@ -90,6 +90,11 @@ export const PATCH = apiRoute<RouteContext>(
document: document as Prisma.InputJsonValue,
},
});
await linkUploadsToRule({
ruleId: row.id,
document,
userId: user.id,
});
return NextResponse.json({ ok: true });
},
@@ -120,6 +125,7 @@ export const DELETE = apiRoute<RouteContext>(
return forbidden("You do not have permission to delete this rule");
}
await deleteUploadsForRule(row.id);
await prisma.publishedRule.delete({ where: { id: row.id } });
return NextResponse.json({ ok: true });