fix(ui): show team projects to internal users (#28855)

Allow internal users to fetch their backend-scoped project list so the key creation project dropdown can populate for selected teams.
This commit is contained in:
milan-berri 2026-06-09 02:27:35 +03:00 committed by GitHub
parent dfd6cbc514
commit f59e4ebc9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

@ -115,8 +115,16 @@ describe("useProjects", () => {
expect(global.fetch).not.toHaveBeenCalled();
});
it("should not fetch when userRole is not an admin role", () => {
it("should fetch when userRole is an internal user role", async () => {
mockUseAuthorized.mockReturnValue({ accessToken: "test-token", userRole: "Internal User" });
(global.fetch as any).mockResolvedValue({ ok: true, json: async () => mockProjects });
const { result } = renderHook(() => useProjects(), { wrapper: makeWrapper(queryClient) });
await waitFor(() => expect(result.current.isSuccess).toBe(true));
expect(global.fetch).toHaveBeenCalled();
});
it("should not fetch when userRole cannot read projects", () => {
mockUseAuthorized.mockReturnValue({ accessToken: "test-token", userRole: "regular_user" });
const { result } = renderHook(() => useProjects(), { wrapper: makeWrapper(queryClient) });
expect(result.current.isFetched).toBe(false);
expect(global.fetch).not.toHaveBeenCalled();

View File

@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";
import { createQueryKeys } from "../common/queryKeysFactory";
import { getProxyBaseUrl, getGlobalLitellmHeaderName, deriveErrorMessage, handleError } from "@/components/networking";
import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";
import { all_admin_roles } from "@/utils/roles";
import { all_admin_roles, internalUserRoles } from "@/utils/roles";
// ── Types ────────────────────────────────────────────────────────────────────
@ -42,6 +42,8 @@ export interface ProjectResponse {
export const projectKeys = createQueryKeys("projects");
const projectReaderRoles = [...all_admin_roles, ...internalUserRoles];
// ── Fetch function ───────────────────────────────────────────────────────────
const fetchProjects = async (accessToken: string): Promise<ProjectResponse[]> => {
@ -74,6 +76,6 @@ export const useProjects = () => {
return useQuery<ProjectResponse[]>({
queryKey: projectKeys.list({}),
queryFn: async () => fetchProjects(accessToken!),
enabled: Boolean(accessToken) && all_admin_roles.includes(userRole!),
enabled: Boolean(accessToken) && projectReaderRoles.includes(userRole!),
});
};