Open History to see the last commit
1import { type EnvironmentId, managedCapabilityDenial } from "@t3tools/contracts";
2import { Atom } from "effect/reactivity";
3
4import { environmentPresentations } from "~/state/presentation";
5import { serverEnvironment } from "~/state/server";
6
7/**
8 * Whether this environment offers "Share with guest": the user may create links there, and its
9 * Guest links beta is on (Settings > Labs). The server refuses links while the beta is off.
10 * Guests arrive through T3 Connect, so a policy that turns Connect off hides sharing too.
11 */
12export const canShareWithGuestAtom = Atom.family((environmentId: EnvironmentId) =>
13 Atom.make((get) => {
14 const serverConfig = get(environmentPresentations.serverConfigsAtom).get(environmentId);
15 return (
16 get(serverEnvironment.createGuestShare.permissionAtom(environmentId)) &&
17 serverConfig?.settings.guestSharingEnabled === true &&
18 managedCapabilityDenial(serverConfig.managedPolicy, "connect") === undefined
19 );
20 }).pipe(Atom.withLabel(`guest-share:available:${environmentId}`)),
21);