Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow non-calcom domains to run team slug pages #18711

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/web/lib/team/[slug]/[type]/getServerSideProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
import { getBookingForReschedule } from "@calcom/features/bookings/lib/get-booking";
import { getSlugOrRequestedSlug, orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
import { getOrganizationSEOSettings } from "@calcom/features/ee/organizations/lib/orgSettings";
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
import slugify from "@calcom/lib/slugify";
import prisma from "@calcom/prisma";
import { RedirectType } from "@calcom/prisma/client";
Expand Down Expand Up @@ -179,7 +179,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
eventData,
});

const organizationSettings = OrganizationRepository.utils.getOrganizationSEOSettings(team);
const organizationSettings = getOrganizationSEOSettings(team);
const allowSEOIndexing = organizationSettings?.allowSEOIndexing ?? false;

if (!eventData) {
Expand Down
15 changes: 12 additions & 3 deletions apps/web/lib/team/[slug]/getServerSideProps.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import type { GetServerSidePropsContext } from "next";

import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
import {
getOrganizationSettings,
getVerifiedDomain,
} from "@calcom/features/ee/organizations/lib/orgSettings";
import { getFeatureFlag } from "@calcom/features/flags/server/utils";
import { IS_CALCOM } from "@calcom/lib/constants";
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
import logger from "@calcom/lib/logger";
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
import { getTeamWithMembers } from "@calcom/lib/server/queries/teams";
import { OrganizationRepository } from "@calcom/lib/server/repository/organization";
import slugify from "@calcom/lib/slugify";
import { stripMarkdown } from "@calcom/lib/stripMarkdown";
import prisma from "@calcom/prisma";
Expand All @@ -30,8 +34,13 @@ function getOrgProfileRedirectToVerifiedDomain(
if (!team.isOrganization) {
return null;
}
// when this is not on a Cal.com page we don't auto redirect -
// good for diagnosis purposes.
if (!IS_CALCOM) {
return null;
}

const verifiedDomain = OrganizationRepository.utils.getVerifiedDomain(settings);
const verifiedDomain = getVerifiedDomain(settings);

if (!settings.orgProfileRedirectsToVerifiedDomain || !verifiedDomain) {
return null;
Expand Down Expand Up @@ -145,7 +154,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
} as const;
}

const organizationSettings = OrganizationRepository.utils.getOrganizationSettings(team);
const organizationSettings = getOrganizationSettings(team);
const allowSEOIndexing = organizationSettings?.allowSEOIndexing ?? false;

const redirectToVerifiedDomain = organizationSettings
Expand Down
38 changes: 38 additions & 0 deletions packages/features/ee/organizations/lib/orgSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { OrganizationSettings } from "@calcom/prisma/client";

type MinimumOrganizationSettings = Pick<
OrganizationSettings,
"orgAutoAcceptEmail" | "orgProfileRedirectsToVerifiedDomain" | "allowSEOIndexing"
>;

type SEOOrganizationSettings = Pick<OrganizationSettings, "allowSEOIndexing">;

export const getOrganizationSettings = (team: {
isOrganization: boolean;
organizationSettings: MinimumOrganizationSettings | null;
parent: {
organizationSettings: MinimumOrganizationSettings | null;
} | null;
}) => {
if (!team) return null;
if (team.isOrganization) return team.organizationSettings ?? null;
if (!team.parent) return null;
return team.parent.organizationSettings ?? null;
};

export const getOrganizationSEOSettings = (team: {
isOrganization: boolean;
organizationSettings: SEOOrganizationSettings | null;
parent: {
organizationSettings: SEOOrganizationSettings | null;
} | null;
}) => {
if (!team) return null;
if (team.isOrganization) return team.organizationSettings ?? null;
if (!team.parent) return null;
return team.parent.organizationSettings ?? null;
};

export const getVerifiedDomain = (settings: Pick<OrganizationSettings, "orgAutoAcceptEmail">) => {
return settings.orgAutoAcceptEmail;
};
40 changes: 0 additions & 40 deletions packages/lib/server/repository/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import { prisma } from "@calcom/prisma";
import type { OrganizationSettings } from "@calcom/prisma/client";
import { MembershipRole } from "@calcom/prisma/enums";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";

import { createAProfileForAnExistingUser } from "../../createAProfileForAnExistingUser";
import { getParsedTeam } from "./teamUtils";
import { UserRepository } from "./user";

type MinimumOrganizationSettings = Pick<
OrganizationSettings,
"orgAutoAcceptEmail" | "orgProfileRedirectsToVerifiedDomain" | "allowSEOIndexing"
>;
type SEOOrganizationSettings = Pick<OrganizationSettings, "allowSEOIndexing">;
const orgSelect = {
id: true,
name: true,
Expand Down Expand Up @@ -356,38 +350,4 @@ export class OrganizationRepository {

return org?.calVideoLogo;
}

static utils = {
/**
* Gets the organization setting if the team is an organization.
* If not, it gets the organization setting of the parent organization.
*/
getOrganizationSettings: (team: {
isOrganization: boolean;
organizationSettings: MinimumOrganizationSettings | null;
parent: {
organizationSettings: MinimumOrganizationSettings | null;
} | null;
}) => {
if (!team) return null;
if (team.isOrganization) return team.organizationSettings ?? null;
if (!team.parent) return null;
return team.parent.organizationSettings ?? null;
},
getOrganizationSEOSettings: (team: {
isOrganization: boolean;
organizationSettings: SEOOrganizationSettings | null;
parent: {
organizationSettings: SEOOrganizationSettings | null;
} | null;
}) => {
if (!team) return null;
if (team.isOrganization) return team.organizationSettings ?? null;
if (!team.parent) return null;
return team.parent.organizationSettings ?? null;
},
getVerifiedDomain(settings: Pick<OrganizationSettings, "orgAutoAcceptEmail">) {
return settings.orgAutoAcceptEmail;
},
};
}
Loading