( request: NextRequest )
| 20 | * organization path also answers `false` for an unexpected failure, such as a |
| 21 | * malformed id. |
| 22 | */ |
| 23 | function refusalResponse(error: unknown, organizationPath: boolean): EnabledRouteResponse { |
| 24 | if (error instanceof TRPCError && error.cause instanceof StaffRequestRefusal) { |
| 25 | return error.cause.response; |
| 26 | } |
| 27 | if (error instanceof TRPCError || organizationPath) return NextResponse.json({ enabled: false }); |
| 28 | throw error; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * GET /api/code-indexing/enabled?organizationId=<uuid> |
| 33 | * |
| 34 | * Returns { enabled: true } if: |
| 35 | * - organizationId is provided in query params |
| 36 | * - User is a member of the organization, or staff the staff guard admits |
| 37 | * for a read of it |
| 38 | * - Organization has code_indexing_enabled set to true in settings |
| 39 | * |
| 40 | * Without organizationId, returns whether the personal index is enabled: the |
| 41 | * configured list enables it, and a platform admin needs the staff guard. |
| 42 | * Both paths reuse this request's one authentication result. |
| 43 | * |
| 44 | * Returns { enabled: false } otherwise |
| 45 | */ |
| 46 | export async function GET(request: NextRequest): Promise<EnabledRouteResponse> { |
| 47 | const auth = await getUserFromAuth({ adminOnly: false }); |
| 48 | if (auth.authFailedResponse) { |
| 49 | return auth.authFailedResponse; |
| 50 | } |
| 51 | |
| 52 | if (!isCodeIndexingEnabled()) { |
| 53 | return NextResponse.json({ enabled: false }); |
| 54 | } |
| 55 | |
| 56 | const ctx = organizationRestAccessContext(auth, { |
nothing calls this directly
no test coverage detected