chore: rename DWD to DelegationCredential (#19703)

* chore: rename DWD to DelegationCredential

* fixup! chore: rename DWD to DelegationCredential

* fixup! fixup! chore: rename DWD to DelegationCredential

* fixup! Merge branch 'main' into rename-domain-wide-delegation

* fixup! fixup! Merge branch 'main' into rename-domain-wide-delegation

* fixup! fixup! fixup! Merge branch 'main' into rename-domain-wide-delegation
This commit is contained in:
Morgan authored and GitHub committed 2025-03-04 09:45:39 -03:00
1 parent a39b5e47a7
commit 7a9ddf2194
167 files changed
+4232 -2356

No files matched your search

@@ -1,28 +1,28 @@
import { isDwdCredential } from "@calcom/lib/domainWideDelegation/clientAndServer";
import { isDelegationCredential } from "@calcom/lib/delegationCredential/clientAndServer";
export function buildCredentialPayloadForPrisma({
credentialId,
domainWideDelegationCredentialId,
delegationCredentialId,
}: {
credentialId: number | null | undefined;
domainWideDelegationCredentialId: string | null | undefined;
delegationCredentialId: string | null | undefined;
}) {
if (credentialId === undefined) {
return {
credentialId,
domainWideDelegationCredentialId,
delegationCredentialId,
};
}
if (isDwdCredential({ credentialId })) {
if (isDelegationCredential({ credentialId })) {
return {
credentialId: null,
domainWideDelegationCredentialId,
delegationCredentialId,
};
} else {
return {
credentialId,
domainWideDelegationCredentialId: null,
delegationCredentialId: null,
};
}
}
@@ -1,6 +1,6 @@
import type { Prisma } from "@prisma/client";
import { enrichUserWithDwdCredentialsWithoutOrgId } from "@calcom/lib/domainWideDelegation/server";
import { enrichUserWithDelegationCredentialsWithoutOrgId } from "@calcom/lib/delegationCredential/server";
import { availabilityUserSelect } from "@calcom/prisma";
import { prisma } from "@calcom/prisma";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
@@ -23,7 +23,7 @@ export async function findUsersForAvailabilityCheck({ where }: { where: Prisma.U
return null;
}
return await enrichUserWithDwdCredentialsWithoutOrgId({
return await enrichUserWithDelegationCredentialsWithoutOrgId({
user: withSelectedCalendars(user),
});
}
+3 -3
View File
@@ -2,13 +2,13 @@ import { prisma } from "@calcom/prisma";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import { enrichUserWithDwdCredentialsWithoutOrgId } from "../domainWideDelegation/server";
import { enrichUserWithDelegationCredentialsWithoutOrgId } from "../delegationCredential/server";
type SessionUser = NonNullable<TrpcSessionUser>;
type User = { id: SessionUser["id"]; email: SessionUser["email"] };
/**
* It includes in-memory DWD credentials as well.
* It includes in-memory DelegationCredential credentials as well.
*/
export async function getUsersCredentials(user: User) {
const credentials = await prisma.credential.findMany({
@@ -21,7 +21,7 @@ export async function getUsersCredentials(user: User) {
},
});
const { credentials: allCredentials } = await enrichUserWithDwdCredentialsWithoutOrgId({
const { credentials: allCredentials } = await enrichUserWithDelegationCredentialsWithoutOrgId({
user: {
email: user.email,
id: user.id,
@@ -4,7 +4,7 @@ import { describe, expect, it, beforeEach, vi } from "vitest";
import { encryptServiceAccountKey } from "@calcom/lib/server/serviceAccountKey";
import { DomainWideDelegationRepository } from "../domainWideDelegation";
import { DelegationCredentialRepository } from "../delegationCredential";
import { OrganizationRepository } from "../organization";
vi.mock("../organization", () => ({
@@ -56,7 +56,7 @@ const buildMockOrganization = () => ({
isOrganization: true,
});
const buildMockDomainWideDelegation = (overrides = {}) => ({
const buildMockDelegationCredential = (overrides = {}) => ({
id: "test-id",
enabled: true,
domain: "example.com",
@@ -68,7 +68,7 @@ const buildMockDomainWideDelegation = (overrides = {}) => ({
});
// Test Utilities
const createTestDomainWideDelegation = async (overrides = {}) => {
const createTestDelegationCredential = async (overrides = {}) => {
// Create organization first (as a team with isOrganization true)
await prismock.team.create({
data: buildMockOrganization(),
@@ -79,9 +79,9 @@ const createTestDomainWideDelegation = async (overrides = {}) => {
data: buildMockWorkspacePlatform(),
});
const data = buildMockDomainWideDelegation(overrides);
const data = buildMockDelegationCredential(overrides);
return await prismock.domainWideDelegation.create({
return await prismock.delegationCredential.create({
data: {
...data,
serviceAccountKey: encryptServiceAccountKey(data.serviceAccountKey),
@@ -96,9 +96,9 @@ const setupOrganizationMock = (returnValue: any) => {
vi.mocked(OrganizationRepository.findByMemberEmail).mockResolvedValue(returnValue);
};
describe("DomainWideDelegationRepository", () => {
describe("DelegationCredentialRepository", () => {
beforeEach(() => {
prismock.domainWideDelegation.deleteMany();
prismock.delegationCredential.deleteMany();
prismock.workspacePlatform.deleteMany();
prismock.team.deleteMany();
vi.clearAllMocks();
@@ -106,13 +106,13 @@ describe("DomainWideDelegationRepository", () => {
describe("Service Account Key Access Control", () => {
beforeEach(async () => {
await createTestDomainWideDelegation();
await createTestDelegationCredential();
});
describe("Regular Find Methods (No Service Account Key)", () => {
describe("findById", () => {
it("should not expose service account key in response", async () => {
const result = await DomainWideDelegationRepository.findById({ id: "test-id" });
const result = await DelegationCredentialRepository.findById({ id: "test-id" });
expect(result).not.toHaveProperty("serviceAccountKey");
expect(result).toEqual(
@@ -127,7 +127,7 @@ describe("DomainWideDelegationRepository", () => {
describe("findAllByDomain", () => {
it("should not expose service account key in any of the results", async () => {
const results = await DomainWideDelegationRepository.findAllByDomain({ domain: "example.com" });
const results = await DelegationCredentialRepository.findAllByDomain({ domain: "example.com" });
expect(results.length).toBeGreaterThan(0);
results.forEach((result) => {
@@ -145,7 +145,7 @@ describe("DomainWideDelegationRepository", () => {
describe("Sensitive Methods (With Service Account Key)", () => {
describe("findByIdIncludeSensitiveServiceAccountKey", () => {
it("should expose valid service account key", async () => {
const result = await DomainWideDelegationRepository.findByIdIncludeSensitiveServiceAccountKey({
const result = await DelegationCredentialRepository.findByIdIncludeSensitiveServiceAccountKey({
id: "test-id",
});
@@ -156,7 +156,7 @@ describe("DomainWideDelegationRepository", () => {
describe("findByOrgIdIncludeSensitiveServiceAccountKey", () => {
it("should expose validated service account keys", async () => {
const results = await DomainWideDelegationRepository.findByOrgIdIncludeSensitiveServiceAccountKey({
const results = await DelegationCredentialRepository.findByOrgIdIncludeSensitiveServiceAccountKey({
organizationId: 1,
});
@@ -170,7 +170,7 @@ describe("DomainWideDelegationRepository", () => {
describe("findUniqueByOrganizationIdAndDomainIncludeSensitiveServiceAccountKey", () => {
it("should expose validated service account key", async () => {
const result =
await DomainWideDelegationRepository.findUniqueByOrganizationIdAndDomainIncludeSensitiveServiceAccountKey(
await DelegationCredentialRepository.findUniqueByOrganizationIdAndDomainIncludeSensitiveServiceAccountKey(
{
organizationId: 1,
domain: "example.com",
@@ -187,7 +187,7 @@ describe("DomainWideDelegationRepository", () => {
setupOrganizationMock({ id: 1 });
const result =
await DomainWideDelegationRepository.findUniqueByOrgMemberEmailIncludeSensitiveServiceAccountKey({
await DelegationCredentialRepository.findUniqueByOrgMemberEmailIncludeSensitiveServiceAccountKey({
email: "[email protected]",
});
@@ -200,7 +200,7 @@ describe("DomainWideDelegationRepository", () => {
setupOrganizationMock(null);
const result =
await DomainWideDelegationRepository.findUniqueByOrgMemberEmailIncludeSensitiveServiceAccountKey({
await DelegationCredentialRepository.findUniqueByOrgMemberEmailIncludeSensitiveServiceAccountKey({
email: "[email protected]",
});
@@ -212,7 +212,7 @@ describe("DomainWideDelegationRepository", () => {
describe("CRUD Operations", () => {
describe("create", () => {
it("should store domain wide delegation with all required fields and establish connections", async () => {
it("should store delegation credential with all required fields and establish connections", async () => {
// Create organization first (as a team with isOrganization true)
await prismock.team.create({
data: buildMockOrganization(),
@@ -223,11 +223,11 @@ describe("DomainWideDelegationRepository", () => {
data: buildMockWorkspacePlatform(),
});
const data = buildMockDomainWideDelegation();
const data = buildMockDelegationCredential();
delete data.id; // ID is auto-generated
delete data.workspacePlatform; // Don't include the relation in create
const result = await DomainWideDelegationRepository.create(data);
const result = await DelegationCredentialRepository.create(data);
expect(result).toEqual({
id: expect.any(String),
@@ -246,7 +246,7 @@ describe("DomainWideDelegationRepository", () => {
describe("update", () => {
it("should modify workspace platform connection when workspacePlatformId is provided", async () => {
const created = await createTestDomainWideDelegation();
const created = await createTestDelegationCredential();
// Create new workspace platform
const newWorkspacePlatform = await prismock.workspacePlatform.create({
@@ -257,7 +257,7 @@ describe("DomainWideDelegationRepository", () => {
},
});
const result = await DomainWideDelegationRepository.updateById({
const result = await DelegationCredentialRepository.updateById({
id: created.id,
data: { workspacePlatformId: newWorkspacePlatform.id },
});
@@ -277,7 +277,7 @@ describe("DomainWideDelegationRepository", () => {
});
it("should modify organization connection when organizationId is provided", async () => {
const created = await createTestDomainWideDelegation();
const created = await createTestDelegationCredential();
// Create new organization (as a team with isOrganization true)
const newOrganization = await prismock.team.create({
@@ -288,7 +288,7 @@ describe("DomainWideDelegationRepository", () => {
},
});
const result = await DomainWideDelegationRepository.updateById({
const result = await DelegationCredentialRepository.updateById({
id: created.id,
data: { organizationId: newOrganization.id },
});
@@ -308,9 +308,9 @@ describe("DomainWideDelegationRepository", () => {
});
it("should modify specified fields while preserving others", async () => {
const created = await createTestDomainWideDelegation();
const created = await createTestDelegationCredential();
const result = await DomainWideDelegationRepository.updateById({
const result = await DelegationCredentialRepository.updateById({
id: created.id,
data: { enabled: false },
});
@@ -326,12 +326,12 @@ describe("DomainWideDelegationRepository", () => {
});
describe("delete", () => {
it("should remove the domain wide delegation completely", async () => {
const created = await createTestDomainWideDelegation();
it("should remove the delegation credential completely", async () => {
const created = await createTestDelegationCredential();
await DomainWideDelegationRepository.deleteById({ id: created.id });
await DelegationCredentialRepository.deleteById({ id: created.id });
const result = await prismock.domainWideDelegation.findUnique({
const result = await prismock.delegationCredential.findUnique({
where: { id: created.id },
});
expect(result).toBeNull();
+7 -7
View File
@@ -2,7 +2,7 @@ import { prisma } from "@calcom/prisma";
import { safeCredentialSelect } from "@calcom/prisma/selects/credential";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
import { buildNonDwdCredential } from "../../domainWideDelegation/server";
import { buildNonDelegationCredential } from "../../delegationCredential/server";
type CredentialCreateInput = {
type: string;
@@ -14,7 +14,7 @@ type CredentialCreateInput = {
export class CredentialRepository {
static async create(data: CredentialCreateInput) {
const credential = await prisma.credential.create({ data: { ...data } });
return buildNonDwdCredential(credential);
return buildNonDelegationCredential(credential);
}
static async findByAppIdAndUserId({ appId, userId }: { appId: string; userId: number }) {
const credential = await prisma.credential.findFirst({
@@ -23,7 +23,7 @@ export class CredentialRepository {
userId,
},
});
return buildNonDwdCredential(credential);
return buildNonDelegationCredential(credential);
}
/**
@@ -31,7 +31,7 @@ export class CredentialRepository {
*/
static async findFirstByIdWithUser({ id }: { id: number }) {
const credential = await prisma.credential.findFirst({ where: { id }, select: safeCredentialSelect });
return buildNonDwdCredential(credential);
return buildNonDelegationCredential(credential);
}
/**
@@ -42,7 +42,7 @@ export class CredentialRepository {
where: { id },
select: { ...safeCredentialSelect, key: true },
});
return buildNonDwdCredential(credential);
return buildNonDelegationCredential(credential);
}
static async findFirstByAppIdAndUserId({ appId, userId }: { appId: string; userId: number }) {
@@ -56,7 +56,7 @@ export class CredentialRepository {
static async findFirstByUserIdAndType({ userId, type }: { userId: number; type: string }) {
const credential = await prisma.credential.findFirst({ where: { userId, type } });
return buildNonDwdCredential(credential);
return buildNonDelegationCredential(credential);
}
static async deleteById({ id }: { id: number }) {
@@ -73,6 +73,6 @@ export class CredentialRepository {
return dbCredential;
}
return buildNonDwdCredential(dbCredential);
return buildNonDelegationCredential(dbCredential);
}
}
@@ -13,8 +13,8 @@ import { prisma } from "@calcom/prisma";
import { OrganizationRepository } from "./organization";
export type { ServiceAccountKey };
const repositoryLogger = logger.getSubLogger({ prefix: ["DomainWideDelegationRepository"] });
const domainWideDelegationSafeSelect = {
const repositoryLogger = logger.getSubLogger({ prefix: ["DelegationCredentialRepository"] });
const delegationCredentialSafeSelect = {
id: true,
enabled: true,
domain: true,
@@ -29,12 +29,12 @@ const domainWideDelegationSafeSelect = {
},
};
const domainWideDelegationSelectIncludesServiceAccountKey = {
...domainWideDelegationSafeSelect,
const delegationCredentialSelectIncludesServiceAccountKey = {
...delegationCredentialSafeSelect,
serviceAccountKey: true,
};
export class DomainWideDelegationRepository {
export class DelegationCredentialRepository {
private static encryptServiceAccountKey(serviceAccountKey: ServiceAccountKey): EncryptedServiceAccountKey {
return encryptServiceAccountKey(serviceAccountKey);
}
@@ -44,12 +44,12 @@ export class DomainWideDelegationRepository {
}
private static withParsedServiceAccountKey<T extends { serviceAccountKey: Prisma.JsonValue } | null>(
domainWideDelegation: T
delegationCredential: T
) {
if (!domainWideDelegation) {
if (!delegationCredential) {
return null;
}
const { serviceAccountKey, ...rest } = domainWideDelegation;
const { serviceAccountKey, ...rest } = delegationCredential;
// Decrypt the service account key if it exists
const decryptedKey = this.decryptServiceAccountKey(serviceAccountKey);
@@ -69,7 +69,7 @@ export class DomainWideDelegationRepository {
serviceAccountKey: ServiceAccountKey;
}) {
const encryptedKey = this.encryptServiceAccountKey(data.serviceAccountKey);
return await prisma.domainWideDelegation.create({
return await prisma.delegationCredential.create({
data: {
workspacePlatform: {
connect: {
@@ -85,14 +85,14 @@ export class DomainWideDelegationRepository {
},
serviceAccountKey: encryptedKey,
},
select: domainWideDelegationSafeSelect,
select: delegationCredentialSafeSelect,
});
}
static async findById({ id }: { id: string }) {
return await prisma.domainWideDelegation.findUnique({
return await prisma.delegationCredential.findUnique({
where: { id },
select: domainWideDelegationSafeSelect,
select: delegationCredentialSafeSelect,
});
}
@@ -103,20 +103,20 @@ export class DomainWideDelegationRepository {
organizationId: number;
domain: string;
}) {
const dwd = await prisma.domainWideDelegation.findUnique({
const delegationCredential = await prisma.delegationCredential.findUnique({
where: { organizationId_domain: { organizationId, domain } },
select: domainWideDelegationSelectIncludesServiceAccountKey,
select: delegationCredentialSelectIncludesServiceAccountKey,
});
return DomainWideDelegationRepository.withParsedServiceAccountKey(dwd);
return DelegationCredentialRepository.withParsedServiceAccountKey(delegationCredential);
}
static async findByIdIncludeSensitiveServiceAccountKey({ id }: { id: string }) {
const domainWideDelegation = await prisma.domainWideDelegation.findUnique({
const delegationCredential = await prisma.delegationCredential.findUnique({
where: { id },
select: domainWideDelegationSelectIncludesServiceAccountKey,
select: delegationCredentialSelectIncludesServiceAccountKey,
});
if (!domainWideDelegation) return null;
return DomainWideDelegationRepository.withParsedServiceAccountKey(domainWideDelegation);
if (!delegationCredential) return null;
return DelegationCredentialRepository.withParsedServiceAccountKey(delegationCredential);
}
static async findUniqueByOrgMemberEmailIncludeSensitiveServiceAccountKey({ email }: { email: string }) {
@@ -131,23 +131,23 @@ export class DomainWideDelegationRepository {
}
const emailDomain = email.split("@")[1];
const domainWideDelegation = await prisma.domainWideDelegation.findUnique({
const delegationCredential = await prisma.delegationCredential.findUnique({
where: {
organizationId_domain: {
organizationId: organization.id,
domain: emailDomain,
},
},
select: domainWideDelegationSelectIncludesServiceAccountKey,
select: delegationCredentialSelectIncludesServiceAccountKey,
});
return DomainWideDelegationRepository.withParsedServiceAccountKey(domainWideDelegation);
return DelegationCredentialRepository.withParsedServiceAccountKey(delegationCredential);
}
static async findAllByDomain({ domain }: { domain: string }) {
return await prisma.domainWideDelegation.findMany({
return await prisma.delegationCredential.findMany({
where: { domain },
select: domainWideDelegationSafeSelect,
select: delegationCredentialSafeSelect,
});
}
@@ -164,7 +164,7 @@ export class DomainWideDelegationRepository {
}>;
}) {
const { workspacePlatformId, organizationId, ...rest } = data;
return await prisma.domainWideDelegation.update({
return await prisma.delegationCredential.update({
where: { id },
data: {
...(workspacePlatformId && {
@@ -183,21 +183,21 @@ export class DomainWideDelegationRepository {
}),
...rest,
},
select: domainWideDelegationSafeSelect,
select: delegationCredentialSafeSelect,
});
}
static async deleteById({ id }: { id: string }) {
return await prisma.domainWideDelegation.delete({
return await prisma.delegationCredential.delete({
where: { id },
});
}
static async findByOrgIdIncludeSensitiveServiceAccountKey({ organizationId }: { organizationId: number }) {
return await prisma.domainWideDelegation.findMany({
return await prisma.delegationCredential.findMany({
where: { organizationId },
select: {
...domainWideDelegationSelectIncludesServiceAccountKey,
...delegationCredentialSelectIncludesServiceAccountKey,
workspacePlatform: {
select: {
id: true,
@@ -44,24 +44,24 @@ export class DestinationCalendarRepository {
externalId?: string;
credentialId?: number | null;
primaryEmail?: string | null;
domainWideDelegationCredentialId?: string | null;
delegationCredentialId?: string | null;
};
create: {
integration: string;
externalId: string;
credentialId: number | null;
primaryEmail?: string | null;
domainWideDelegationCredentialId?: string | null;
delegationCredentialId?: string | null;
};
}) {
const credentialPayloadForUpdate = buildCredentialPayloadForPrisma({
credentialId: update.credentialId,
domainWideDelegationCredentialId: update.domainWideDelegationCredentialId,
delegationCredentialId: update.delegationCredentialId,
});
const credentialPayloadForCreate = buildCredentialPayloadForPrisma({
credentialId: create.credentialId,
domainWideDelegationCredentialId: create.domainWideDelegationCredentialId,
delegationCredentialId: create.delegationCredentialId,
});
return await prisma.destinationCalendar.upsert({
@@ -290,13 +290,13 @@ describe("SelectedCalendarRepository", () => {
});
});
describe("Domain Wide Delegation", () => {
it("should create a selected calendar with domainWideDelegationCredentialId", async () => {
describe("Delegation Credential", () => {
it("should create a selected calendar with delegationCredentialId", async () => {
const data = {
userId: 1,
integration: "google_calendar",
externalId: "[email protected]",
domainWideDelegationCredentialId: "dwd-123",
delegationCredentialId: "delegationCredential-123",
};
const result = await SelectedCalendarRepository.create(data);
@@ -306,7 +306,7 @@ describe("SelectedCalendarRepository", () => {
describe("upsert", () => {
describe("updation", () => {
it("should update existing record with domainWideDelegationCredentialId if credentialId is -1", async () => {
it("should update existing record with delegationCredentialId if credentialId is -1", async () => {
const initialData = {
userId: 1,
integration: "google_calendar",
@@ -322,17 +322,17 @@ describe("SelectedCalendarRepository", () => {
integration: "google_calendar",
externalId: "[email protected]",
credentialId: -1,
domainWideDelegationCredentialId: "dwd-123",
delegationCredentialId: "delegationCredential-123",
};
const result = await SelectedCalendarRepository.upsert(data);
expect(result.id).not.toBe(null);
expect(result.id).toBe(existingCalendar.id);
expect(result.credentialId).toBe(null);
expect(result.domainWideDelegationCredentialId).toBe(data.domainWideDelegationCredentialId);
expect(result.delegationCredentialId).toBe(data.delegationCredentialId);
});
it("should update existing record with credentialId if credentialId is valid(>0) even if domainWideDelegationCredentialId is set", async () => {
it("should update existing record with credentialId if credentialId is valid(>0) even if delegationCredentialId is set", async () => {
const initialData = {
userId: 1,
integration: "google_calendar",
@@ -348,19 +348,19 @@ describe("SelectedCalendarRepository", () => {
integration: "google_calendar",
externalId: "[email protected]",
credentialId: 2,
domainWideDelegationCredentialId: "dwd-123",
delegationCredentialId: "delegationCredential-123",
};
const result = await SelectedCalendarRepository.upsert(data);
expect(result.id).not.toBe(null);
expect(result.id).toBe(existingCalendar.id);
expect(result.credentialId).toBe(data.credentialId);
expect(result.domainWideDelegationCredentialId).toBeNull();
expect(result.delegationCredentialId).toBeNull();
});
});
describe("creation", () => {
it("should create a new record with domainWideDelegationCredentialId if credentialId is -1", async () => {
it("should create a new record with delegationCredentialId if credentialId is -1", async () => {
const initialData = {
userId: 1,
integration: "google_calendar",
@@ -376,7 +376,7 @@ describe("SelectedCalendarRepository", () => {
integration: "google_calendar",
externalId: "[email protected]",
credentialId: -1,
domainWideDelegationCredentialId: "dwd-123",
delegationCredentialId: "delegationCredential-123",
};
// It will create a new record because of unique constraint violation
@@ -384,17 +384,17 @@ describe("SelectedCalendarRepository", () => {
expect(result.id).not.toBe(null);
expect(result.id).not.toBe(existingCalendar.id);
expect(result.credentialId).toBe(null);
expect(result.domainWideDelegationCredentialId).toBe(data.domainWideDelegationCredentialId);
expect(result.delegationCredentialId).toBe(data.delegationCredentialId);
});
});
it("shouldnt update existing domainWideDelegationCredentialId if upsert data doesn't have it", async () => {
it("shouldnt update existing delegationCredentialId if upsert data doesn't have it", async () => {
const initialData = {
userId: 1,
integration: "google_calendar",
externalId: "[email protected]",
eventTypeId: null,
domainWideDelegationCredentialId: "dwd-123",
delegationCredentialId: "delegationCredential-123",
credentialId: 1,
};
@@ -410,16 +410,16 @@ describe("SelectedCalendarRepository", () => {
const result = await SelectedCalendarRepository.upsert(data);
expect(result.id).toBe(existingCalendar.id);
expect(result.credentialId).toBe(existingCalendar.credentialId);
expect(result.domainWideDelegationCredentialId).toBe(null);
expect(result.delegationCredentialId).toBe(null);
});
it("shouldnt update domainWideDelegationCredentialId if it is undefined", async () => {
it("shouldnt update delegationCredentialId if it is undefined", async () => {
const initialData = {
userId: 1,
integration: "google_calendar",
externalId: "[email protected]",
eventTypeId: null,
domainWideDelegationCredentialId: "dwd-123",
delegationCredentialId: "delegationCredential-123",
};
const existingCalendar = await SelectedCalendarRepository.create(initialData);
@@ -433,9 +433,7 @@ describe("SelectedCalendarRepository", () => {
const result = await SelectedCalendarRepository.upsert(data);
expect(result.id).toBe(existingCalendar.id);
expect(result.credentialId).toBe(existingCalendar.credentialId);
expect(result.domainWideDelegationCredentialId).toBe(
existingCalendar.domainWideDelegationCredentialId
);
expect(result.delegationCredentialId).toBe(existingCalendar.delegationCredentialId);
});
});
});
@@ -82,7 +82,7 @@ export class SelectedCalendarRepository {
// So, this unique constraint can't be used in upsert. Prisma doesn't allow that, So, we do create and update separately
const credentialPayload = buildCredentialPayloadForPrisma({
credentialId: data.credentialId,
domainWideDelegationCredentialId: data.domainWideDelegationCredentialId,
delegationCredentialId: data.delegationCredentialId,
});
const newData = {
+2 -2
View File
@@ -12,7 +12,7 @@ import { userMetadata } from "@calcom/prisma/zod-utils";
import type { UpId, UserProfile } from "@calcom/types/UserProfile";
import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "../../availability";
import { buildNonDwdCredentials } from "../../domainWideDelegation/clientAndServer";
import { buildNonDelegationCredentials } from "../../delegationCredential/clientAndServer";
import { withSelectedCalendars } from "../withSelectedCalendars";
import { ProfileRepository } from "./profile";
import { getParsedTeam } from "./teamUtils";
@@ -786,7 +786,7 @@ export class UserRepository {
const { credentials, ...userWithSelectedCalendars } = withSelectedCalendars(user);
return {
...userWithSelectedCalendars,
credentials: buildNonDwdCredentials(credentials),
credentials: buildNonDelegationCredentials(credentials),
};
}