Skip to content

Commit ae1787c

Browse files
github-actions[bot]chasprowebdevMarfuen
authored
[HOTFIX] Add orgId to /api/cloud-tests/providers endpoint (#1926)
* fix(app): add orgId query parameter to /api/cloud-tests/providers endpoint * fix(app): add auth check to api/cloud-tests/providers endpoint * fix(app): verify if the user belongs to the org in cloud-tests/provider endpoint * fix(app): update cloud-tests/findings endpoint to have orgId as query param --------- Co-authored-by: chasprowebdev <[email protected]> Co-authored-by: Mariano Fuentes <[email protected]>
1 parent 15ca0e1 commit ae1787c

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

apps/app/src/app/(app)/[orgId]/cloud-tests/components/TestsLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function TestsLayout({ initialFindings, initialProviders, orgId }: TestsL
7575
const { disconnectConnection } = useIntegrationMutations();
7676

7777
const { data: findings = initialFindings, mutate: mutateFindings } = useSWR<Finding[]>(
78-
'/api/cloud-tests/findings',
78+
`/api/cloud-tests/findings?orgId=${orgId}`,
7979
async (url) => {
8080
const res = await fetch(url);
8181
if (!res.ok) throw new Error('Failed to fetch');
@@ -89,7 +89,7 @@ export function TestsLayout({ initialFindings, initialProviders, orgId }: TestsL
8989
);
9090

9191
const { data: providers = initialProviders, mutate: mutateProviders } = useSWR<Provider[]>(
92-
'/api/cloud-tests/providers',
92+
`/api/cloud-tests/providers?orgId=${orgId}`,
9393
async (url) => {
9494
const res = await fetch(url);
9595
if (!res.ok) throw new Error('Failed to fetch');

apps/app/src/app/api/cloud-tests/findings/route.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
import { auth } from '@/utils/auth';
22
import { db } from '@db';
33
import { headers } from 'next/headers';
4-
import { NextResponse } from 'next/server';
4+
import { NextRequest, NextResponse } from 'next/server';
55

66
const CLOUD_PROVIDER_SLUGS = ['aws', 'gcp', 'azure'];
77

8-
export async function GET() {
8+
export async function GET(request: NextRequest) {
99
try {
1010
const session = await auth.api.getSession({
1111
headers: await headers(),
1212
});
1313

14-
const orgId = session?.session.activeOrganizationId;
14+
if (!session?.user?.id) {
15+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
16+
}
17+
18+
const { searchParams } = new URL(request.url);
19+
const orgId = searchParams.get('orgId');
1520

1621
if (!orgId) {
17-
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
22+
return NextResponse.json({ error: 'Organization ID is required' }, { status: 400 });
23+
}
24+
25+
// Verify the user belongs to the requested organization
26+
const member = await db.member.findFirst({
27+
where: {
28+
userId: session.user.id,
29+
organizationId: orgId,
30+
deactivated: false,
31+
},
32+
});
33+
34+
if (!member) {
35+
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
1836
}
1937

2038
// ====================================================================

apps/app/src/app/api/cloud-tests/providers/route.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { auth } from '@/utils/auth';
22
import { getManifest } from '@comp/integration-platform';
33
import { db } from '@db';
44
import { headers } from 'next/headers';
5-
import { NextResponse } from 'next/server';
5+
import { NextRequest, NextResponse } from 'next/server';
66

77
const CLOUD_PROVIDER_SLUGS = ['aws', 'gcp', 'azure'];
88

@@ -24,16 +24,34 @@ const getRequiredVariables = (providerSlug: string): string[] => {
2424
return Array.from(requiredVars);
2525
};
2626

27-
export async function GET() {
27+
export async function GET(request: NextRequest) {
2828
try {
2929
const session = await auth.api.getSession({
3030
headers: await headers(),
3131
});
3232

33-
const orgId = session?.session.activeOrganizationId;
33+
if (!session?.user?.id) {
34+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
35+
}
36+
37+
const { searchParams } = new URL(request.url);
38+
const orgId = searchParams.get('orgId');
3439

3540
if (!orgId) {
36-
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
41+
return NextResponse.json({ error: 'Organization ID is required' }, { status: 400 });
42+
}
43+
44+
// Verify the user belongs to the requested organization
45+
const member = await db.member.findFirst({
46+
where: {
47+
userId: session.user.id,
48+
organizationId: orgId,
49+
deactivated: false,
50+
},
51+
});
52+
53+
if (!member) {
54+
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
3755
}
3856

3957
// Fetch from NEW integration platform (IntegrationConnection)

0 commit comments

Comments
 (0)