Skip to content

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

✨ Gate conferencing providers per user until their apps are approved (#3375)

Luke Vellade955de5bb85
diff --git a/.worktreeinclude b/.worktreeinclude
new file mode 100644
index 000000000..85e14844d
--- /dev/null
+++ b/.worktreeinclude
@@ -0,0 +1,7 @@
+# Gitignored files Claude Code copies from the main checkout into each new
+# worktree, so every worktree starts with the same local configuration.
+apps/web/.env
+apps/landing/.env
+packages/database/.env
+packages/billing/.env
+packages/posthog/.env
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 35d5958c7..e51315f03 100644
--- a/apps/web/src/app/[locale]/(optional-space)/new/page.tsx
+++ b/apps/web/src/app/[locale]/(optional-space)/new/page.tsx
@@ -22,8 +22,8 @@ import { getSession } from "@/lib/auth";
export default async function Page() {
const session = await getSession();
- const userId =
- session?.user.id && !session.user.isGuest ? session.user.id : null;
+ const user = session?.user && !session.user.isGuest ? session.user : null;
+ const userId = user?.id ?? null;
const space = userId ? await getActiveSpaceForUser(userId) : null;
@@ -31,7 +31,10 @@ export default async function Page() {
redirect("/setup");
}
- const conferencing = await loadConferencingOptions({ userId });
+ const conferencing = await loadConferencingOptions({
+ userId,
+ email: user?.email ?? null,
+ });
const primaryColor =
space?.primaryColor &&
diff --git a/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx b/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx
index 094347e50..0d78af5b1 100644
--- a/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx
@@ -33,7 +33,11 @@ import { useAuthedUser } from "@/features/user/client";
import { Trans, useTranslation } from "@/i18n/client";
import { useFeatureFlag } from "@/lib/feature-flags/client";
-export function AccountSidebarMenu() {
+export function AccountSidebarMenu({
+ showConferencing,
+}: {
+ showConferencing: boolean;
+}) {
const { t } = useTranslation();
const pathname = usePathname();
const menuItems = [
@@ -70,7 +74,6 @@ export function AccountSidebarMenu() {
];
const isCalendarsEnabled = useFeatureFlag("calendars");
- const isConferencingEnabled = useFeatureFlag("conferencing");
if (isCalendarsEnabled) {
menuItems.push({
@@ -81,7 +84,7 @@ export function AccountSidebarMenu() {
});
}
- if (isConferencingEnabled) {
+ if (showConferencing) {
menuItems.push({
id: "conferencing",
label: t("conferencing", { defaultValue: "Conferencing" }),
diff --git a/apps/web/src/app/[locale]/(space)/settings/conferencing/page.tsx b/apps/web/src/app/[locale]/(space)/settings/conferencing/page.tsx
index 4aabaf13a..3d2d5c71a 100644
--- a/apps/web/src/app/[locale]/(space)/settings/conferencing/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/conferencing/page.tsx
@@ -14,13 +14,29 @@ import { Spinner } from "@/components/spinner";
import { ConferencingConnectionFlash } from "@/features/conferencing/components/conferencing-connection-flash";
import { ConferencingConnectionList } from "@/features/conferencing/components/conferencing-connection-list";
import { ConnectConferencingDropdown } from "@/features/conferencing/components/connect-conferencing-dropdown";
-import { getAvailableConferencingProviders } from "@/features/conferencing/constants";
-import { loadConferencingConnections } from "@/features/conferencing/loaders";
+import {
+ loadAvailableConferencingProviders,
+ loadConferencingConnections,
+} from "@/features/conferencing/loaders";
import { integrationIdToConferencingProvider } from "@/features/conferencing/utils";
import { Trans } from "@/i18n/client";
import { getTranslation } from "@/i18n/server";
import { isFeatureEnabled } from "@/lib/feature-flags/server";
+// The page exists for a user only while some provider is offered to them.
+async function AvailabilityGate() {
+ const providers = await loadAvailableConferencingProviders();
+ if (providers.length === 0) {
+ notFound();
+ }
+ return null;
+}
+
+async function ConnectAction() {
+ const providers = await loadAvailableConferencingProviders();
+ return <ConnectConferencingDropdown providers={providers} />;
+}
+
export default function ConferencingPage() {
if (!isFeatureEnabled("conferencing")) {
notFound();
@@ -28,6 +44,9 @@ export default function ConferencingPage() {
return (
<SettingsPage>
+ <Suspense fallback={null}>
+ <AvailabilityGate />
+ </Suspense>
<ConferencingConnectionFlash />
<SettingsPageHeader>
<SettingsPageTitle>
@@ -40,9 +59,9 @@ export default function ConferencingPage() {
/>
</SettingsPageDescription>
<SettingsPageAction>
- <ConnectConferencingDropdown
- providers={getAvailableConferencingProviders()}
- />
+ <Suspense fallback={null}>
+ <ConnectAction />
+ </Suspense>
</SettingsPageAction>
</SettingsPageHeader>
<SettingsPageContent>
diff --git a/apps/web/src/app/[locale]/(space)/settings/layout.tsx b/apps/web/src/app/[locale]/(space)/settings/layout.tsx
index 0389f6df5..83c6f824f 100644
--- a/apps/web/src/app/[locale]/(space)/settings/layout.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/layout.tsx
@@ -16,8 +16,10 @@ import {
} from "@rallly/ui/sidebar";
import { ArrowLeftIcon, SettingsIcon } from "lucide-react";
import type React from "react";
+import { Suspense } from "react";
import { HoverPrefetchLink } from "@/components/hover-prefetch-link";
import { PastDueAlert } from "@/features/billing/components/past-due-alert";
+import { loadAvailableConferencingProviders } from "@/features/conferencing/loaders";
import { NavUser } from "@/features/user/components/nav-user";
import { Trans } from "@/i18n/client";
import {
@@ -26,6 +28,11 @@ import {
SpaceSidebarMenu,
} from "./components/sidebar";
+async function AccountMenu() {
+ const providers = await loadAvailableConferencingProviders();
+ return <AccountSidebarMenu showConferencing={providers.length > 0} />;
+}
+
export default function Layout({ children }: { children?: React.ReactNode }) {
return (
<SidebarProvider>
@@ -62,7 +69,11 @@ export default function Layout({ children }: { children?: React.ReactNode }) {
<Trans i18nKey="account" defaults="Account" />
</SidebarGroupLabel>
<SidebarGroupContent>
- <AccountSidebarMenu />
+ <Suspense
+ fallback={<AccountSidebarMenu showConferencing={false} />}
+ >
+ <AccountMenu />
+ </Suspense>
</SidebarGroupContent>
</SidebarGroup>
<SidebarGroup>
diff --git a/apps/web/src/app/api/integrations/[...connection]/route.ts b/apps/web/src/app/api/integrations/[...connection]/route.ts
index a0ea486d6..692d75a80 100644
--- a/apps/web/src/app/api/integrations/[...connection]/route.ts
+++ b/apps/web/src/app/api/integrations/[...connection]/route.ts
@@ -3,8 +3,12 @@ import {
createCalendarConnection,
syncCalendars,
} from "@/features/calendars/mutations";
-import { isConferencingEnabled } from "@/features/conferencing/constants";
+import {
+ isConferencingEnabled,
+ isConferencingProviderAllowedFor,
+} from "@/features/conferencing/constants";
import { createConferencingConnection } from "@/features/conferencing/mutations";
+import type { ConferencingProvider } from "@/features/conferencing/schema";
import { saveOAuthCredentials } from "@/features/credentials/mutations";
import { getSession } from "@/lib/auth";
import { GoogleOAuthClient } from "@/lib/oauth/providers/google";
@@ -26,6 +30,14 @@ async function requireSessionUserId() {
return session.user.id;
}
+async function isAllowedForSession(provider: ConferencingProvider) {
+ const session = await getSession();
+ return isConferencingProviderAllowedFor({
+ provider,
+ email: session?.user.email ?? null,
+ });
+}
+
function conferencingOnConnect({
integrationId,
displayName,
@@ -57,7 +69,7 @@ function conferencingOnConnect({
const { handler } = OAuthIntegration<Integration>({
basePath: "/api/integrations",
- getIntegration: ({ integrationId, callbackUrl }) => {
+ getIntegration: async ({ integrationId, callbackUrl }) => {
switch (integrationId) {
case "google-calendar": {
if (!env.GOOGLE_CLIENT_ID || !env.GOOGLE_CLIENT_SECRET) {
@@ -108,7 +120,8 @@ const { handler } = OAuthIntegration<Integration>({
if (
!isConferencingEnabled ||
!env.GOOGLE_CLIENT_ID ||
- !env.GOOGLE_CLIENT_SECRET
+ !env.GOOGLE_CLIENT_SECRET ||
+ !(await isAllowedForSession("meet"))
) {
return null;
}
@@ -131,7 +144,8 @@ const { handler } = OAuthIntegration<Integration>({
if (
!isConferencingEnabled ||
!env.ZOOM_CLIENT_ID ||
- !env.ZOOM_CLIENT_SECRET
+ !env.ZOOM_CLIENT_SECRET ||
+ !(await isAllowedForSession("zoom"))
) {
return null;
}
diff --git a/apps/web/src/env.ts b/apps/web/src/env.ts
index 2907d7bd9..75202b537 100644
--- a/apps/web/src/env.ts
+++ b/apps/web/src/env.ts
@@ -118,6 +118,10 @@ export const env = createEnv({
ZOOM_CLIENT_SECRET: z.string().optional(),
// Signs Zoom's event notifications, including app deauthorization.
ZOOM_WEBHOOK_SECRET_TOKEN: z.string().optional(),
+ // Comma separated. While set, only these accounts are offered the
+ // provider: an unpublished or unverified OAuth app authorizes no one else.
+ ZOOM_ALLOWED_EMAILS: z.string().optional(),
+ GOOGLE_MEET_ALLOWED_EMAILS: z.string().optional(),
/**
* Microsoft Integration
@@ -294,6 +298,8 @@ export const env = createEnv({
ZOOM_CLIENT_ID: process.env.ZOOM_CLIENT_ID,
ZOOM_CLIENT_SECRET: process.env.ZOOM_CLIENT_SECRET,
ZOOM_WEBHOOK_SECRET_TOKEN: process.env.ZOOM_WEBHOOK_SECRET_TOKEN,
+ ZOOM_ALLOWED_EMAILS: process.env.ZOOM_ALLOWED_EMAILS,
+ GOOGLE_MEET_ALLOWED_EMAILS: process.env.GOOGLE_MEET_ALLOWED_EMAILS,
MICROSOFT_TENANT_ID: process.env.MICROSOFT_TENANT_ID,
MICROSOFT_CLIENT_ID: process.env.MICROSOFT_CLIENT_ID,
MICROSOFT_CLIENT_SECRET: process.env.MICROSOFT_CLIENT_SECRET,
diff --git a/apps/web/src/features/conferencing/constants.ts b/apps/web/src/features/conferencing/constants.ts
index 3bede0a8c..db0a12f75 100644
--- a/apps/web/src/features/conferencing/constants.ts
+++ b/apps/web/src/features/conferencing/constants.ts
@@ -1,4 +1,5 @@
import type { ConferencingProvider } from "./schema";
+import { isEmailAllowlisted } from "./utils";
export const isConferencingEnabled =
process.env.CONFERENCING_ENABLED === "true";
@@ -18,3 +19,35 @@ export function getAvailableConferencingProviders(): ConferencingProvider[] {
}
return providers;
}
+
+// While a provider's allowlist is set, only the listed accounts are offered
+// it, for a provider whose OAuth app is not yet published or verified and so
+// authorizes nobody else. Only an unset variable opens the provider to
+// everyone; a set but empty list lets nobody in.
+const providerAllowlists: Record<ConferencingProvider, string | undefined> = {
+ zoom: process.env.ZOOM_ALLOWED_EMAILS,
+ meet: process.env.GOOGLE_MEET_ALLOWED_EMAILS,
+};
+
+export function isConferencingProviderAllowedFor({
+ provider,
+ email,
+}: {
+ provider: ConferencingProvider;
+ email: string | null;
+}) {
+ const allowlist = providerAllowlists[provider];
+ return allowlist === undefined || isEmailAllowlisted({ email, allowlist });
+}
+
+// What this user is offered. Conferencing settings exist for a user only
+// while this is non empty.
+export function getAvailableConferencingProvidersFor({
+ email,
+}: {
+ email: string | null;
+}) {
+ return getAvailableConferencingProviders().filter((provider) =>
+ isConferencingProviderAllowedFor({ provider, email }),
+ );
+}
diff --git a/apps/web/src/features/conferencing/loaders.ts b/apps/web/src/features/conferencing/loaders.ts
index bf4f75a14..df796bf67 100644
--- a/apps/web/src/features/conferencing/loaders.ts
+++ b/apps/web/src/features/conferencing/loaders.ts
@@ -2,12 +2,17 @@ import "server-only";
import { cache } from "react";
import { loadUser } from "@/features/user/loaders";
-import { getAvailableConferencingProviders } from "./constants";
+import { getAvailableConferencingProvidersFor } from "./constants";
import {
getConferencingConnections,
getConnectedConferencingProviders,
} from "./data";
+export const loadAvailableConferencingProviders = cache(async () => {
+ const user = await loadUser();
+ return getAvailableConferencingProvidersFor({ email: user.email });
+});
+
export const loadConferencingConnections = cache(async () => {
const user = await loadUser();
return getConferencingConnections(user.id);
@@ -17,10 +22,19 @@ export const loadConferencingConnections = cache(async () => {
// the organizer has already linked. Guests have nothing to link; a pasted
// link needs no provider, so the options always exist.
export const loadConferencingOptions = cache(
- async ({ userId }: { userId: string | null }) => {
- const available = getAvailableConferencingProviders();
+ async ({
+ userId,
+ email,
+ }: {
+ userId: string | null;
+ email: string | null;
+ }) => {
+ const available = getAvailableConferencingProvidersFor({ email });
+ // A provider the user linked before it was gated is not offered either.
const connected = userId
- ? await getConnectedConferencingProviders(userId)
+ ? (await getConnectedConferencingProviders(userId)).filter((provider) =>
+ available.includes(provider),
+ )
: [];
return { available, connected };
},
diff --git a/apps/web/src/features/conferencing/utils.test.ts b/apps/web/src/features/conferencing/utils.test.ts
index 6888c3d00..d852ba2e5 100644
--- a/apps/web/src/features/conferencing/utils.test.ts
+++ b/apps/web/src/features/conferencing/utils.test.ts
@@ -4,6 +4,7 @@ import { conferencingSchema } from "./schema";
import {
createZoomUrlValidationResponse,
getConferencingUri,
+ isEmailAllowlisted,
meetSpaceResponseSchema,
meetSpaceToConferencing,
verifyZoomWebhookSignature,
@@ -155,3 +156,26 @@ describe("createZoomUrlValidationResponse", () => {
});
});
});
+
+describe("isEmailAllowlisted", () => {
+ const allowlist = "[email protected], [email protected]";
+
+ it("matches a listed address regardless of case and spacing", () => {
+ expect(isEmailAllowlisted({ email: "[email protected]", allowlist })).toBe(
+ true,
+ );
+ expect(
+ isEmailAllowlisted({ email: "[email protected]", allowlist }),
+ ).toBe(true);
+ });
+
+ it("rejects an address that is not listed", () => {
+ expect(
+ isEmailAllowlisted({ email: "[email protected]", allowlist }),
+ ).toBe(false);
+ });
+
+ it("rejects a missing address", () => {
+ expect(isEmailAllowlisted({ email: null, allowlist })).toBe(false);
+ });
+});
diff --git a/apps/web/src/features/conferencing/utils.ts b/apps/web/src/features/conferencing/utils.ts
index 1d06246be..cb81805ff 100644
--- a/apps/web/src/features/conferencing/utils.ts
+++ b/apps/web/src/features/conferencing/utils.ts
@@ -179,3 +179,20 @@ export async function createZoomUrlValidationResponse({
);
return { plainToken, encryptedToken };
}
+
+// A comma separated list of addresses, matched case insensitively.
+export function isEmailAllowlisted({
+ email,
+ allowlist,
+}: {
+ email: string | null;
+ allowlist: string;
+}) {
+ if (!email) {
+ return false;
+ }
+ const normalized = email.trim().toLowerCase();
+ return allowlist
+ .split(",")
+ .some((entry) => entry.trim().toLowerCase() === normalized);
+}
diff --git a/apps/web/src/lib/oauth/server.ts b/apps/web/src/lib/oauth/server.ts
index 09ae387c3..ad1d254a2 100644
--- a/apps/web/src/lib/oauth/server.ts
+++ b/apps/web/src/lib/oauth/server.ts
@@ -72,7 +72,7 @@ export function OAuthIntegration<T extends string>(
try {
const { id } = c.req.valid("param");
- const integration = getIntegration({
+ const integration = await getIntegration({
integrationId: id as T,
callbackUrl: absoluteUrl(`${basePath}/callback/${id}`),
});
@@ -128,7 +128,7 @@ export function OAuthIntegration<T extends string>(
try {
const { id } = c.req.valid("param");
- const integration = getIntegration({
+ const integration = await getIntegration({
integrationId: id as T,
callbackUrl: absoluteUrl(`${basePath}/callback/${id}`),
});
diff --git a/apps/web/src/lib/oauth/types.ts b/apps/web/src/lib/oauth/types.ts
index f0c738fef..6740afbfc 100644
--- a/apps/web/src/lib/oauth/types.ts
+++ b/apps/web/src/lib/oauth/types.ts
@@ -48,7 +48,7 @@ export interface CreateOAuthOptions<T extends string> {
}: {
integrationId: T;
callbackUrl: string;
- }) => OAuthClient | null;
+ }) => OAuthClient | null | Promise<OAuthClient | null>;
cookieConfig?: {
prefix?: string;
maxAge?: number;