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

91 lines
3.3 KiB
TypeScript

import { OAuthClientRepository } from "@calcom/features/oauth/repositories/OAuthClientRepository";
import type { PrismaClient } from "@calcom/prisma";
import { OAuthClientStatus } from "@calcom/prisma/enums";
import { TRPCError } from "@trpc/server";
import type { TUpdateClientInputSchema } from "./updateClient.schema";
type UpdateClientOptions = {
ctx: {
user: { id: number; role: string };
prisma: PrismaClient;
};
input: TUpdateClientInputSchema;
};
export const updateClientHandler = async ({ ctx, input }: UpdateClientOptions) => {
const { clientId, status, rejectionReason, ...updateFields } = input;
const oAuthClientRepository = new OAuthClientRepository(ctx.prisma);
const existingClient = await oAuthClientRepository.findByClientId(clientId);
if (!existingClient) {
throw new TRPCError({ code: "NOT_FOUND", message: "OAuth Client not found" });
}
const isOwner = existingClient.userId != null && existingClient.userId === ctx.user.id;
const isAdmin = ctx.user.role === "ADMIN";
// Status changes (approve/reject) require admin
if (status !== undefined && !isAdmin) {
throw new TRPCError({ code: "FORBIDDEN", message: "Only admins can change client status" });
}
// Non-status field updates require ownership (or admin)
if (!isOwner && !isAdmin) {
throw new TRPCError({ code: "NOT_FOUND", message: "OAuth Client not found" });
}
// If admin is changing status, update status directly
if (status !== undefined && isAdmin) {
await oAuthClientRepository.updateStatus(clientId, status);
if (status === OAuthClientStatus.REJECTED && rejectionReason) {
await ctx.prisma.oAuthClient.update({
where: { clientId },
data: { rejectionReason },
});
}
}
// Build update data from non-undefined fields
const updateData: {
name?: string;
purpose?: string;
redirectUri?: string;
logo?: string;
websiteUrl?: string;
} = {};
if (updateFields.name !== undefined) updateData.name = updateFields.name;
if (updateFields.purpose !== undefined) updateData.purpose = updateFields.purpose;
if (updateFields.redirectUri !== undefined) updateData.redirectUri = updateFields.redirectUri;
if (updateFields.logo !== undefined) updateData.logo = updateFields.logo ?? undefined;
if (updateFields.websiteUrl !== undefined) updateData.websiteUrl = updateFields.websiteUrl ?? undefined;
if (Object.keys(updateData).length > 0) {
await oAuthClientRepository.update(clientId, updateData);
}
// If redirectUri changed on an APPROVED client, reset to PENDING for re-approval
if (
updateFields.redirectUri !== undefined &&
existingClient.status === OAuthClientStatus.APPROVED &&
updateFields.redirectUri !== existingClient.redirectUri
) {
await oAuthClientRepository.updateStatus(clientId, OAuthClientStatus.PENDING);
}
const updated = await oAuthClientRepository.findByClientId(clientId);
return {
clientId,
name: updated?.name ?? existingClient.name,
purpose: updated?.purpose ?? existingClient.purpose,
redirectUri: updated?.redirectUri ?? existingClient.redirectUri,
websiteUrl: updated?.websiteUrl ?? existingClient.websiteUrl,
logo: updated?.logo ?? existingClient.logo,
status: updated?.status ?? existingClient.status,
rejectionReason: updated?.rejectionReason ?? existingClient.rejectionReason,
};
};