Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Enforce instance branding when the white label add-on is active (#3125)
Luke Vella1c6f5da32439
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 47b08a1be..7db7cec4f 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -204,6 +204,7 @@"customBranding": "Custom branding","customBrandingAlertDescription": "Custom branding is available to Enterprise license holders as a paid add-on.","customBrandingDescription": "Show your logo and brand colors to your participants",+ "customBrandingManagedByInstance": "Branding is managed by your instance administrator.","customBrandingSettingLabel": "Show your logo and colors to participants.","customBrandingSettingTitle": "Custom branding","dangerZone": "Danger zone",diff --git a/apps/web/src/app/[locale]/(optional-space)/new/page.tsx b/apps/web/src/app/[locale]/(optional-space)/new/page.tsxindex 169463888..d5708f000 100644--- a/apps/web/src/app/[locale]/(optional-space)/new/page.tsx+++ b/apps/web/src/app/[locale]/(optional-space)/new/page.tsx@@ -11,6 +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 { CreatePoll } from "@/features/poll/components/create-poll";import { getActiveSpaceForUser } from "@/features/space/data";import { Trans } from "@/i18n/client";@@ -29,7 +30,11 @@ export default async function Page() {}const primaryColor =- space?.showBranding && space.primaryColor ? space.primaryColor : null;+ space?.showBranding &&+ space.primaryColor &&+ (await loadSpaceBrandingAllowed())+ ? space.primaryColor+ : null;return (<div className="page-bg-gray-100 absolute inset-0 h-dvh scroll-pt-16 overflow-auto dark:bg-gray-900">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.tsxindex bcc4ab24a..6dc44aa29 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@@ -1,5 +1,6 @@"use client";+import { Alert, AlertDescription } from "@rallly/ui/alert";import { parseColor } from "@rallly/ui/color-picker";import {Field,@@ -11,6 +12,7 @@ import {} from "@rallly/ui/field";import { toast } from "@rallly/ui/sonner";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";@@ -23,6 +25,7 @@ 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 {updateSpaceAction,@@ -44,6 +47,7 @@ export function CustomBrandingSection({const { data: space } = useSpace();const user = useAuthedUser();const isFree = useIsFree();+ const { spaceBrandingAllowed } = useBranding();const { t } = useTranslation();const currentColor = space.primaryColor ?? DEFAULT_PRIMARY_COLOR;@@ -119,66 +123,84 @@ export function CustomBrandingSection({<PageSectionContent><FieldGroup variant="divided"><SpaceSettingsForm space={space} disabled={disabled} />- <Field orientation="responsive">- <FieldContent>- <FieldTitle id="primary-color-label">- <Trans- i18nKey="primaryColorSettingTitle"- defaults="Primary color"- />- </FieldTitle>- <FieldDescription>- <Trans- i18nKey="primaryColorSettingHint"- defaults="Used for buttons and highlights."- />- </FieldDescription>- </FieldContent>- <ColorPickerWithSaveButton- value={color}- onChange={setColor}- disabled={disabled}- isSaving={updateSpace.isExecuting}- onSave={handleSave}- onReset={handleReset}- showReset={!isDefault}- aria-labelledby="primary-color-label"- />- </Field>- <IfCloudHosted>- <RemoveAttributionSetting disabled={disabled} />- </IfCloudHosted>- <Field>- <Field orientation="horizontal">- <FieldContent>- <FieldLabel htmlFor="show-branding">+ {!spaceBrandingAllowed ? (+ // The divided field group pads its children directly, which would+ // land inside the alert's border — the wrapper takes it instead+ <div>+ <Alert variant="note">+ <LockIcon />+ <AlertDescription><Trans- i18nKey="customBrandingSettingTitle"- defaults="Custom branding"+ i18nKey="customBrandingManagedByInstance"+ defaults="Branding is managed by your instance administrator."/>- {space.tier !== "pro" && <ProBadge />}- </FieldLabel>- <FieldDescription>- <Trans- i18nKey="customBrandingSettingLabel"- defaults="Show your logo and colors to participants."+ </AlertDescription>+ </Alert>+ </div>+ ) : (+ <>+ <Field orientation="responsive">+ <FieldContent>+ <FieldTitle id="primary-color-label">+ <Trans+ i18nKey="primaryColorSettingTitle"+ defaults="Primary color"+ />+ </FieldTitle>+ <FieldDescription>+ <Trans+ i18nKey="primaryColorSettingHint"+ defaults="Used for buttons and highlights."+ />+ </FieldDescription>+ </FieldContent>+ <ColorPickerWithSaveButton+ value={color}+ onChange={setColor}+ disabled={disabled}+ isSaving={updateSpace.isExecuting}+ onSave={handleSave}+ onReset={handleReset}+ showReset={!isDefault}+ aria-labelledby="primary-color-label"+ />+ </Field>+ <IfCloudHosted>+ <RemoveAttributionSetting disabled={disabled} />+ </IfCloudHosted>+ <Field>+ <Field orientation="horizontal">+ <FieldContent>+ <FieldLabel htmlFor="show-branding">+ <Trans+ i18nKey="customBrandingSettingTitle"+ defaults="Custom branding"+ />+ {space.tier !== "pro" && <ProBadge />}+ </FieldLabel>+ <FieldDescription>+ <Trans+ i18nKey="customBrandingSettingLabel"+ defaults="Show your logo and colors to participants."+ />+ </FieldDescription>+ </FieldContent>+ <Switch+ id="show-branding"+ checked={showBranding}+ onCheckedChange={handleToggle}+ disabled={disabled || updateShowBranding.isExecuting}/>- </FieldDescription>- </FieldContent>- <Switch- id="show-branding"- checked={showBranding}- onCheckedChange={handleToggle}- disabled={disabled || updateShowBranding.isExecuting}- />- </Field>- <BrandingPreview- spaceName={space.name}- spaceImage={space.image}- primaryColor={hexColor}- hostName={user.name}- />- </Field>+ </Field>+ <BrandingPreview+ spaceName={space.name}+ spaceImage={space.image}+ primaryColor={hexColor}+ hostName={user.name}+ />+ </Field>+ </>+ )}</FieldGroup></PageSectionContent></PageSection>diff --git a/apps/web/src/app/[locale]/layout.tsx b/apps/web/src/app/[locale]/layout.tsxindex d07638887..bd59bfba1 100644--- a/apps/web/src/app/[locale]/layout.tsx+++ b/apps/web/src/app/[locale]/layout.tsx@@ -12,7 +12,10 @@ 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 } from "@/features/branding/data";+import {+ getInstanceBrandingConfig,+ isSpaceBrandingAllowed,+} from "@/features/branding/data";import { I18nProvider } from "@/i18n/client";import { initI18next } from "@/i18n/i18n";import { TimeZoneSync } from "@/lib/datetime/timezone-sync";@@ -32,14 +35,15 @@ export const viewport: Viewport = {};async function loadData(locale: string) {- const [brandingConfig, { i18n }] = await Promise.all([+ const [brandingConfig, spaceBrandingAllowed, { i18n }] = await Promise.all([getInstanceBrandingConfig(),+ isSpaceBrandingAllowed(),initI18next({ lng: locale }),]);return {resources: i18n.store.data,- brandingConfig,+ brandingConfig: { ...brandingConfig, spaceBrandingAllowed },};}diff --git a/apps/web/src/emails/branding.ts b/apps/web/src/emails/branding.tsindex 102fea767..e19e2f1a0 100644--- a/apps/web/src/emails/branding.ts+++ b/apps/web/src/emails/branding.ts@@ -1,6 +1,9 @@import type { EmailBranding } from "@rallly/emails";-import { getInstanceBrandingConfig } from "@/features/branding/data";+import {+ getInstanceBrandingConfig,+ isSpaceBrandingAllowed,+} from "@/features/branding/data";import { isSelfHosted } from "@/lib/constants";import { resolveStorageUrl } from "@/lib/storage/resolve-storage-url";@@ -28,7 +31,10 @@ export async function getSpaceBranding(space: {primaryColor: string | null;image: string | null;}): Promise<EmailBranding> {- const instance = await getInstanceBranding();+ const [instance, spaceBrandingAllowed] = await Promise.all([+ getInstanceBranding(),+ isSpaceBrandingAllowed(),+ ]);return {...instance,// Space-level attribution removal is cloud-only; self-hosted attribution@@ -36,7 +42,7 @@ export async function getSpaceBranding(space: {// branding.hideAttribution:instance.hideAttribution || (!isSelfHosted && space.hideAttribution),- ...(space.showBranding+ ...(space.showBranding && spaceBrandingAllowed? {primaryColor: space.primaryColor ?? instance.primaryColor,logoUrl: space.imagediff --git a/apps/web/src/features/branding/client.tsx b/apps/web/src/features/branding/client.tsxindex e55689d41..b59f652fd 100644--- a/apps/web/src/features/branding/client.tsx+++ b/apps/web/src/features/branding/client.tsx@@ -18,12 +18,18 @@ export interface BrandingConfig {appName: string;}-const BrandingContext = React.createContext<BrandingConfig | undefined>(+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>(undefined,);interface BrandingProviderProps {- value: BrandingConfig;+ value: BrandingContextValue;children: React.ReactNode;}@@ -35,7 +41,7 @@ export function BrandingProvider({ value, children }: BrandingProviderProps) {);}-export function useBranding(): BrandingConfig {+export function useBranding(): BrandingContextValue {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.tsindex d5aca6e5c..98c716ba9 100644--- a/apps/web/src/features/branding/data.ts+++ b/apps/web/src/features/branding/data.ts@@ -55,3 +55,22 @@ 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.tsindex 02288443f..5d62c56b9 100644--- a/apps/web/src/features/branding/loaders.ts+++ b/apps/web/src/features/branding/loaders.ts@@ -5,9 +5,11 @@ 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 } from "./data";+import { getCustomBrandingConfig, isSpaceBrandingAllowed } 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 thediff --git a/apps/web/src/features/poll/components/event-card.tsx b/apps/web/src/features/poll/components/event-card.tsxindex 6486f2069..bc6e26413 100644--- a/apps/web/src/features/poll/components/event-card.tsx+++ b/apps/web/src/features/poll/components/event-card.tsx@@ -2,6 +2,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 { usePoll } from "@/features/poll/client";import {EventMetaDescription,@@ -45,6 +46,7 @@ function IconDescription({export function EventCard() {const poll = usePoll();+ const branding = useBranding();return (<Card><RandomGradientBar />@@ -60,6 +62,19 @@ export function EventCard() {{poll.space.name}</p></div>+ ) : !branding.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">+ <SpaceIcon+ name={branding.appName}+ src={branding.logoIcon}+ size="xl"+ />+ <p className="mt-2 font-medium text-muted-foreground text-sm">+ {branding.appName}+ </p>+ </div>) : null}<div><EventMetaTitle>{poll.title}</EventMetaTitle>diff --git a/apps/web/src/features/space/actions.ts b/apps/web/src/features/space/actions.tsindex 305aa6892..c7cc03690 100644--- a/apps/web/src/features/space/actions.ts+++ b/apps/web/src/features/space/actions.ts@@ -4,6 +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 { spaceIconAssetProfile } from "@/features/space/constants";import { getActiveSpaceForUser } from "@/features/space/data";import { defineAbilityForMember } from "@/features/space/member/ability";@@ -193,6 +194,13 @@ export const updateSpaceAction = authActionClient});}+ if (parsedInput.primaryColor && !(await isSpaceBrandingAllowed())) {+ throw new AppError({+ code: "FORBIDDEN",+ message: "Space branding is managed by the instance administrator",+ });+ }+await updateSpace({spaceId: space.id,name: parsedInput.name,@@ -234,6 +242,13 @@ export const updateSpaceShowBrandingAction = authActionClient});}+ if (parsedInput.showBranding && !(await isSpaceBrandingAllowed())) {+ throw new AppError({+ code: "FORBIDDEN",+ message: "Space branding is managed by the instance administrator",+ });+ }+await updateSpaceShowBranding({spaceId: space.id,showBranding: parsedInput.showBranding,diff --git a/apps/web/src/features/space/client.tsx b/apps/web/src/features/space/client.tsxindex 95ed66299..e6e3b4294 100644--- a/apps/web/src/features/space/client.tsx+++ b/apps/web/src/features/space/client.tsx@@ -2,6 +2,7 @@import { posthog } from "@rallly/posthog/client";import React from "react";+import { useBranding } from "@/features/branding/client";import { getPrimaryColorVars } from "@/features/branding/utils";import { defineAbilityForMember } from "@/features/space/member/ability";import type { SpaceDTO } from "@/features/space/types";@@ -52,8 +53,10 @@ export function SpaceProvider({posthog?.group("space", space.id);}, [space.id]);+ const { spaceBrandingAllowed } = useBranding();+const primaryColorVars =- space.showBranding && space.primaryColor+ spaceBrandingAllowed && space.showBranding && space.primaryColor? getPrimaryColorVars(space.primaryColor): null;diff --git a/apps/web/src/features/space/data.ts b/apps/web/src/features/space/data.tsindex f860b6fad..bd1d89eeb 100644--- a/apps/web/src/features/space/data.ts+++ b/apps/web/src/features/space/data.ts@@ -9,6 +9,7 @@ import { createLogger } from "@rallly/logger";import { cache } from "react";import { getSpaceSubscription } from "@/features/billing/data";+import { isSpaceBrandingAllowed } from "@/features/branding/data";import { cached_getInstanceLicense } from "@/features/licensing/data";import type { LicenseType } from "@/features/licensing/schema";import type { MemberDTO } from "@/features/space/member/types";@@ -198,8 +199,8 @@ export const getMember = async (id: string) => {return createMemberDTO(member);};-export function getSpaceBranding(spaceId: string) {- return prisma.space.findUnique({+export async function getSpaceBranding(spaceId: string) {+ const space = await prisma.space.findUnique({where: { id: spaceId },select: {name: true,@@ -208,6 +209,16 @@ export function getSpaceBranding(spaceId: string) {primaryColor: true,},});++ if (!space) {+ return null;+ }++ if (!(await isSpaceBrandingAllowed())) {+ return { ...space, showBranding: false, primaryColor: null };+ }++ return space;}export const getOwnedSpace = cache(async (userId: string) => {diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.tsindex 75ab7bcd2..54adcb5fb 100644--- a/apps/web/src/trpc/routers/polls.ts+++ b/apps/web/src/trpc/routers/polls.ts@@ -8,6 +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 { moderateContent } from "@/features/moderation/mutations";import { recordPollActivities } from "@/features/poll/activity/mutations";import {@@ -832,6 +833,8 @@ export const polls = router({}: null;+ const spaceBrandingAllowed = await isSpaceBrandingAllowed();+return {...res,// Space-level attribution removal is cloud-only; self-hosted@@ -840,6 +843,10 @@ export const polls = router({space: res.space? {...res.space,+ showBranding: res.space.showBranding && spaceBrandingAllowed,+ primaryColor: spaceBrandingAllowed+ ? res.space.primaryColor+ : null,hideAttribution: !isSelfHosted && res.space.hideAttribution,}: null,