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,111 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
RULE_VISIBILITY,
|
||||
canReadPublishedRule,
|
||||
isListedPublishedRule,
|
||||
isPrivilegedAdminRead,
|
||||
type PublishedRuleReadAccess,
|
||||
} from "../../lib/ruleVisibility";
|
||||
|
||||
function access(
|
||||
overrides: Partial<PublishedRuleReadAccess> = {},
|
||||
): PublishedRuleReadAccess {
|
||||
return {
|
||||
visibility: RULE_VISIBILITY.private,
|
||||
viaShareSlug: false,
|
||||
userId: null,
|
||||
ownerUserId: "owner-1",
|
||||
viewerEmail: null,
|
||||
invitedEmails: [],
|
||||
invitedUserIds: [],
|
||||
isAdmin: false,
|
||||
holdsGuestClaim: false,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("isListedPublishedRule", () => {
|
||||
it("lists only public and featured Rules", () => {
|
||||
expect(
|
||||
isListedPublishedRule({ visibility: RULE_VISIBILITY.private }),
|
||||
).toBe(false);
|
||||
expect(
|
||||
isListedPublishedRule({ visibility: RULE_VISIBILITY.shared_by_link }),
|
||||
).toBe(false);
|
||||
expect(
|
||||
isListedPublishedRule({
|
||||
visibility: RULE_VISIBILITY.public_and_featured,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("canReadPublishedRule", () => {
|
||||
it("lets the owner, invited people, guest claim, and named admins read a private Rule", () => {
|
||||
expect(canReadPublishedRule(access())).toBe(false);
|
||||
expect(canReadPublishedRule(access({ userId: "owner-1" }))).toBe(true);
|
||||
expect(
|
||||
canReadPublishedRule(
|
||||
access({ viewerEmail: "rosa@example.org", invitedEmails: ["rosa@example.org"] }),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
canReadPublishedRule(access({ userId: "u-2", invitedUserIds: ["u-2"] })),
|
||||
).toBe(true);
|
||||
expect(canReadPublishedRule(access({ holdsGuestClaim: true }))).toBe(true);
|
||||
expect(canReadPublishedRule(access({ isAdmin: true }))).toBe(true);
|
||||
});
|
||||
|
||||
it("lets anyone with the rotating slug read a shared-by-link Rule", () => {
|
||||
expect(
|
||||
canReadPublishedRule(
|
||||
access({
|
||||
visibility: RULE_VISIBILITY.shared_by_link,
|
||||
viaShareSlug: true,
|
||||
}),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
canReadPublishedRule(
|
||||
access({
|
||||
visibility: RULE_VISIBILITY.shared_by_link,
|
||||
viaShareSlug: false,
|
||||
}),
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("lets anyone read a public and featured Rule", () => {
|
||||
expect(
|
||||
canReadPublishedRule(
|
||||
access({ visibility: RULE_VISIBILITY.public_and_featured }),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isPrivilegedAdminRead", () => {
|
||||
it("is true only when a named admin would otherwise be denied", () => {
|
||||
expect(isPrivilegedAdminRead(access({ isAdmin: true }))).toBe(true);
|
||||
expect(
|
||||
isPrivilegedAdminRead(access({ isAdmin: true, userId: "owner-1" })),
|
||||
).toBe(false);
|
||||
expect(
|
||||
isPrivilegedAdminRead(
|
||||
access({
|
||||
isAdmin: true,
|
||||
visibility: RULE_VISIBILITY.public_and_featured,
|
||||
}),
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
isPrivilegedAdminRead(
|
||||
access({
|
||||
isAdmin: true,
|
||||
visibility: RULE_VISIBILITY.shared_by_link,
|
||||
viaShareSlug: true,
|
||||
}),
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user