Files
Benny JooandDevin AI ab21c7f805 refactor: Cal.diy (#28903)
* feat: Cal.diy — community-driven MIT-licensed fork of Cal.com

This squashed commit contains all Cal.diy changes applied on top of calcom/cal.com main:

- Rebrand Cal.com to Cal.diy across the entire codebase
- Remove Enterprise Edition (EE) features, license checks, and AGPL restrictions
- Switch license from AGPL-3.0 to MIT
- Remove docs/ directory (migrated to Nextra at cal.diy)
- Remove dead code: org tests, EE tips, platform nav, premium username, SAML/SSO, etc.
- Clean up .env.example for self-hosted Cal.diy
- Update Docker image references to calcom/cal.diy
- Update README, CONTRIBUTING.md, and issue templates for Cal.diy community fork
- Add PR welcome bot for Cal.diy contributors
- Fix API v2 breaking changes oasdiff ignore entries
- Replace Blacksmith CI runners with default GitHub Actions

3893 files changed, 20789 insertions(+), 411020 deletions(-)

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* refactor: remove org-specific /organizations/:orgId endpoints from API v2 atoms controllers (#1701)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: revert Cal.diy Inc to Cal.com, Inc. in license files, copyright notices, and package metadata (#1702)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* rip out org related comments in api v2

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-04-15 09:52:36 -03:00

185 lines
4.5 KiB
TypeScript

import { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository";
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
import logger from "@calcom/lib/logger";
import { prisma } from "@calcom/prisma";
const log = logger.getSubLogger({ name: "hideBranding" });
const userRepository = new UserRepository(prisma);
type Team = {
hideBranding: boolean | null;
parent: {
hideBranding: boolean | null;
} | null;
};
type Profile = {
organization: {
hideBranding: boolean | null;
} | null;
};
type UserWithoutProfile = {
id: number;
hideBranding: boolean | null;
};
type UserWithProfile = UserWithoutProfile & {
profile: Profile | null;
};
/**
* Determines if branding should be hidden by checking entity and organization settings
*/
function resolveHideBranding(options: {
entityHideBranding: boolean | null;
organizationHideBranding: boolean | null;
}): boolean {
// If the organization has branding hidden, we should hide branding for the entity regardless of its own setting
if (options.organizationHideBranding) {
return true;
}
return options.entityHideBranding ?? false;
}
/**
* Get hideBranding value for a user or team by their IDs
*/
export async function getHideBranding({
userId,
teamId,
}: {
userId?: number;
teamId?: number;
}): Promise<boolean> {
if (teamId) {
const team = await prisma.team.findUnique({
where: { id: teamId },
select: {
hideBranding: true,
parent: { select: { hideBranding: true } },
},
});
if (!team) return false;
return resolveHideBranding({
entityHideBranding: team.hideBranding,
organizationHideBranding: team.parent?.hideBranding ?? null,
});
} else if (userId) {
// Get user data with profile and organization
const user = await userRepository.findUserWithHideBranding({ userId });
if (!user) return false;
return resolveHideBranding({
entityHideBranding: user.hideBranding,
organizationHideBranding: user.profiles?.[0]?.organization?.hideBranding,
});
}
return false;
}
/**
* Determines if branding should be hidden for an event that could be a team event or user event
*/
export function shouldHideBrandingForEventUsingProfile({
eventTypeId,
owner,
team,
}: {
owner: UserWithProfile | null;
team: Team | null;
eventTypeId: number;
}) {
let hideBranding;
if (team) {
hideBranding = resolveHideBranding({
entityHideBranding: team.hideBranding ?? null,
organizationHideBranding: team.parent?.hideBranding ?? null,
});
} else if (owner) {
hideBranding = resolveHideBranding({
entityHideBranding: owner.hideBranding ?? null,
organizationHideBranding: owner.profile?.organization?.hideBranding ?? null,
});
} else {
log.error(`No owner or team found for event: ${eventTypeId}`);
return false;
}
return hideBranding;
}
/**
* A wrapper over shouldHideBrandingForEventUsingProfile that fetches the profile itself
* Use it when you don't have user's profile
*/
export async function shouldHideBrandingForEvent({
eventTypeId,
team,
owner,
organizationId,
}: {
eventTypeId: number;
team: Team | null;
owner: UserWithoutProfile | null;
organizationId: number | null;
}) {
let ownerProfile = null;
if (team) {
return shouldHideBrandingForTeamEvent({
team,
eventTypeId,
});
} else if (owner) {
// Needed only for User events, not for Team events
ownerProfile = organizationId
? await ProfileRepository.findByUserIdAndOrgSlug({
userId: owner.id,
organizationId,
})
: null;
return shouldHideBrandingForUserEvent({
eventTypeId,
owner: {
...owner,
profile: ownerProfile,
},
});
} else {
log.error(`No owner or team found for event: ${eventTypeId}`);
return false;
}
}
/**
* A convenience wrapper for shouldHideBrandingForEventUsingProfile to use for Team events
*/
export function shouldHideBrandingForTeamEvent({ eventTypeId, team }: { eventTypeId: number; team: Team }) {
return shouldHideBrandingForEventUsingProfile({
owner: null,
team,
eventTypeId,
});
}
/**
* A convenience wrapper for shouldHideBrandingForEventUsingProfile to use for User events
*/
export function shouldHideBrandingForUserEvent({
eventTypeId,
owner,
}: {
eventTypeId: number;
owner: UserWithProfile;
}) {
return shouldHideBrandingForEventUsingProfile({
owner,
team: null,
eventTypeId,
});
}