Keep shared Rule files reachable, and say when a privacy change does not save.

This commit is contained in:
adilallo committed 2026-11-09 20:05:06 -07:00
1 parent b6795c1f18
commit 63ba21c614
9 files changed
+148 -16

No files matched your search

+18 -13
View File
@@ -133,30 +133,35 @@ async function resolveAccessForRow(opts: {
/**
* Fetch a published rule the viewer is allowed to read.
*
* Lookup is by internal id unless `viaShareSlug` is set. Shared-by-link
* strangers must use the rotating slug so turning the link off invalidates it.
* Returns `null` for missing rows, denied readers, and DB failures — callers
* render the same 404 as a missing Rule.
* Lookup is by internal id unless `viaShareSlug` is set. Pass `lookup: "id"`
* when the caller already has the Rule id but link visitors should still
* count as readers (file URLs on a shared Rule). Shared-by-link strangers
* opening the Rule itself must use the rotating slug so turning the link off
* invalidates it. Returns `null` for missing rows, denied readers, and DB
* failures — callers render the same 404 as a missing Rule.
*/
export async function getReadablePublishedRule(opts: {
idOrSlug: string;
user: User | null;
viaShareSlug: boolean;
requestPath: string;
lookup?: "id" | "shareSlug";
}): Promise<ReadablePublishedRule | null> {
if (!isDatabaseConfigured()) return null;
const idOrSlug = opts.idOrSlug.trim();
if (idOrSlug.length === 0) return null;
const lookup = opts.lookup ?? (opts.viaShareSlug ? "shareSlug" : "id");
try {
const row = opts.viaShareSlug
? await prisma.publishedRule.findUnique({
where: { shareSlug: idOrSlug },
select: RULE_ACCESS_SELECT,
})
: await prisma.publishedRule.findUnique({
where: { id: idOrSlug },
select: RULE_ACCESS_SELECT,
});
const row =
lookup === "shareSlug"
? await prisma.publishedRule.findUnique({
where: { shareSlug: idOrSlug },
select: RULE_ACCESS_SELECT,
})
: await prisma.publishedRule.findUnique({
where: { id: idOrSlug },
select: RULE_ACCESS_SELECT,
});
if (!row) return null;
return resolveAccessForRow({
row,