mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix(ui): skip organization fetches when the session is not premium
This commit is contained in:
parent
81f1778f53
commit
cc401c4041
2 changed files with 51 additions and 10 deletions
|
|
@ -81,7 +81,7 @@ describe("useOrganizations", () => {
|
|||
userRole: "Admin",
|
||||
token: "test-token",
|
||||
userEmail: "test@example.com",
|
||||
premiumUser: false,
|
||||
premiumUser: true,
|
||||
disabledPersonalKeyCreation: null,
|
||||
showSSOBanner: false,
|
||||
});
|
||||
|
|
@ -181,7 +181,7 @@ describe("useOrganizations", () => {
|
|||
userRole: "Admin",
|
||||
token: null,
|
||||
userEmail: "test@example.com",
|
||||
premiumUser: false,
|
||||
premiumUser: true,
|
||||
disabledPersonalKeyCreation: null,
|
||||
showSSOBanner: false,
|
||||
});
|
||||
|
|
@ -197,6 +197,26 @@ describe("useOrganizations", () => {
|
|||
expect(organizationListCall).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not call the organization API when the session is not premium", async () => {
|
||||
mockUseAuthorized.mockReturnValue({
|
||||
accessToken: "test-access-token",
|
||||
userId: "test-user-id",
|
||||
userRole: "Admin",
|
||||
token: "test-token",
|
||||
userEmail: "test@example.com",
|
||||
premiumUser: false,
|
||||
disabledPersonalKeyCreation: null,
|
||||
showSSOBanner: false,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useOrganizations(), { wrapper });
|
||||
|
||||
expect(result.current.isLoading).toBe(false);
|
||||
expect(result.current.data).toBeUndefined();
|
||||
expect(result.current.isFetched).toBe(false);
|
||||
expect(organizationListCall).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not execute query when userId is missing", async () => {
|
||||
// Mock missing userId
|
||||
mockUseAuthorized.mockReturnValue({
|
||||
|
|
@ -205,7 +225,7 @@ describe("useOrganizations", () => {
|
|||
userRole: "Admin",
|
||||
token: "test-token",
|
||||
userEmail: "test@example.com",
|
||||
premiumUser: false,
|
||||
premiumUser: true,
|
||||
disabledPersonalKeyCreation: null,
|
||||
showSSOBanner: false,
|
||||
});
|
||||
|
|
@ -229,7 +249,7 @@ describe("useOrganizations", () => {
|
|||
userRole: null,
|
||||
token: "test-token",
|
||||
userEmail: "test@example.com",
|
||||
premiumUser: false,
|
||||
premiumUser: true,
|
||||
disabledPersonalKeyCreation: null,
|
||||
showSSOBanner: false,
|
||||
});
|
||||
|
|
@ -253,7 +273,7 @@ describe("useOrganizations", () => {
|
|||
userRole: null,
|
||||
token: null,
|
||||
userEmail: "test@example.com",
|
||||
premiumUser: false,
|
||||
premiumUser: true,
|
||||
disabledPersonalKeyCreation: null,
|
||||
showSSOBanner: false,
|
||||
});
|
||||
|
|
@ -335,7 +355,7 @@ describe("useOrganization", () => {
|
|||
userRole: "Admin",
|
||||
token: "test-token",
|
||||
userEmail: "test@example.com",
|
||||
premiumUser: false,
|
||||
premiumUser: true,
|
||||
disabledPersonalKeyCreation: null,
|
||||
showSSOBanner: false,
|
||||
});
|
||||
|
|
@ -356,6 +376,26 @@ describe("useOrganization", () => {
|
|||
expect(result.current.isLoading).toBe(false);
|
||||
});
|
||||
|
||||
it("does not call the organization info API when the session is not premium", () => {
|
||||
mockUseAuthorized.mockReturnValue({
|
||||
accessToken: "test-access-token",
|
||||
userId: "test-user-id",
|
||||
userRole: "Admin",
|
||||
token: "test-token",
|
||||
userEmail: "test@example.com",
|
||||
premiumUser: false,
|
||||
disabledPersonalKeyCreation: null,
|
||||
showSSOBanner: false,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useOrganization("org-1"), { wrapper });
|
||||
|
||||
expect(result.current.isLoading).toBe(false);
|
||||
expect(result.current.data).toBeUndefined();
|
||||
expect(result.current.isFetched).toBe(false);
|
||||
expect(organizationInfoCall).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("falls through to the detail API call when no cached list contains the organization", async () => {
|
||||
(organizationInfoCall as any).mockResolvedValue(mockOrganizations[0]);
|
||||
queryClient.setQueryData(organizationKeys.list({ filters: { org_id: "org-2" } }), [mockOrganizations[1]]);
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ export interface OrganizationListFilters {
|
|||
}
|
||||
|
||||
export const useOrganizations = (filters?: OrganizationListFilters): UseQueryResult<Organization[]> => {
|
||||
const { accessToken, userId, userRole } = useAuthorized();
|
||||
const { accessToken, userId, userRole, premiumUser } = useAuthorized();
|
||||
const orgId = filters?.org_id || null;
|
||||
const orgAlias = filters?.org_alias || null;
|
||||
const hasSession = Boolean(accessToken && userId && userRole);
|
||||
return useQuery<Organization[]>({
|
||||
queryKey: organizationKeys.list(
|
||||
orgId || orgAlias
|
||||
|
|
@ -21,16 +22,16 @@ export const useOrganizations = (filters?: OrganizationListFilters): UseQueryRes
|
|||
: {},
|
||||
),
|
||||
queryFn: async () => await organizationListCall(accessToken!, orgId, orgAlias),
|
||||
enabled: Boolean(accessToken && userId && userRole),
|
||||
enabled: hasSession && premiumUser === true,
|
||||
});
|
||||
};
|
||||
|
||||
export const useOrganization = (organizationID?: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
const { accessToken } = useAuthorized();
|
||||
const { accessToken, premiumUser } = useAuthorized();
|
||||
return useQuery<Organization>({
|
||||
queryKey: organizationKeys.detail(organizationID!),
|
||||
enabled: Boolean(accessToken && organizationID),
|
||||
enabled: Boolean(accessToken && organizationID) && premiumUser === true,
|
||||
|
||||
queryFn: async () => {
|
||||
if (!accessToken || !organizationID) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue