Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

♻️ Centralize deployment-mode behavior in capabilities and instance policy (#3147)

Luke Vella95979adff92f
diff --git a/CLAUDE.md b/CLAUDE.md
index 89ecc7ec7..a68523b43 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -106,6 +106,10 @@ pnpm sherif # Check package dependencies
- **Cloud Hosted**: Full SaaS with Stripe billing on Vercel
- **Self Hosted**: Docker-based deployment without billing features
- Environment variable `NEXT_PUBLIC_SELF_HOSTED=true` toggles features
+- **Every cloud vs self-hosted behavior difference lives in one of two files, one line per field with the reason on the line, so the files are the inventory:**
+ - **Capabilities** ("can this instance do X?") — `lib/feature-flags/config.ts` (`featureFlagConfig`, `isFeatureEnabled` server-side, `useFeatureFlag` client-side). Behavior forks key on a capability such as `billing`, never on `isSelfHosted` directly; "no billing ⇒ every paid feature is on" is derived once in `features/billing/utils.ts` (`resolveSpaceTier`).
+ - **Policies** ("what does this instance's org decide for its spaces?") — `features/instance-policy/` (`deriveInstancePolicy` in `utils.ts` is the inventory; `getInstancePolicy` from `data.ts` for server code, `loadInstancePolicy` from `loaders.ts` for pages, `useInstancePolicy` from `client.tsx`). When the organization layer lands this becomes the org's policy with the same field names.
+ - `isSelfHosted` is for infrastructure wiring (Stripe webhook, licensing routes, updates route, storage). A few legacy product forks still key on it directly (account deletion mode, control panel footer links, the cookie banner link, API access, the guest poll upsell); they shrink toward zero and are never a precedent. A new `isSelfHosted` product fork is a review blocker: add a capability or policy field instead.
## Testing
diff --git a/apps/docs/spaces/collaboration.mdx b/apps/docs/spaces/collaboration.mdx
index 30022b4ab..1639a8790 100644
--- a/apps/docs/spaces/collaboration.mdx
+++ b/apps/docs/spaces/collaboration.mdx
@@ -36,6 +36,10 @@ Turning collaboration on gives members access to everything already in the space
Collaboration is a Pro feature. You can turn it off at any time, but turning it on requires an active Pro subscription.
+<Note>
+On self-hosted instances collaboration is always on and the setting is not shown. The instance is already the boundary of your organization, so adding someone to a space is how you work together.
+</Note>
+
## What it affects
Collaboration controls visibility between members inside the space: polls, events, and anything else created in it.
diff --git a/apps/docs/spaces/introduction.mdx b/apps/docs/spaces/introduction.mdx
index 21dc23735..5609d6828 100644
--- a/apps/docs/spaces/introduction.mdx
+++ b/apps/docs/spaces/introduction.mdx
@@ -10,7 +10,7 @@ Spaces are Rallly's solution for team and organizational collaboration. Instead
<Card title="Key Benefits" icon="rocket">
- **Centralized Billing**: One subscription covers all team members
- - **Optional Collaboration**: Choose whether members work together or keep their scheduling private
+ - **Optional Collaboration**: Choose whether members work together or keep their scheduling private (on Rallly Cloud; self-hosted spaces always work together)
- **Member Management**: Invite and manage team members from one place
- **Seat-Based Pricing**: Pay only for the seats you need and scale as you grow
</Card>
diff --git a/apps/web/src/app/[locale]/(optional-space)/layout.tsx b/apps/web/src/app/[locale]/(optional-space)/layout.tsx
index d99c9e42e..2d6640da4 100644
--- a/apps/web/src/app/[locale]/(optional-space)/layout.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/layout.tsx
@@ -3,13 +3,13 @@ import { RouterLoadingIndicator } from "@/components/router-loading-indicator";
import { SessionRefresher } from "@/components/session-refresher";
import { TierProvider } from "@/features/billing/client";
import { PayWall } from "@/features/billing/components/pay-wall";
+import { resolveSpaceTier } from "@/features/billing/utils";
import { isQuickCreateEnabled } from "@/features/quick-create/constants";
import { getActiveSpaceForUser } from "@/features/space/data";
import { UserProvider } from "@/features/user/client";
import { requireUser } from "@/features/user/loaders";
import { getLocale } from "@/i18n/server/get-locale";
import { getSession } from "@/lib/auth";
-import { isSelfHosted } from "@/lib/constants";
import { DeviceDateTimeProvider } from "@/lib/datetime/device";
import { getDeviceDateTimeConfig } from "@/lib/datetime/server";
@@ -31,7 +31,8 @@ async function OptionalSpaceGate({ children }: { children: React.ReactNode }) {
const space =
user && !user.isGuest ? await getActiveSpaceForUser(user.id) : null;
- const tier = space?.tier ?? (isSelfHosted ? "pro" : "hobby");
+ // Guests have no space; they get whatever an unpaid space resolves to
+ const tier = space?.tier ?? resolveSpaceTier("hobby");
return (
<>
diff --git a/apps/web/src/app/[locale]/(optional-space)/new/page.tsx b/apps/web/src/app/[locale]/(optional-space)/new/page.tsx
index d5708f000..bee968bb5 100644
--- a/apps/web/src/app/[locale]/(optional-space)/new/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/new/page.tsx
@@ -11,7 +11,7 @@ import type { Metadata } from "next";
import Link from "next/link";
import { redirect } from "next/navigation";
import { BrandStyle } from "@/features/branding/components/brand-style";
-import { loadSpaceBrandingAllowed } from "@/features/branding/loaders";
+import { loadInstancePolicy } from "@/features/instance-policy/loaders";
import { CreatePoll } from "@/features/poll/components/create-poll";
import { getActiveSpaceForUser } from "@/features/space/data";
import { Trans } from "@/i18n/client";
@@ -32,7 +32,7 @@ export default async function Page() {
const primaryColor =
space?.showBranding &&
space.primaryColor &&
- (await loadSpaceBrandingAllowed())
+ (await loadInstancePolicy()).spaceBrandingAllowed
? space.primaryColor
: null;
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/members/members-page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/members/members-page.tsx
index f025bd977..fc4e3abda 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/members/members-page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/members/members-page.tsx
@@ -8,7 +8,6 @@ import {
import { Badge } from "@rallly/ui/badge";
import { InfoIcon, SparklesIcon } from "lucide-react";
import Link from "next/link";
-import { IfCloudHosted, IfSelfHosted } from "@/components/environment";
import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
import { PageHeaderActions } from "@/components/page-layout";
import { StackedList, StackedListItem } from "@/components/stacked-list";
@@ -23,6 +22,7 @@ import {
import { requireUser } from "@/features/user/loaders";
import { Trans } from "@/i18n/client";
import { IfFeatureEnabled } from "@/lib/feature-flags/client";
+import { isFeatureEnabled } from "@/lib/feature-flags/server";
import { InviteMemberButton } from "./components/invite-member-button";
import { MemberDropdownMenu } from "./components/member-dropdown-menu";
import { PendingInvites } from "./components/pending-invites";
@@ -92,7 +92,7 @@ export async function MembersPageContent() {
<Alert variant="info">
<InfoIcon />
<AlertDescription>
- <IfCloudHosted>
+ {isFeatureEnabled("billing") ? (
<p>
<Trans
i18nKey="noSeatsAvailableAlertBillingDescription"
@@ -107,8 +107,7 @@ export async function MembersPageContent() {
}}
/>
</p>
- </IfCloudHosted>
- <IfSelfHosted>
+ ) : (
<p>
<Trans
i18nKey="noSeatsAvailableAlertSelfHostedDescription"
@@ -124,7 +123,7 @@ export async function MembersPageContent() {
}}
/>
</p>
- </IfSelfHosted>
+ )}
</AlertDescription>
</Alert>
) : null}
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
index 6dc44aa29..59b47522b 100644
--- a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
@@ -15,7 +15,6 @@ import { Switch } from "@rallly/ui/switch";
import { LockIcon } from "lucide-react";
import React from "react";
import { ColorPickerWithSaveButton } from "@/components/color-picker-with-save-button";
-import { IfCloudHosted } from "@/components/environment";
import {
PageSection,
PageSectionContent,
@@ -25,8 +24,8 @@ import {
} from "@/components/page-layout";
import { showPayWall, useIsFree } from "@/features/billing/client";
import { ProBadge } from "@/features/billing/components/pro-badge";
-import { useBranding } from "@/features/branding/client";
import { DEFAULT_PRIMARY_COLOR } from "@/features/branding/constants";
+import { useInstancePolicy } from "@/features/instance-policy/client";
import {
updateSpaceAction,
updateSpaceShowBrandingAction,
@@ -47,7 +46,8 @@ export function CustomBrandingSection({
const { data: space } = useSpace();
const user = useAuthedUser();
const isFree = useIsFree();
- const { spaceBrandingAllowed } = useBranding();
+ const { spaceBrandingAllowed, spaceAttributionConfigurable } =
+ useInstancePolicy();
const { t } = useTranslation();
const currentColor = space.primaryColor ?? DEFAULT_PRIMARY_COLOR;
@@ -165,9 +165,9 @@ export function CustomBrandingSection({
aria-labelledby="primary-color-label"
/>
</Field>
- <IfCloudHosted>
+ {spaceAttributionConfigurable ? (
<RemoveAttributionSetting disabled={disabled} />
- </IfCloudHosted>
+ ) : null}
<Field>
<Field orientation="horizontal">
<FieldContent>
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/page-client.tsx b/apps/web/src/app/[locale]/(space)/settings/general/page-client.tsx
index 2db617f2b..6016520a2 100644
--- a/apps/web/src/app/[locale]/(space)/settings/general/page-client.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/general/page-client.tsx
@@ -26,6 +26,7 @@ import {
SettingsPageHeader,
SettingsPageTitle,
} from "@/components/settings-layout";
+import { useInstancePolicy } from "@/features/instance-policy/client";
import { useSpace } from "@/features/space/client";
import { useAuthedUser } from "@/features/user/client";
import { Trans } from "@/i18n/client";
@@ -37,6 +38,7 @@ import { LeaveSpaceButton } from "./components/leave-space-button";
export function GeneralSettingsPageClient() {
const { data: space, getMemberAbility } = useSpace();
const user = useAuthedUser();
+ const { spacesAlwaysShared } = useInstancePolicy();
const ability = getMemberAbility();
const isAdmin = space.role === "admin";
const canDeleteSpace = ability.can("delete", subject("Space", { ...space }));
@@ -69,7 +71,9 @@ export function GeneralSettingsPageClient() {
</Alert>
) : null}
<CustomBrandingSection disabled={!isAdmin} />
- <CollaborationSection disabled={!isAdmin} />
+ {!spacesAlwaysShared ? (
+ <CollaborationSection disabled={!isAdmin} />
+ ) : null}
{!isOwner || canDeleteSpace ? (
<PageSection variant="card">
<PageSectionHeader>
diff --git a/apps/web/src/app/[locale]/layout.tsx b/apps/web/src/app/[locale]/layout.tsx
index bd59bfba1..63d653c45 100644
--- a/apps/web/src/app/[locale]/layout.tsx
+++ b/apps/web/src/app/[locale]/layout.tsx
@@ -12,10 +12,9 @@ import type { Params } from "@/app/[locale]/types";
import { CookieConsentBanner } from "@/components/cookie-consent-banner";
import { SkipNavLink } from "@/components/skip-nav-link";
import { BrandingProvider } from "@/features/branding/client";
-import {
- getInstanceBrandingConfig,
- isSpaceBrandingAllowed,
-} from "@/features/branding/data";
+import { getInstanceBrandingConfig } from "@/features/branding/data";
+import { InstancePolicyProvider } from "@/features/instance-policy/client";
+import { loadInstancePolicy } from "@/features/instance-policy/loaders";
import { I18nProvider } from "@/i18n/client";
import { initI18next } from "@/i18n/i18n";
import { TimeZoneSync } from "@/lib/datetime/timezone-sync";
@@ -35,15 +34,16 @@ export const viewport: Viewport = {
};
async function loadData(locale: string) {
- const [brandingConfig, spaceBrandingAllowed, { i18n }] = await Promise.all([
+ const [brandingConfig, instancePolicy, { i18n }] = await Promise.all([
getInstanceBrandingConfig(),
- isSpaceBrandingAllowed(),
+ loadInstancePolicy(),
initI18next({ lng: locale }),
]);
return {
resources: i18n.store.data,
- brandingConfig: { ...brandingConfig, spaceBrandingAllowed },
+ brandingConfig,
+ instancePolicy,
};
}
@@ -60,7 +60,7 @@ export default async function Root({
notFound();
}
- const { brandingConfig, resources } = await loadData(locale);
+ const { brandingConfig, instancePolicy, resources } = await loadData(locale);
const brandingStyles = {
"--primary-light": brandingConfig.primaryColor.light,
@@ -79,20 +79,22 @@ export default async function Root({
<body>
<ThemeProvider>
<FeatureFlagsProvider value={featureFlagConfig}>
- <BrandingProvider value={brandingConfig}>
- <Toaster />
- <I18nProvider locale={locale} resources={resources}>
- <TRPCProvider>
- <LazyMotion features={domAnimation}>
- <SkipNavLink />
- <TimeZoneSync>
- <TooltipProvider>{children}</TooltipProvider>
- </TimeZoneSync>
- <CookieConsentBanner />
- </LazyMotion>
- </TRPCProvider>
- </I18nProvider>
- </BrandingProvider>
+ <InstancePolicyProvider value={instancePolicy}>
+ <BrandingProvider value={brandingConfig}>
+ <Toaster />
+ <I18nProvider locale={locale} resources={resources}>
+ <TRPCProvider>
+ <LazyMotion features={domAnimation}>
+ <SkipNavLink />
+ <TimeZoneSync>
+ <TooltipProvider>{children}</TooltipProvider>
+ </TimeZoneSync>
+ <CookieConsentBanner />
+ </LazyMotion>
+ </TRPCProvider>
+ </I18nProvider>
+ </BrandingProvider>
+ </InstancePolicyProvider>
</FeatureFlagsProvider>
</ThemeProvider>
</body>
diff --git a/apps/web/src/app/api/private/utils/api-key.ts b/apps/web/src/app/api/private/utils/api-key.ts
index 02d9b1afe..adb4d69e0 100644
--- a/apps/web/src/app/api/private/utils/api-key.ts
+++ b/apps/web/src/app/api/private/utils/api-key.ts
@@ -11,8 +11,8 @@ import {
isLegacyApiKeyHash,
verifyApiKey,
} from "@/features/api-keys/utils";
+import { resolveSpaceTier } from "@/features/billing/utils";
import type { AuthorizedSpaceId } from "@/features/space/types";
-import { isSelfHosted } from "@/lib/constants";
import { apiError } from "./poll";
const LAST_USED_AT_WRITE_INTERVAL_MS = 60_000;
@@ -80,7 +80,7 @@ const verifyKey = bearerAuth({
return false;
}
- const effectiveTier = isSelfHosted ? ("pro" as const) : spaceTier;
+ const effectiveTier = resolveSpaceTier(spaceTier);
c.set("apiAuth", {
spaceId: spaceId as AuthorizedSpaceId,
@@ -102,7 +102,8 @@ const verifyKey = bearerAuth({
// Skip the write for non-Pro spaces: requireProSpace rejects them with
// 403, so bumping lastUsedAt would misreport a blocked key as active and
- // waste a DB write on rejected traffic. Self-hosted is always Pro here.
+ // waste a DB write on rejected traffic. Without billing every space
+ // resolves to Pro here.
if (effectiveTier === "pro" && (rehashedKey || isLastUsedAtStale)) {
after(() =>
prisma.spaceApiKey.update({
diff --git a/apps/web/src/emails/branding.ts b/apps/web/src/emails/branding.ts
index e19e2f1a0..9aa7105b6 100644
--- a/apps/web/src/emails/branding.ts
+++ b/apps/web/src/emails/branding.ts
@@ -1,10 +1,7 @@
import type { EmailBranding } from "@rallly/emails";
-import {
- getInstanceBrandingConfig,
- isSpaceBrandingAllowed,
-} from "@/features/branding/data";
-import { isSelfHosted } from "@/lib/constants";
+import { getInstanceBrandingConfig } from "@/features/branding/data";
+import { getInstancePolicy } from "@/features/instance-policy/data";
import { resolveStorageUrl } from "@/lib/storage/resolve-storage-url";
/**
@@ -31,17 +28,15 @@ export async function getSpaceBranding(space: {
primaryColor: string | null;
image: string | null;
}): Promise<EmailBranding> {
- const [instance, spaceBrandingAllowed] = await Promise.all([
- getInstanceBranding(),
- isSpaceBrandingAllowed(),
- ]);
+ const [instance, { spaceBrandingAllowed, spaceAttributionConfigurable }] =
+ await Promise.all([getInstanceBranding(), getInstancePolicy()]);
return {
...instance,
- // Space-level attribution removal is cloud-only; self-hosted attribution
- // is licensed at instance level and already reflected in the instance
- // branding.
+ // Where attribution is licensed at instance level it is already
+ // reflected in the instance branding
hideAttribution:
- instance.hideAttribution || (!isSelfHosted && space.hideAttribution),
+ instance.hideAttribution ||
+ (spaceAttributionConfigurable && space.hideAttribution),
...(space.showBranding && spaceBrandingAllowed
? {
primaryColor: space.primaryColor ?? instance.primaryColor,
diff --git a/apps/web/src/features/billing/constants.ts b/apps/web/src/features/billing/constants.ts
index 9dd0bf58a..c866bbe81 100644
--- a/apps/web/src/features/billing/constants.ts
+++ b/apps/web/src/features/billing/constants.ts
@@ -1,5 +1,6 @@
import { isSelfHosted } from "@/lib/constants";
+// Billing is Stripe on cloud; self-hosted is licensed at instance level
export const isBillingEnabled = !isSelfHosted;
// Re-export plan names from the shared billing package
diff --git a/apps/web/src/features/billing/utils.test.ts b/apps/web/src/features/billing/utils.test.ts
new file mode 100644
index 000000000..be65c02f3
--- /dev/null
+++ b/apps/web/src/features/billing/utils.test.ts
@@ -0,0 +1,30 @@
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+// isBillingEnabled is a module constant read from the environment, so each
+// branch needs a fresh module registry to observe the stubbed value.
+const loadResolveSpaceTier = async (selfHosted: boolean) => {
+ vi.stubEnv("NEXT_PUBLIC_SELF_HOSTED", selfHosted ? "true" : "false");
+ vi.resetModules();
+ const { resolveSpaceTier } = await import("./utils");
+ return resolveSpaceTier;
+};
+
+describe("resolveSpaceTier", () => {
+ afterEach(() => {
+ vi.unstubAllEnvs();
+ });
+
+ it("returns the stored tier when billing is enabled", async () => {
+ const resolveSpaceTier = await loadResolveSpaceTier(false);
+
+ expect(resolveSpaceTier("hobby")).toBe("hobby");
+ expect(resolveSpaceTier("pro")).toBe("pro");
+ });
+
+ it("treats every space as pro when there is no billing", async () => {
+ const resolveSpaceTier = await loadResolveSpaceTier(true);
+
+ expect(resolveSpaceTier("hobby")).toBe("pro");
+ expect(resolveSpaceTier("pro")).toBe("pro");
+ });
+});
diff --git a/apps/web/src/features/billing/utils.ts b/apps/web/src/features/billing/utils.ts
new file mode 100644
index 000000000..23a638793
--- /dev/null
+++ b/apps/web/src/features/billing/utils.ts
@@ -0,0 +1,11 @@
+import { isBillingEnabled } from "@/features/billing/constants";
+import type { SpaceTier } from "@/features/space/schema";
+
+/**
+ * The tier a space's paid features are gated on. Without billing there is
+ * nothing to pay for, so every space has every paid feature regardless of
+ * what the row says. This is the only place that rule is derived.
+ */
+export function resolveSpaceTier(storedTier: SpaceTier): SpaceTier {
+ return isBillingEnabled ? storedTier : "pro";
+}
diff --git a/apps/web/src/features/branding/client.tsx b/apps/web/src/features/branding/client.tsx
index b59f652fd..e55689d41 100644
--- a/apps/web/src/features/branding/client.tsx
+++ b/apps/web/src/features/branding/client.tsx
@@ -18,18 +18,12 @@ export interface BrandingConfig {
appName: string;
}
-export interface BrandingContextValue extends BrandingConfig {
- // False when the instance holds the white label addon: space branding is
- // suppressed and branding is managed from the control panel
- spaceBrandingAllowed: boolean;
-}
-
-const BrandingContext = React.createContext<BrandingContextValue | undefined>(
+const BrandingContext = React.createContext<BrandingConfig | undefined>(
undefined,
);
interface BrandingProviderProps {
- value: BrandingContextValue;
+ value: BrandingConfig;
children: React.ReactNode;
}
@@ -41,7 +35,7 @@ export function BrandingProvider({ value, children }: BrandingProviderProps) {
);
}
-export function useBranding(): BrandingContextValue {
+export function useBranding(): BrandingConfig {
const context = React.useContext(BrandingContext);
if (context === undefined) {
throw new Error("useBranding must be used within a BrandingProvider");
diff --git a/apps/web/src/features/branding/data.ts b/apps/web/src/features/branding/data.ts
index 98c716ba9..d5aca6e5c 100644
--- a/apps/web/src/features/branding/data.ts
+++ b/apps/web/src/features/branding/data.ts
@@ -55,22 +55,3 @@ export const getInstanceBrandingConfig = cache(async () => {
? getCustomBrandingConfig()
: getDefaultBrandingConfig();
});
-
-/**
- * Whether spaces may apply their own branding on top of the instance
- * branding. A white label instance is branded by its operator, so space
- * branding is suppressed everywhere it would render. Interim rule until
- * organizations own branding enforcement.
- */
-export const isSpaceBrandingAllowed = cache(async () => {
- if (!isSelfHosted) {
- return true;
- }
- if (isMaintenanceModeEnabled()) {
- // Skip the license lookup so pages can render while the database is
- // unreachable; nothing space-branded renders in maintenance mode
- return true;
- }
- const license = await loadInstanceLicense();
- return !(license?.whiteLabelAddon ?? false);
-});
diff --git a/apps/web/src/features/branding/loaders.ts b/apps/web/src/features/branding/loaders.ts
index 5d62c56b9..02288443f 100644
--- a/apps/web/src/features/branding/loaders.ts
+++ b/apps/web/src/features/branding/loaders.ts
@@ -5,11 +5,9 @@ import { env } from "@/env";
import { getInstanceSettings } from "@/features/instance-settings/data";
import { loadInstanceLicense } from "@/features/licensing/data";
import { DEFAULT_PRIMARY_COLOR } from "./constants";
-import { getCustomBrandingConfig, isSpaceBrandingAllowed } from "./data";
+import { getCustomBrandingConfig } from "./data";
import { getPrimaryColorVars } from "./utils";
-export const loadSpaceBrandingAllowed = cache(() => isSpaceBrandingAllowed());
-
/**
* Raw branding values for the control panel branding page. Editable fields
* expose the stored value (db, then env, then default) rather than the
diff --git a/apps/web/src/features/feedback/constants.ts b/apps/web/src/features/feedback/constants.ts
index a667fcaa9..ba1d19b86 100644
--- a/apps/web/src/features/feedback/constants.ts
+++ b/apps/web/src/features/feedback/constants.ts
@@ -1,3 +1,4 @@
import { isSelfHosted } from "@/lib/constants";
+// Feedback goes to the Rallly team; there is nobody to receive it self-hosted
export const isFeedbackEnabled = !isSelfHosted;
diff --git a/apps/web/src/features/instance-policy/client.tsx b/apps/web/src/features/instance-policy/client.tsx
new file mode 100644
index 000000000..87e3a08c6
--- /dev/null
+++ b/apps/web/src/features/instance-policy/client.tsx
@@ -0,0 +1,32 @@
+"use client";
+
+import React from "react";
+import type { InstancePolicy } from "./types";
+
+const InstancePolicyContext = React.createContext<InstancePolicy | undefined>(
+ undefined,
+);
+
+export function InstancePolicyProvider({
+ value,
+ children,
+}: {
+ value: InstancePolicy;
+ children: React.ReactNode;
+}) {
+ return (
+ <InstancePolicyContext.Provider value={value}>
+ {children}
+ </InstancePolicyContext.Provider>
+ );
+}
+
+export function useInstancePolicy(): InstancePolicy {
+ const context = React.useContext(InstancePolicyContext);
+ if (context === undefined) {
+ throw new Error(
+ "useInstancePolicy must be used within an InstancePolicyProvider",
+ );
+ }
+ return context;
+}
diff --git a/apps/web/src/features/instance-policy/data.ts b/apps/web/src/features/instance-policy/data.ts
new file mode 100644
index 000000000..06d7603ab
--- /dev/null
+++ b/apps/web/src/features/instance-policy/data.ts
@@ -0,0 +1,26 @@
+import "server-only";
+
+import { cache } from "react";
+import { loadInstanceLicense } from "@/features/licensing/data";
+import { isSelfHosted } from "@/lib/constants";
+import { isMaintenanceModeEnabled } from "@/lib/maintenance";
+import { deriveInstancePolicy } from "./utils";
+
+/**
+ * Instance policy for the current request. Callable from any server
+ * context (tRPC, API routes, emails, other features' data.ts); pages read
+ * it through `loadInstancePolicy`.
+ */
+export const getInstancePolicy = cache(async () => {
+ // The license lookup is skipped in maintenance mode so the maintenance
+ // page can render while the database is unreachable; nothing that the
+ // license gates renders there. loadInstanceLicense is null on cloud.
+ const license = isMaintenanceModeEnabled()
+ ? null
+ : await loadInstanceLicense();
+
+ return deriveInstancePolicy({
+ isSelfHosted,
+ whiteLabelAddon: license?.whiteLabelAddon ?? false,
+ });
+});
diff --git a/apps/web/src/features/instance-policy/loaders.ts b/apps/web/src/features/instance-policy/loaders.ts
new file mode 100644
index 000000000..37228deb2
--- /dev/null
+++ b/apps/web/src/features/instance-policy/loaders.ts
@@ -0,0 +1,12 @@
+import "server-only";
+
+import { cache } from "react";
+import { getInstancePolicy } from "./data";
+
+/**
+ * Page-facing read of the instance policy. There is no actor to resolve:
+ * the policy is instance wide, so this only satisfies the rule that pages
+ * read through loaders. Mounted once in the root layout and handed to the
+ * client through `InstancePolicyProvider`.
+ */
+export const loadInstancePolicy = cache(() => getInstancePolicy());
diff --git a/apps/web/src/features/instance-policy/types.ts b/apps/web/src/features/instance-policy/types.ts
new file mode 100644
index 000000000..71513fa7d
--- /dev/null
+++ b/apps/web/src/features/instance-policy/types.ts
@@ -0,0 +1,14 @@
+/**
+ * What this instance's organization decides for its spaces. Every field is
+ * a cloud vs self-hosted behavior difference; there is no other place for
+ * one. When the organization layer lands this becomes the org's policy:
+ * same fields, new source.
+ */
+export type InstancePolicy = {
+ // Every space is a team: independent membership does not exist
+ spacesAlwaysShared: boolean;
+ // Spaces may apply their own branding on top of the instance branding
+ spaceBrandingAllowed: boolean;
+ // Attribution removal is a per-space setting rather than instance wide
+ spaceAttributionConfigurable: boolean;
+};
diff --git a/apps/web/src/features/instance-policy/utils.test.ts b/apps/web/src/features/instance-policy/utils.test.ts
new file mode 100644
index 000000000..e57ce0b91
--- /dev/null
+++ b/apps/web/src/features/instance-policy/utils.test.ts
@@ -0,0 +1,59 @@
+import { describe, expect, it } from "vitest";
+import { deriveInstancePolicy } from "./utils";
+
+describe("deriveInstancePolicy", () => {
+ describe("spacesAlwaysShared", () => {
+ it("forces every space to be shared on a self-hosted instance", () => {
+ expect(
+ deriveInstancePolicy({ isSelfHosted: true, whiteLabelAddon: false })
+ .spacesAlwaysShared,
+ ).toBe(true);
+ });
+
+ it("leaves sharing to each space on cloud", () => {
+ expect(
+ deriveInstancePolicy({ isSelfHosted: false, whiteLabelAddon: false })
+ .spacesAlwaysShared,
+ ).toBe(false);
+ });
+ });
+
+ describe("spaceBrandingAllowed", () => {
+ it("suppresses space branding on a white label instance", () => {
+ expect(
+ deriveInstancePolicy({ isSelfHosted: true, whiteLabelAddon: true })
+ .spaceBrandingAllowed,
+ ).toBe(false);
+ });
+
+ it("allows space branding on a self-hosted instance without the addon", () => {
+ expect(
+ deriveInstancePolicy({ isSelfHosted: true, whiteLabelAddon: false })
+ .spaceBrandingAllowed,
+ ).toBe(true);
+ });
+
+ it("allows space branding on cloud", () => {
+ expect(
+ deriveInstancePolicy({ isSelfHosted: false, whiteLabelAddon: false })
+ .spaceBrandingAllowed,
+ ).toBe(true);
+ });
+ });
+
+ describe("spaceAttributionConfigurable", () => {
+ it("is licensed at instance level on a self-hosted instance", () => {
+ expect(
+ deriveInstancePolicy({ isSelfHosted: true, whiteLabelAddon: false })
+ .spaceAttributionConfigurable,
+ ).toBe(false);
+ });
+
+ it("is a per-space setting on cloud", () => {
+ expect(
+ deriveInstancePolicy({ isSelfHosted: false, whiteLabelAddon: false })
+ .spaceAttributionConfigurable,
+ ).toBe(true);
+ });
+ });
+});
diff --git a/apps/web/src/features/instance-policy/utils.ts b/apps/web/src/features/instance-policy/utils.ts
new file mode 100644
index 000000000..cfc04ba72
--- /dev/null
+++ b/apps/web/src/features/instance-policy/utils.ts
@@ -0,0 +1,25 @@
+import type { InstancePolicy } from "./types";
+
+/**
+ * The one derivation of instance policy from deployment facts. Each field
+ * is one line with its reason, so this function is the inventory of what
+ * differs between cloud and self-hosted at the policy level.
+ */
+export function deriveInstancePolicy({
+ isSelfHosted,
+ whiteLabelAddon,
+}: {
+ isSelfHosted: boolean;
+ whiteLabelAddon: boolean;
+}): InstancePolicy {
+ return {
+ // Single-tenant instance: the instance is the org boundary, so adding a
+ // member to a space only makes sense to collaborate
+ spacesAlwaysShared: isSelfHosted,
+ // A white label instance is branded by its operator
+ spaceBrandingAllowed: !whiteLabelAddon,
+ // Self-hosted attribution is licensed at instance level (white label
+ // addon + HIDE_ATTRIBUTION), not chosen per space
+ spaceAttributionConfigurable: !isSelfHosted,
+ };
+}
diff --git a/apps/web/src/features/poll/components/event-card.tsx b/apps/web/src/features/poll/components/event-card.tsx
index bc6e26413..6dfad7b79 100644
--- a/apps/web/src/features/poll/components/event-card.tsx
+++ b/apps/web/src/features/poll/components/event-card.tsx
@@ -3,6 +3,7 @@ import { Card, CardContent } from "@rallly/ui/card";
import { MapPinIcon, User2Icon } from "lucide-react";
import { RandomGradientBar } from "@/components/random-gradient-bar";
import { useBranding } from "@/features/branding/client";
+import { useInstancePolicy } from "@/features/instance-policy/client";
import { usePoll } from "@/features/poll/client";
import {
EventMetaDescription,
@@ -47,6 +48,7 @@ function IconDescription({
export function EventCard() {
const poll = usePoll();
const branding = useBranding();
+ const { spaceBrandingAllowed } = useInstancePolicy();
return (
<Card>
<RandomGradientBar />
@@ -62,7 +64,7 @@ export function EventCard() {
{poll.space.name}
</p>
</div>
- ) : !branding.spaceBrandingAllowed ? (
+ ) : !spaceBrandingAllowed ? (
// Instance branding is enforced: the space chip is suppressed, so
// the slot carries the instance's logo icon and name instead
<div className="mb-2">
diff --git a/apps/web/src/features/poll/data.ts b/apps/web/src/features/poll/data.ts
index 22db3ae23..acb47d461 100644
--- a/apps/web/src/features/poll/data.ts
+++ b/apps/web/src/features/poll/data.ts
@@ -2,6 +2,7 @@ import "server-only";
import type { PollStatus, Prisma } from "@rallly/database";
import { prisma } from "@rallly/database";
+import { getInstancePolicy } from "@/features/instance-policy/data";
import { effectiveSpaceMemberWhere } from "@/features/space/member/utils";
import type {
AuthorizedSpaceId,
@@ -415,7 +416,9 @@ export async function canUserManagePoll(
},
});
- if (membership?.space.shared) {
+ const { spacesAlwaysShared } = await getInstancePolicy();
+
+ if (membership && (spacesAlwaysShared || membership.space.shared)) {
// Members manage each other's polls only in a shared space. Uniform
// across roles: admins are members here too.
return true;
@@ -426,6 +429,8 @@ export async function canUserManagePoll(
}
export const hasPollAdminAccess = async (pollId: string, userId: string) => {
+ const { spacesAlwaysShared } = await getInstancePolicy();
+
const poll = await prisma.poll.findFirst({
where: {
id: pollId,
@@ -436,7 +441,9 @@ export const hasPollAdminAccess = async (pollId: string, userId: string) => {
// across roles: admins are members here too.
{
space: {
- shared: true,
+ // The row is not coerced the way the DTO is, so the policy has
+ // to override it here
+ ...(spacesAlwaysShared ? {} : { shared: true }),
members: { some: effectiveSpaceMemberWhere({ userId }) },
},
},
diff --git a/apps/web/src/features/quick-create/constants.ts b/apps/web/src/features/quick-create/constants.ts
index c5e4ccb51..dad14b434 100644
--- a/apps/web/src/features/quick-create/constants.ts
+++ b/apps/web/src/features/quick-create/constants.ts
@@ -1,4 +1,5 @@
import { isSelfHosted } from "@/lib/constants";
+// Guest poll creation is a cloud growth surface, gated by its own switch
export const isQuickCreateEnabled =
!isSelfHosted && process.env.QUICK_CREATE_ENABLED === "true";
diff --git a/apps/web/src/features/space/actions.ts b/apps/web/src/features/space/actions.ts
index c7cc03690..531031ed2 100644
--- a/apps/web/src/features/space/actions.ts
+++ b/apps/web/src/features/space/actions.ts
@@ -4,7 +4,7 @@ import { subject } from "@casl/ability";
import { prisma } from "@rallly/database";
import { createMiddleware } from "next-safe-action";
import * as z from "zod";
-import { isSpaceBrandingAllowed } from "@/features/branding/data";
+import { getInstancePolicy } from "@/features/instance-policy/data";
import { spaceIconAssetProfile } from "@/features/space/constants";
import { getActiveSpaceForUser } from "@/features/space/data";
import { defineAbilityForMember } from "@/features/space/member/ability";
@@ -28,7 +28,6 @@ import {
updateSpaceShowBrandingSchema,
} from "@/features/space/schema";
import { setActiveSpace } from "@/features/user/mutations";
-import { isSelfHosted } from "@/lib/constants";
import { AppError } from "@/lib/errors/app-error";
import { identifyGroup, track } from "@/lib/posthog";
import {
@@ -194,7 +193,9 @@ export const updateSpaceAction = authActionClient
});
}
- if (parsedInput.primaryColor && !(await isSpaceBrandingAllowed())) {
+ const { spaceBrandingAllowed } = await getInstancePolicy();
+
+ if (parsedInput.primaryColor && !spaceBrandingAllowed) {
throw new AppError({
code: "FORBIDDEN",
message: "Space branding is managed by the instance administrator",
@@ -242,7 +243,9 @@ export const updateSpaceShowBrandingAction = authActionClient
});
}
- if (parsedInput.showBranding && !(await isSpaceBrandingAllowed())) {
+ const { spaceBrandingAllowed } = await getInstancePolicy();
+
+ if (parsedInput.showBranding && !spaceBrandingAllowed) {
throw new AppError({
code: "FORBIDDEN",
message: "Space branding is managed by the instance administrator",
@@ -280,10 +283,9 @@ export const updateSpaceHideAttributionAction = authActionClient
.action(async ({ ctx, parsedInput }) => {
const { space } = ctx;
- // Space-level attribution removal is a cloud feature. On self-hosted
- // instances attribution is licensed at instance level (white label
- // addon + HIDE_ATTRIBUTION), where every space reports as "pro".
- if (isSelfHosted) {
+ const { spaceAttributionConfigurable } = await getInstancePolicy();
+
+ if (!spaceAttributionConfigurable) {
throw new AppError({
code: "FORBIDDEN",
message: "Attribution removal is not available on this instance",
@@ -327,6 +329,14 @@ export const updateSpaceSharedAction = authActionClient
.inputSchema(updateSpaceSharedSchema)
.action(async ({ ctx, parsedInput }) => {
const { space } = ctx;
+ const { spacesAlwaysShared } = await getInstancePolicy();
+
+ if (spacesAlwaysShared) {
+ throw new AppError({
+ code: "FORBIDDEN",
+ message: "Spaces are always shared on this instance",
+ });
+ }
if (parsedInput.shared && space.tier !== "pro") {
throw new AppError({
diff --git a/apps/web/src/features/space/client.tsx b/apps/web/src/features/space/client.tsx
index e6e3b4294..d7c60b743 100644
--- a/apps/web/src/features/space/client.tsx
+++ b/apps/web/src/features/space/client.tsx
@@ -2,8 +2,8 @@
import { posthog } from "@rallly/posthog/client";
import React from "react";
-import { useBranding } from "@/features/branding/client";
import { getPrimaryColorVars } from "@/features/branding/utils";
+import { useInstancePolicy } from "@/features/instance-policy/client";
import { defineAbilityForMember } from "@/features/space/member/ability";
import type { SpaceDTO } from "@/features/space/types";
import { useAuthedUser } from "@/features/user/client";
@@ -53,7 +53,7 @@ export function SpaceProvider({
posthog?.group("space", space.id);
}, [space.id]);
- const { spaceBrandingAllowed } = useBranding();
+ const { spaceBrandingAllowed } = useInstancePolicy();
const primaryColorVars =
spaceBrandingAllowed && space.showBranding && space.primaryColor
diff --git a/apps/web/src/features/space/data.ts b/apps/web/src/features/space/data.ts
index bd1d89eeb..769b24673 100644
--- a/apps/web/src/features/space/data.ts
+++ b/apps/web/src/features/space/data.ts
@@ -1,22 +1,18 @@
import "server-only";
-import type {
- SpaceMemberRole as DBSpaceMemberRole,
- SpaceTier as DBSpaceTier,
-} from "@rallly/database";
+import type { SpaceMemberRole as DBSpaceMemberRole } from "@rallly/database";
import { prisma } from "@rallly/database";
import { createLogger } from "@rallly/logger";
import { cache } from "react";
+import { isBillingEnabled } from "@/features/billing/constants";
import { getSpaceSubscription } from "@/features/billing/data";
-import { isSpaceBrandingAllowed } from "@/features/branding/data";
+import { getInstancePolicy } from "@/features/instance-policy/data";
import { cached_getInstanceLicense } from "@/features/licensing/data";
import type { LicenseType } from "@/features/licensing/schema";
import type { MemberDTO } from "@/features/space/member/types";
import { effectiveSpaceMemberWhere } from "@/features/space/member/utils";
-import type { AuthorizedSpaceId, SpaceDTO } from "@/features/space/types";
-import { fromDBRole } from "@/features/space/utils";
-import { isSelfHosted } from "@/lib/constants";
+import { createSpaceDTO, fromDBRole } from "@/features/space/utils";
import { AppError } from "@/lib/errors/app-error";
const logger = createLogger("space/data");
@@ -95,8 +91,8 @@ function getSelfHostedSeatLimit(licenseType: LicenseType | null): number {
*/
export async function getTotalSeatsForSpace(spaceId: string): Promise<number> {
try {
- if (isSelfHosted) {
- // For self-hosted instances, get seat limit from instance license
+ if (!isBillingEnabled) {
+ // Without billing, seats come from the instance license
const license = await cached_getInstanceLicense();
if (!license) {
@@ -137,36 +133,6 @@ export async function getTotalSeatsForSpace(spaceId: string): Promise<number> {
}
}
-export function createSpaceDTO(space: {
- id: string;
- ownerId: string;
- name: string;
- role: DBSpaceMemberRole;
- image?: string | null;
- tier: DBSpaceTier;
- primaryColor?: string | null;
- showBranding: boolean;
- hideAttribution: boolean;
- shared: boolean;
- memberCount: number;
- seatCount: number;
-}): SpaceDTO {
- return {
- id: space.id as AuthorizedSpaceId,
- name: space.name,
- ownerId: space.ownerId,
- tier: isSelfHosted ? "pro" : space.tier,
- role: fromDBRole(space.role),
- shared: space.shared,
- memberCount: space.memberCount,
- seatCount: space.seatCount,
- image: space.image ?? undefined,
- primaryColor: space.primaryColor ?? undefined,
- showBranding: space.showBranding,
- hideAttribution: space.hideAttribution,
- };
-}
-
export const getMember = async (id: string) => {
const member = await prisma.spaceMember.findUnique({
where: {
@@ -214,7 +180,9 @@ export async function getSpaceBranding(spaceId: string) {
return null;
}
- if (!(await isSpaceBrandingAllowed())) {
+ const { spaceBrandingAllowed } = await getInstancePolicy();
+
+ if (!spaceBrandingAllowed) {
return { ...space, showBranding: false, primaryColor: null };
}
@@ -255,12 +223,17 @@ export const listSpacesForUser = cache(async (userId: string) => {
},
});
+ const policy = await getInstancePolicy();
+
return result.map((spaceMember) =>
createSpaceDTO({
- ...spaceMember.space,
- role: spaceMember.role,
- memberCount: spaceMember.space._count.members,
- seatCount: spaceMember.space.subscriptions[0]?.quantity ?? 1,
+ space: {
+ ...spaceMember.space,
+ role: spaceMember.role,
+ memberCount: spaceMember.space._count.members,
+ seatCount: spaceMember.space.subscriptions[0]?.quantity ?? 1,
+ },
+ policy,
}),
);
});
@@ -290,9 +263,12 @@ export const getActiveSpaceForUser = cache(async (userId: string) => {
}
return createSpaceDTO({
- ...spaceMember.space,
- role: spaceMember.role,
- memberCount: spaceMember.space._count.members,
- seatCount: spaceMember.space.subscriptions[0]?.quantity ?? 1,
+ space: {
+ ...spaceMember.space,
+ role: spaceMember.role,
+ memberCount: spaceMember.space._count.members,
+ seatCount: spaceMember.space.subscriptions[0]?.quantity ?? 1,
+ },
+ policy: await getInstancePolicy(),
});
});
diff --git a/apps/web/src/features/space/mutations.ts b/apps/web/src/features/space/mutations.ts
index 49a4957c9..e806e2cea 100644
--- a/apps/web/src/features/space/mutations.ts
+++ b/apps/web/src/features/space/mutations.ts
@@ -3,8 +3,9 @@ import "server-only";
import type { SpaceTier, SpaceType } from "@rallly/database";
import { prisma } from "@rallly/database";
import { after } from "next/server";
-import { createSpaceDTO } from "@/features/space/data";
-import { isSelfHosted } from "@/lib/constants";
+import { resolveSpaceTier } from "@/features/billing/utils";
+import { getInstancePolicy } from "@/features/instance-policy/data";
+import { createSpaceDTO } from "@/features/space/utils";
import {
deleteStoredAsset,
replaceStoredAsset,
@@ -13,7 +14,9 @@ import {
export async function createSpace({
name = "Personal",
ownerId,
- tier = isSelfHosted ? "pro" : "hobby",
+ // Stored as what reads resolve an unpaid space to, so the row matches
+ // behavior on instances without billing
+ tier = resolveSpaceTier("hobby"),
spaceType,
industry,
}: {
@@ -23,6 +26,8 @@ export async function createSpace({
spaceType?: SpaceType;
industry?: string | null;
}) {
+ const policy = await getInstancePolicy();
+
const space = await prisma.space.create({
data: {
name,
@@ -32,8 +37,9 @@ export async function createSpace({
industry,
// New spaces start unshared; sharing everything is opt-in. Matches
// the column default — explicit here so the decision is visible in
- // code, not just the schema.
- shared: false,
+ // code, not just the schema. Stored as shared where the policy forces
+ // it so the row matches what reads coerce it to.
+ shared: policy.spacesAlwaysShared,
members: {
create: {
userId: ownerId,
@@ -45,10 +51,13 @@ export async function createSpace({
});
return createSpaceDTO({
- ...space,
- role: "ADMIN",
- memberCount: 1,
- seatCount: 1,
+ space: {
+ ...space,
+ role: "ADMIN",
+ memberCount: 1,
+ seatCount: 1,
+ },
+ policy,
});
}
diff --git a/apps/web/src/features/space/utils.test.ts b/apps/web/src/features/space/utils.test.ts
index c12071564..8bcda32a8 100644
--- a/apps/web/src/features/space/utils.test.ts
+++ b/apps/web/src/features/space/utils.test.ts
@@ -1,6 +1,10 @@
import { describe, expect, it } from "vitest";
import type { AuthorizedSpaceId } from "@/features/space/types";
-import { createSpaceContentScope, inferIndustry } from "@/features/space/utils";
+import {
+ createSpaceContentScope,
+ createSpaceDTO,
+ inferIndustry,
+} from "@/features/space/utils";
const spaceId = "space-1" as AuthorizedSpaceId;
@@ -149,3 +153,36 @@ describe("inferIndustry", () => {
).toBe("government");
});
});
+
+describe("createSpaceDTO", () => {
+ const space = {
+ id: "space-1",
+ ownerId: "user-1",
+ name: "My Team",
+ role: "MEMBER" as const,
+ tier: "hobby" as const,
+ showBranding: false,
+ hideAttribution: false,
+ shared: false,
+ memberCount: 1,
+ seatCount: 1,
+ };
+
+ it("keeps the stored sharing setting when spaces are not always shared", () => {
+ expect(
+ createSpaceDTO({ space, policy: { spacesAlwaysShared: false } }).shared,
+ ).toBe(false);
+ expect(
+ createSpaceDTO({
+ space: { ...space, shared: true },
+ policy: { spacesAlwaysShared: false },
+ }).shared,
+ ).toBe(true);
+ });
+
+ it("coerces an unshared space to shared when spaces are always shared", () => {
+ expect(
+ createSpaceDTO({ space, policy: { spacesAlwaysShared: true } }).shared,
+ ).toBe(true);
+ });
+});
diff --git a/apps/web/src/features/space/utils.ts b/apps/web/src/features/space/utils.ts
index 35d5922b6..59c5b9f1d 100644
--- a/apps/web/src/features/space/utils.ts
+++ b/apps/web/src/features/space/utils.ts
@@ -1,11 +1,20 @@
-import type { SpaceMemberRole as PrismaSpaceMemberRole } from "@rallly/database";
+import type {
+ SpaceMemberRole as PrismaSpaceMemberRole,
+ SpaceTier as PrismaSpaceTier,
+} from "@rallly/database";
+import { resolveSpaceTier } from "@/features/billing/utils";
+import type { InstancePolicy } from "@/features/instance-policy/types";
import type { Industry } from "@/features/space/constants";
import {
industryDomainRules,
industryKeywordRules,
} from "@/features/space/constants";
import type { MemberRole } from "@/features/space/schema";
-import type { SpaceContentScope, SpaceDTO } from "@/features/space/types";
+import type {
+ AuthorizedSpaceId,
+ SpaceContentScope,
+ SpaceDTO,
+} from "@/features/space/types";
export const toDBRole = (role: MemberRole): PrismaSpaceMemberRole => {
switch (role) {
@@ -25,6 +34,45 @@ export const fromDBRole = (role: PrismaSpaceMemberRole): MemberRole => {
}
};
+export function createSpaceDTO({
+ space,
+ policy,
+}: {
+ space: {
+ id: string;
+ ownerId: string;
+ name: string;
+ role: PrismaSpaceMemberRole;
+ image?: string | null;
+ tier: PrismaSpaceTier;
+ primaryColor?: string | null;
+ showBranding: boolean;
+ hideAttribution: boolean;
+ shared: boolean;
+ memberCount: number;
+ seatCount: number;
+ };
+ policy: Pick<InstancePolicy, "spacesAlwaysShared">;
+}): SpaceDTO {
+ return {
+ id: space.id as AuthorizedSpaceId,
+ name: space.name,
+ ownerId: space.ownerId,
+ tier: resolveSpaceTier(space.tier),
+ role: fromDBRole(space.role),
+ // Coerced at read time: migrations are shared with cloud, so the column
+ // cannot be backfilled per deployment. Every reader of `shared` must go
+ // through this DTO rather than the row.
+ shared: policy.spacesAlwaysShared || space.shared,
+ memberCount: space.memberCount,
+ seatCount: space.seatCount,
+ image: space.image ?? undefined,
+ primaryColor: space.primaryColor ?? undefined,
+ showBranding: space.showBranding,
+ hideAttribution: space.hideAttribution,
+ };
+}
+
/**
* The visibility scope space-scoped content reads must apply for this
* member. One rule for all content types and all roles: in an unshared
diff --git a/apps/web/src/lib/feature-flags/config.ts b/apps/web/src/lib/feature-flags/config.ts
index 7f50abbd5..3bdd2c339 100644
--- a/apps/web/src/lib/feature-flags/config.ts
+++ b/apps/web/src/lib/feature-flags/config.ts
@@ -4,6 +4,7 @@ import { isBillingEnabled } from "@/features/billing/constants";
import { isCalendarsEnabled } from "@/features/calendars/constants";
import { isEventTypesEnabled } from "@/features/event-types/constants";
import { isFeedbackEnabled } from "@/features/feedback/constants";
+import { isQuickCreateEnabled } from "@/features/quick-create/constants";
import type { FeatureFlagConfig } from "@/lib/feature-flags/types";
import { isStorageEnabled } from "@/lib/storage";
@@ -25,4 +26,5 @@ export const featureFlagConfig: FeatureFlagConfig = {
// The new poll admin at /polls/[pollId] is dev-only until it reaches
// feature parity with the legacy admin and cuts over.
pollAdmin: env.NODE_ENV === "development",
+ quickCreate: isQuickCreateEnabled,
};
diff --git a/apps/web/src/lib/feature-flags/types.ts b/apps/web/src/lib/feature-flags/types.ts
index 5fc985478..0ecfa1832 100644
--- a/apps/web/src/lib/feature-flags/types.ts
+++ b/apps/web/src/lib/feature-flags/types.ts
@@ -8,6 +8,7 @@ export interface FeatureFlagConfig {
calendars: boolean;
eventTypes: boolean;
pollAdmin: boolean;
+ quickCreate: boolean;
}
export type Feature = keyof FeatureFlagConfig;
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index 54adcb5fb..3b772ef62 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -8,7 +8,7 @@ import { TRPCError } from "@trpc/server";
import { after } from "next/server";
import * as z from "zod";
import { getInstanceBranding, getSpaceBranding } from "@/emails/branding";
-import { isSpaceBrandingAllowed } from "@/features/branding/data";
+import { getInstancePolicy } from "@/features/instance-policy/data";
import { moderateContent } from "@/features/moderation/mutations";
import { recordPollActivities } from "@/features/poll/activity/mutations";
import {
@@ -19,7 +19,6 @@ import {
import { MAX_POLL_DESCRIPTION_LENGTH } from "@/features/poll/schema";
import { formatEventDateTime } from "@/features/scheduled-event/utils";
import { getActiveSpaceForUser } from "@/features/space/data";
-import { isSelfHosted } from "@/lib/constants";
import { dayjs } from "@/lib/dayjs";
import { identifyGroup, track } from "@/lib/posthog";
import { createIcsEvent } from "@/lib/utils/ics";
@@ -833,13 +832,11 @@ export const polls = router({
}
: null;
- const spaceBrandingAllowed = await isSpaceBrandingAllowed();
+ const { spaceBrandingAllowed, spaceAttributionConfigurable } =
+ await getInstancePolicy();
return {
...res,
- // Space-level attribution removal is cloud-only; self-hosted
- // attribution is licensed at instance level via the white label
- // addon.
space: res.space
? {
...res.space,
@@ -847,7 +844,8 @@ export const polls = router({
primaryColor: spaceBrandingAllowed
? res.space.primaryColor
: null,
- hideAttribution: !isSelfHosted && res.space.hideAttribution,
+ hideAttribution:
+ spaceAttributionConfigurable && res.space.hideAttribution,
}
: null,
canManage,
diff --git a/apps/web/src/trpc/trpc.ts b/apps/web/src/trpc/trpc.ts
index fe7b0d8ee..973bb4b3a 100644
--- a/apps/web/src/trpc/trpc.ts
+++ b/apps/web/src/trpc/trpc.ts
@@ -6,7 +6,6 @@ import { getActiveSpaceForUser } from "@/features/space/data";
import { createSpaceContentScope } from "@/features/space/utils";
import { createUserDTO } from "@/features/user/data";
import { signOut } from "@/lib/auth";
-import { isSelfHosted } from "@/lib/constants";
import { AppError } from "@/lib/errors/app-error";
import { isMaintenanceActiveForRequest } from "@/lib/maintenance-server";
import { createRatelimit } from "@/lib/rate-limit";
@@ -174,7 +173,8 @@ export const spaceProcedure = privateProcedure.use(async ({ ctx, next }) => {
});
export const proProcedure = spaceProcedure.use(async ({ ctx, next }) => {
- if (!isSelfHosted && ctx.space.tier !== "pro") {
+ // ctx.space is the coerced DTO: without billing every space is pro here
+ if (ctx.space.tier !== "pro") {
throw new TRPCError({
code: "PAYMENT_REQUIRED",
message: