From 4aa0b4cc65993b988d8c5ba71557f3c0c80d2b98 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Mon, 8 Jan 2024 20:55:48 +0530 Subject: [PATCH] fix: Team URL and booker URLs (#13050) Co-authored-by: Bailey Pumfleet Co-authored-by: Peer Richelsen --- apps/web/lib/orgMigration.test.ts | 4 +++- apps/web/test/utils/bookingScenario/test.ts | 4 +++- .../ee/organizations/lib/orgDomains.ts | 7 +++--- .../ee/teams/components/TeamListItem.tsx | 22 ++++++++----------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/apps/web/lib/orgMigration.test.ts b/apps/web/lib/orgMigration.test.ts index 2bf8fb7093..18b924dbc2 100644 --- a/apps/web/lib/orgMigration.test.ts +++ b/apps/web/lib/orgMigration.test.ts @@ -3,12 +3,14 @@ import prismock from "../../../tests/libs/__mocks__/prisma"; import { describe, expect, it } from "vitest"; import type { z } from "zod"; +import { WEBSITE_URL } from "@calcom/lib/constants"; import type { MembershipRole, Prisma } from "@calcom/prisma/client"; import { RedirectType } from "@calcom/prisma/enums"; import type { teamMetadataSchema } from "@calcom/prisma/zod-utils"; import { moveTeamToOrg, moveUserToOrg, removeTeamFromOrg, removeUserFromOrg } from "./orgMigration"; +const WEBSITE_PROTOCOL = new URL(WEBSITE_URL).protocol; describe("orgMigration", () => { describe("moveUserToOrg", () => { describe("when user email does not match orgAutoAcceptEmail", () => { @@ -1366,7 +1368,7 @@ async function expectRedirectToBeEnabled({ } expect(redirect).not.toBeNull(); - expect(redirect?.toUrl).toBe(`http://${orgSlug}.cal.local:3000/${to}`); + expect(redirect?.toUrl).toBe(`${WEBSITE_PROTOCOL}//${orgSlug}.cal.local:3000/${to}`); if (!redirect) { throw new Error(`Redirect doesn't exist for ${JSON.stringify(tempOrgRedirectWhere)}`); } diff --git a/apps/web/test/utils/bookingScenario/test.ts b/apps/web/test/utils/bookingScenario/test.ts index 74eb503f86..7a00f894fd 100644 --- a/apps/web/test/utils/bookingScenario/test.ts +++ b/apps/web/test/utils/bookingScenario/test.ts @@ -1,9 +1,11 @@ import type { TestFunction } from "vitest"; +import { WEBSITE_URL } from "@calcom/lib/constants"; import { test } from "@calcom/web/test/fixtures/fixtures"; import type { Fixtures } from "@calcom/web/test/fixtures/fixtures"; import { createOrganization } from "@calcom/web/test/utils/bookingScenario/bookingScenario"; +const WEBSITE_PROTOCOL = new URL(WEBSITE_URL).protocol; const _testWithAndWithoutOrg = ( description: Parameters[0], fn: Parameters[1], @@ -28,7 +30,7 @@ const _testWithAndWithoutOrg = ( skip, org: { organization: org, - urlOrigin: `http://${org.slug}.cal.local:3000`, + urlOrigin: `${WEBSITE_PROTOCOL}//${org.slug}.cal.local:3000`, }, }); }, diff --git a/packages/features/ee/organizations/lib/orgDomains.ts b/packages/features/ee/organizations/lib/orgDomains.ts index 461f5e2c03..ebb0c9d73e 100644 --- a/packages/features/ee/organizations/lib/orgDomains.ts +++ b/packages/features/ee/organizations/lib/orgDomains.ts @@ -1,7 +1,7 @@ import type { Prisma } from "@prisma/client"; import type { IncomingMessage } from "http"; -import { IS_PRODUCTION } from "@calcom/lib/constants"; +import { IS_PRODUCTION, WEBSITE_URL } from "@calcom/lib/constants"; import { ALLOWED_HOSTNAMES, RESERVED_SUBDOMAINS, WEBAPP_URL } from "@calcom/lib/constants"; import logger from "@calcom/lib/logger"; import slugify from "@calcom/lib/slugify"; @@ -100,9 +100,10 @@ export function subdomainSuffix() { } export function getOrgFullOrigin(slug: string, options: { protocol: boolean } = { protocol: true }) { - if (!slug) return options.protocol ? WEBAPP_URL : WEBAPP_URL.replace("https://", "").replace("http://", ""); + if (!slug) + return options.protocol ? WEBSITE_URL : WEBSITE_URL.replace("https://", "").replace("http://", ""); const orgFullOrigin = `${ - options.protocol ? `${new URL(WEBAPP_URL).protocol}//` : "" + options.protocol ? `${new URL(WEBSITE_URL).protocol}//` : "" }${slug}.${subdomainSuffix()}`; return orgFullOrigin; } diff --git a/packages/features/ee/teams/components/TeamListItem.tsx b/packages/features/ee/teams/components/TeamListItem.tsx index 4355ad6461..0eb04d4140 100644 --- a/packages/features/ee/teams/components/TeamListItem.tsx +++ b/packages/features/ee/teams/components/TeamListItem.tsx @@ -107,9 +107,7 @@ export default function TeamListItem(props: Props) { {team.name} {team.slug ? ( - `${getTeamUrlSync({ orgSlug: team.parent ? team.parent.slug : null, teamSlug: team.slug })}/${ - team.slug - }` + `${getTeamUrlSync({ orgSlug: team.parent ? team.parent.slug : null, teamSlug: team.slug })}` ) : ( {t("upgrade")} )} @@ -245,11 +243,10 @@ export default function TeamListItem(props: Props) { color="secondary" onClick={() => { navigator.clipboard.writeText( - `${ - orgBranding - ? `${orgBranding.fullDomain}` - : `${process.env.NEXT_PUBLIC_WEBSITE_URL}/team` - }/${team.slug}` + `${getTeamUrlSync({ + orgSlug: team.parent ? team.parent.slug : null, + teamSlug: team.slug, + })}` ); showToast(t("link_copied"), "success"); }} @@ -285,11 +282,10 @@ export default function TeamListItem(props: Props) { {t("preview_team") as string}