mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-01 02:02:20 +00:00
fix(ui): show team projects to internal users
Some checks failed
Unit Tests: Proxy DB Operations / assert-shard-coverage (push) Has been cancelled
Unit Tests: Security / security (push) Has been cancelled
Unit Tests: Proxy DB Operations / auth-checks (push) Has been cancelled
Unit Tests: Proxy DB Operations / budgets (push) Has been cancelled
Unit Tests: Proxy DB Operations / custom-logging (push) Has been cancelled
Unit Tests: Proxy DB Operations / db-and-spend (push) Has been cancelled
Unit Tests: Proxy DB Operations / endpoints-and-responses (push) Has been cancelled
Unit Tests: Proxy DB Operations / guardrails-hooks (push) Has been cancelled
Unit Tests: Proxy DB Operations / jwt-and-keys (push) Has been cancelled
Unit Tests: Proxy DB Operations / key-generation (push) Has been cancelled
Unit Tests: Proxy DB Operations / logging-misc (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-runtime (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-server-core (push) Has been cancelled
Unit Tests: Proxy DB Operations / schema-migration (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-utils (push) Has been cancelled
Some checks failed
Unit Tests: Proxy DB Operations / assert-shard-coverage (push) Has been cancelled
Unit Tests: Security / security (push) Has been cancelled
Unit Tests: Proxy DB Operations / auth-checks (push) Has been cancelled
Unit Tests: Proxy DB Operations / budgets (push) Has been cancelled
Unit Tests: Proxy DB Operations / custom-logging (push) Has been cancelled
Unit Tests: Proxy DB Operations / db-and-spend (push) Has been cancelled
Unit Tests: Proxy DB Operations / endpoints-and-responses (push) Has been cancelled
Unit Tests: Proxy DB Operations / guardrails-hooks (push) Has been cancelled
Unit Tests: Proxy DB Operations / jwt-and-keys (push) Has been cancelled
Unit Tests: Proxy DB Operations / key-generation (push) Has been cancelled
Unit Tests: Proxy DB Operations / logging-misc (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-runtime (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-server-core (push) Has been cancelled
Unit Tests: Proxy DB Operations / schema-migration (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-utils (push) Has been cancelled
Allow internal users to fetch their backend-scoped project list so the key creation project dropdown can populate for selected teams. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
96a2e8b16d
commit
8cb9ceb9c0
2 changed files with 13 additions and 3 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import {
|
|||
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 ────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
|
@ -47,6 +47,8 @@ export interface ProjectResponse {
|
|||
|
||||
export const projectKeys = createQueryKeys("projects");
|
||||
|
||||
const projectReaderRoles = [...all_admin_roles, ...internalUserRoles];
|
||||
|
||||
// ── Fetch function ───────────────────────────────────────────────────────────
|
||||
|
||||
const fetchProjects = async (
|
||||
|
|
@ -81,6 +83,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!),
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue