From a18015b1e5fa38e8e37bd10a7df73434f4069680 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Tue, 20 Aug 2024 19:35:34 +0400 Subject: [PATCH] Fix: Use unique parameter for passing devops org name Used to be teamId, now it's azureDevopsOrgName. --- .../server/routes/v1/integration-auth-router.ts | 1 + .../integration-auth/integration-app-list.ts | 9 +++++---- .../integration-auth/integration-auth-service.ts | 2 ++ .../integration-auth/integration-auth-types.ts | 1 + frontend/src/hooks/api/integrationAuth/queries.tsx | 9 +++++++++ .../pages/integrations/azure-devops/authorize.tsx | 14 +++++++++----- .../src/pages/integrations/azure-devops/create.tsx | 4 ++-- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/backend/src/server/routes/v1/integration-auth-router.ts b/backend/src/server/routes/v1/integration-auth-router.ts index 963b7101c..4baa39f76 100644 --- a/backend/src/server/routes/v1/integration-auth-router.ts +++ b/backend/src/server/routes/v1/integration-auth-router.ts @@ -293,6 +293,7 @@ export const registerIntegrationAuthRouter = async (server: FastifyZodProvider) }), querystring: z.object({ teamId: z.string().trim().optional(), + azureDevOpsOrgName: z.string().trim().optional(), workspaceSlug: z.string().trim().optional() }), response: { diff --git a/backend/src/services/integration-auth/integration-app-list.ts b/backend/src/services/integration-auth/integration-app-list.ts index 4fd8264f5..bd7c19228 100644 --- a/backend/src/services/integration-auth/integration-app-list.ts +++ b/backend/src/services/integration-auth/integration-app-list.ts @@ -1030,11 +1030,10 @@ const getAppsCloud66 = async ({ accessToken }: { accessToken: string }) => { return apps; }; -const getAppsAzureDevOps = async ({ accessToken, orgId }: { accessToken: string; orgId: string }) => { - console.log({ accessToken, orgId }); +const getAppsAzureDevOps = async ({ accessToken, orgName }: { accessToken: string; orgName: string }) => { const res = ( await request.get<{ count: number; value: Record[] }>( - `${IntegrationUrls.AZURE_DEVOPS_API_URL}/${orgId}/_apis/projects?api-version=7.2-preview.2`, + `${IntegrationUrls.AZURE_DEVOPS_API_URL}/${orgName}/_apis/projects?api-version=7.2-preview.2`, { headers: { Authorization: `Basic ${accessToken}` @@ -1055,6 +1054,7 @@ export const getApps = async ({ accessToken, accessId, teamId, + azureDevOpsOrgName, workspaceSlug, url }: { @@ -1062,6 +1062,7 @@ export const getApps = async ({ accessToken: string; accessId?: string; teamId?: string | null; + azureDevOpsOrgName?: string | null; workspaceSlug?: string; url?: string | null; }): Promise => { @@ -1207,7 +1208,7 @@ export const getApps = async ({ case Integrations.AZURE_DEVOPS: return getAppsAzureDevOps({ accessToken, - orgId: teamId as string // small hack to pass orgId as teamId + orgName: azureDevOpsOrgName as string }); default: diff --git a/backend/src/services/integration-auth/integration-auth-service.ts b/backend/src/services/integration-auth/integration-auth-service.ts index e16f6bb77..7b201e6ea 100644 --- a/backend/src/services/integration-auth/integration-auth-service.ts +++ b/backend/src/services/integration-auth/integration-auth-service.ts @@ -440,6 +440,7 @@ export const integrationAuthServiceFactory = ({ actorOrgId, actorAuthMethod, teamId, + azureDevOpsOrgName, id, workspaceSlug }: TIntegrationAuthAppsDTO) => { @@ -462,6 +463,7 @@ export const integrationAuthServiceFactory = ({ accessToken, accessId, teamId, + azureDevOpsOrgName, workspaceSlug, url: integrationAuth.url }); diff --git a/backend/src/services/integration-auth/integration-auth-types.ts b/backend/src/services/integration-auth/integration-auth-types.ts index 44b6d4c4c..af390297a 100644 --- a/backend/src/services/integration-auth/integration-auth-types.ts +++ b/backend/src/services/integration-auth/integration-auth-types.ts @@ -29,6 +29,7 @@ export type TDeleteIntegrationAuthsDTO = TProjectPermission & { export type TIntegrationAuthAppsDTO = { id: string; teamId?: string; + azureDevOpsOrgName?: string; workspaceSlug?: string; } & Omit; diff --git a/frontend/src/hooks/api/integrationAuth/queries.tsx b/frontend/src/hooks/api/integrationAuth/queries.tsx index 45ac90a84..efb5ad7fb 100644 --- a/frontend/src/hooks/api/integrationAuth/queries.tsx +++ b/frontend/src/hooks/api/integrationAuth/queries.tsx @@ -120,16 +120,22 @@ const fetchIntegrationAuthById = async (integrationAuthId: string) => { const fetchIntegrationAuthApps = async ({ integrationAuthId, teamId, + azureDevOpsOrgName, workspaceSlug }: { integrationAuthId: string; teamId?: string; + azureDevOpsOrgName?: string; workspaceSlug?: string; }) => { const params: Record = {}; if (teamId) { params.teamId = teamId; } + if (azureDevOpsOrgName) { + params.azureDevOpsOrgName = azureDevOpsOrgName; + } + if (workspaceSlug) { params.workspaceSlug = workspaceSlug; } @@ -452,10 +458,12 @@ export const useGetIntegrationAuthById = (integrationAuthId: string) => { export const useGetIntegrationAuthApps = ({ integrationAuthId, teamId, + azureDevOpsOrgName, workspaceSlug }: { integrationAuthId: string; teamId?: string; + azureDevOpsOrgName?: string; workspaceSlug?: string; }) => { return useQuery({ @@ -464,6 +472,7 @@ export const useGetIntegrationAuthApps = ({ fetchIntegrationAuthApps({ integrationAuthId, teamId, + azureDevOpsOrgName, workspaceSlug }), enabled: true diff --git a/frontend/src/pages/integrations/azure-devops/authorize.tsx b/frontend/src/pages/integrations/azure-devops/authorize.tsx index 8dbb2e946..2f4d17628 100644 --- a/frontend/src/pages/integrations/azure-devops/authorize.tsx +++ b/frontend/src/pages/integrations/azure-devops/authorize.tsx @@ -10,7 +10,7 @@ export default function AzureDevopsCreateIntegrationPage() { const { mutateAsync } = useSaveIntegrationAccessToken(); const [apiKey, setApiKey] = useState(""); - const [orgId, setOrgId] = useState(""); + const [devopsOrgName, setDevopsOrgName] = useState(""); const [apiKeyErrorText, setApiKeyErrorText] = useState(""); const [isLoading, setIsLoading] = useState(false); @@ -24,7 +24,7 @@ export default function AzureDevopsCreateIntegrationPage() { setIsLoading(true); - localStorage.setItem("azure-devops-org-id", orgId); + localStorage.setItem("azure-devops-org-name", devopsOrgName); const integrationAuth = await mutateAsync({ workspaceId: localStorage.getItem("projectData.id"), @@ -52,12 +52,16 @@ export default function AzureDevopsCreateIntegrationPage() { setApiKey(e.target.value)} /> - setOrgId(e.target.value)} /> + setDevopsOrgName(e.target.value)} + /> diff --git a/frontend/src/pages/integrations/azure-devops/create.tsx b/frontend/src/pages/integrations/azure-devops/create.tsx index 59b9720d8..d34636106 100644 --- a/frontend/src/pages/integrations/azure-devops/create.tsx +++ b/frontend/src/pages/integrations/azure-devops/create.tsx @@ -29,7 +29,7 @@ export default function AzureDevopsCreateIntegrationPage() { const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? ""); const { data: integrationAuthApps } = useGetIntegrationAuthApps({ integrationAuthId: (integrationAuthId as string) ?? "", - teamId: localStorage.getItem("azure-devops-org-id") ?? "" + azureDevOpsOrgName: localStorage.getItem("azure-devops-org-name") ?? "" }); const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState(""); @@ -63,7 +63,7 @@ export default function AzureDevopsCreateIntegrationPage() { await mutateAsync({ integrationAuthId: integrationAuth?.id, isActive: true, - app: localStorage.getItem("azure-devops-org-id") || "", + app: localStorage.getItem("azure-devops-org-name") || "", appId: targetApp, sourceEnvironment: selectedSourceEnvironment, secretPath