fix: DelegationCredential - Duplicate GoogleMeet and unnecessary serviceAccount key access (#21269)
* Remove unused return statement * Fix return from fn instead of continuing the loop * Ensure userId is set for existing records on update * ensure that serviceAccountKey is only retrieved whenb assked
This commit is contained in:
1 parent
deb55c0536
commit
df75df7008
32 files changed
+196
-113
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { enrichUserWithDelegationCredentialsWithoutOrgId } from "@calcom/lib/delegationCredential/server";
|
||||
import { enrichUserWithDelegationCredentialsIncludeServiceAccountKey } 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 enrichUserWithDelegationCredentialsWithoutOrgId({
|
||||
return await enrichUserWithDelegationCredentialsIncludeServiceAccountKey({
|
||||
user: withSelectedCalendars(user),
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
|
||||
import { DailyLocationType } from "@calcom/app-store/locations";
|
||||
import getApps from "@calcom/app-store/utils";
|
||||
import { getUsersCredentials } from "@calcom/lib/server/getUsersCredentials";
|
||||
import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials";
|
||||
import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { EventTypeLocation } from "@calcom/prisma/zod/custom/eventtype";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
@@ -17,7 +17,8 @@ export async function getDefaultLocations(user: User): Promise<EventTypeLocation
|
||||
const defaultConferencingData = userMetadataSchema.parse(user.metadata)?.defaultConferencingApp;
|
||||
|
||||
if (defaultConferencingData && defaultConferencingData.appSlug !== "daily-video") {
|
||||
const credentials = await getUsersCredentials(user);
|
||||
// We are not returning the credential, so we are fine with the service account key
|
||||
const credentials = await getUsersCredentialsIncludeServiceAccountKey(user);
|
||||
|
||||
const foundApp = getApps(credentials, true).filter(
|
||||
(app) => app.slug === defaultConferencingData.appSlug
|
||||
|
||||
@@ -2,7 +2,7 @@ import { prisma } from "@calcom/prisma";
|
||||
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { enrichUserWithDelegationCredentialsWithoutOrgId } from "../delegationCredential/server";
|
||||
import { enrichUserWithDelegationCredentialsIncludeServiceAccountKey } from "../delegationCredential/server";
|
||||
|
||||
type SessionUser = NonNullable<TrpcSessionUser>;
|
||||
type User = { id: SessionUser["id"]; email: SessionUser["email"] };
|
||||
@@ -10,7 +10,7 @@ type User = { id: SessionUser["id"]; email: SessionUser["email"] };
|
||||
/**
|
||||
* It includes in-memory DelegationCredential credentials as well.
|
||||
*/
|
||||
export async function getUsersCredentials(user: User) {
|
||||
export async function getUsersCredentialsIncludeServiceAccountKey(user: User) {
|
||||
const credentials = await prisma.credential.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
@@ -21,7 +21,7 @@ export async function getUsersCredentials(user: User) {
|
||||
},
|
||||
});
|
||||
|
||||
const { credentials: allCredentials } = await enrichUserWithDelegationCredentialsWithoutOrgId({
|
||||
const { credentials: allCredentials } = await enrichUserWithDelegationCredentialsIncludeServiceAccountKey({
|
||||
user: {
|
||||
email: user.email,
|
||||
id: user.id,
|
||||
@@ -31,3 +31,8 @@ export async function getUsersCredentials(user: User) {
|
||||
|
||||
return allCredentials;
|
||||
}
|
||||
|
||||
export async function getUsersCredentials(user: User) {
|
||||
const credentials = await getUsersCredentialsIncludeServiceAccountKey(user);
|
||||
return credentials.map(({ delegatedTo: _1, ...rest }) => rest);
|
||||
}
|
||||
Reference in new issue
Block a user