fix(api): use public username and correct base URL for platform orgs (#26830)
- Use public instead of internal profile username for platform orgs - Use base URL instead of
This commit is contained in:
+7
-6
@@ -85,22 +85,22 @@ describe("OutputEventTypesService_2024_06_14", () => {
|
||||
it("should use cal.com for non-managed users in platform orgs", () => {
|
||||
const user = {
|
||||
id: 1,
|
||||
name: "Dhairyashil Shinde",
|
||||
username: "dhairyashil10101010-gmail-com",
|
||||
name: "Test User",
|
||||
username: "platform-user", // Public username
|
||||
avatarUrl: null,
|
||||
brandColor: null,
|
||||
darkBrandColor: null,
|
||||
weekStart: "Monday",
|
||||
metadata: {},
|
||||
organizationId: 1,
|
||||
organization: { slug: "gmail-platform-9041df0e" },
|
||||
organization: { slug: "platform-org-slug" },
|
||||
movedToProfile: null,
|
||||
profiles: [
|
||||
{
|
||||
id: 100,
|
||||
username: "dhairyashil",
|
||||
username: "platform-user-generated-id", // Platform-generated username
|
||||
organizationId: 1,
|
||||
organization: { id: 1, slug: "gmail-platform-9041df0e", isPlatform: true },
|
||||
organization: { id: 1, slug: "platform-org-slug", isPlatform: true },
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -108,7 +108,8 @@ describe("OutputEventTypesService_2024_06_14", () => {
|
||||
|
||||
const result = service.buildBookingUrl(user, slug);
|
||||
|
||||
expect(result).toBe("https://cal.com/dhairyashil/secret");
|
||||
// Should use user.username (platform-user), not profile.username (platform-user-generated-id)
|
||||
expect(result).toBe("https://cal.com/platform-user/secret");
|
||||
});
|
||||
|
||||
it("should return empty string for managed users", () => {
|
||||
|
||||
+9
-5
@@ -448,17 +448,21 @@ export class OutputEventTypesService_2024_06_14 {
|
||||
}
|
||||
|
||||
const profile = this.usersService.getUserMainProfile(user);
|
||||
const username = profile?.username ?? user.username;
|
||||
const org = profile?.organization;
|
||||
const isPlatformOrg = org?.isPlatform ?? false;
|
||||
|
||||
// For platform orgs, use user.username (public username like 'dhairyashil')
|
||||
// For regular orgs, use profile.username (org-specific username)
|
||||
const username = isPlatformOrg ? user.username : (profile?.username ?? user.username);
|
||||
|
||||
if (!username) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const org = profile?.organization;
|
||||
// Don't use org subdomain for platform organizations - they don't have public-facing subdomains
|
||||
const orgSlug = org && !org.isPlatform ? org.slug : null;
|
||||
const webAppUrl = this.configService.get<string>("app.baseUrl", "https://app.cal.com");
|
||||
const baseUrl = orgSlug ? getBookerBaseUrlSync(orgSlug) : webAppUrl;
|
||||
const orgSlug = !isPlatformOrg && org?.slug ? org.slug : null;
|
||||
// getBookerBaseUrlSync(null) returns WEBSITE_URL (https://cal.com)
|
||||
const baseUrl = getBookerBaseUrlSync(orgSlug);
|
||||
const normalizedBaseUrl = baseUrl.replace(/\/$/, "");
|
||||
|
||||
return `${normalizedBaseUrl}/${username}/${slug}`;
|
||||
|
||||
Reference in New Issue
Block a user