diff --git a/ui/litellm-dashboard/src/components/templates/key_info_view.test.tsx b/ui/litellm-dashboard/src/components/templates/key_info_view.test.tsx index 219c3cc515..008b4cbe6c 100644 --- a/ui/litellm-dashboard/src/components/templates/key_info_view.test.tsx +++ b/ui/litellm-dashboard/src/components/templates/key_info_view.test.tsx @@ -1,8 +1,8 @@ -import { render, waitFor, screen } from "@testing-library/react"; -import { describe, expect, it, vi, beforeEach } from "vitest"; +import useTeams from "@/app/(dashboard)/hooks/useTeams"; +import { render, screen, waitFor } from "@testing-library/react"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { KeyResponse, Team } from "../key_team_helpers/key_list"; import KeyInfoView from "./key_info_view"; -import useTeams from "@/app/(dashboard)/hooks/useTeams"; vi.mock("@/app/(dashboard)/hooks/useTeams", () => ({ default: vi.fn(), @@ -255,4 +255,32 @@ describe("KeyInfoView", () => { expect(screen.queryByText("Delete Key")).not.toBeInTheDocument(); }); }); + + it("should not allow Internal Viewer to modify key even if they own it", async () => { + vi.mocked(useTeams).mockReturnValue({ + teams: [], + setTeams: vi.fn(), + }); + + const ownerUserId = "internal-viewer-user-id"; + const keyData = { ...MOCK_KEY_DATA, user_id: ownerUserId }; + render( + {}} + keyId={"test-key-id"} + onKeyDataUpdate={() => {}} + accessToken={"test-token"} + userID={ownerUserId} + userRole={"Internal Viewer"} + premiumUser={true} + teams={[]} + />, + ); + + await waitFor(() => { + expect(screen.queryByText("Regenerate Key")).not.toBeInTheDocument(); + expect(screen.queryByText("Delete Key")).not.toBeInTheDocument(); + }); + }); }); diff --git a/ui/litellm-dashboard/src/components/templates/key_info_view.tsx b/ui/litellm-dashboard/src/components/templates/key_info_view.tsx index 8b7f9e7787..d3028802ad 100644 --- a/ui/litellm-dashboard/src/components/templates/key_info_view.tsx +++ b/ui/litellm-dashboard/src/components/templates/key_info_view.tsx @@ -302,6 +302,7 @@ export default function KeyInfoView({ }); return `${dateStr} at ${timeStr}`; }; + console.log("userRole", userRole); const canModifyKey = isProxyAdminRole(userRole || "") || @@ -310,7 +311,7 @@ export default function KeyInfoView({ teamsData?.filter((team) => team.team_id === currentKeyData.team_id)[0], userID || "", )) || - userID === currentKeyData.user_id; + (userID === currentKeyData.user_id && userRole !== "Internal Viewer"); return (