fix: filter Google Workspace credentials by current user (#26216)
* fix: filter Google Workspace credentials by current user Add userId filter to getUsersFromGWorkspace credential query and add unit tests for all googleWorkspace handler functions. Also fix OAuth2Client import to use google-auth-library for proper type compatibility * refactor(tests): improve googleWorkspace handler test structure Move dynamic imports to beforeEach block to reduce repetition and improve test readability --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
This commit is contained in:
co-authored by
Keith Williams
parent
f629b61be7
commit
f8dcc6b13d
@@ -1,5 +1,5 @@
|
||||
import { admin_directory_v1 } from "@googleapis/admin";
|
||||
import { OAuth2Client } from "googleapis-common";
|
||||
import { OAuth2Client } from "google-auth-library";
|
||||
import { z } from "zod";
|
||||
|
||||
import getAppKeysFromSlug from "@calcom/app-store/_utils/getAppKeysFromSlug";
|
||||
@@ -33,7 +33,7 @@ export const checkForGWorkspace = async ({ ctx }: CheckForGCalOptions) => {
|
||||
return { id: gWorkspacePresent?.id };
|
||||
};
|
||||
|
||||
export const getUsersFromGWorkspace = async ({}: CheckForGCalOptions) => {
|
||||
export const getUsersFromGWorkspace = async ({ ctx }: CheckForGCalOptions) => {
|
||||
const { client_id, client_secret } = await getAppKeysFromSlug("google-calendar");
|
||||
if (!client_id || typeof client_id !== "string") throw new Error("Google client_id missing.");
|
||||
if (!client_secret || typeof client_secret !== "string") throw new Error("Google client_secret missing.");
|
||||
@@ -41,6 +41,7 @@ export const getUsersFromGWorkspace = async ({}: CheckForGCalOptions) => {
|
||||
const hasExistingCredentials = await prisma.credential.findFirst({
|
||||
where: {
|
||||
type: "google_workspace_directory",
|
||||
userId: ctx.user.id,
|
||||
},
|
||||
});
|
||||
if (!hasExistingCredentials) {
|
||||
@@ -56,7 +57,7 @@ export const getUsersFromGWorkspace = async ({}: CheckForGCalOptions) => {
|
||||
|
||||
// Create a new instance of the Admin SDK directory API
|
||||
const directory = new admin_directory_v1.Admin({
|
||||
auth: oAuth2Client as any,
|
||||
auth: oAuth2Client,
|
||||
});
|
||||
const { data } = await directory.users.list({
|
||||
maxResults: 200, // Up this if we ever need to get more than 200 users
|
||||
|
||||
Reference in New Issue
Block a user