Respect key tab permissions in saved URLs

This commit is contained in:
moe-berri 2026-11-06 16:38:59 +08:00
parent f1bddaf805
commit da3676918b
2 changed files with 20 additions and 1 deletions

View file

@ -281,6 +281,25 @@ describe("KeyInfoView", () => {
expect(screen.queryByRole("tab", { name: "Auto-router usage" })).not.toBeInTheDocument();
});
it.each(["detail_tab", "key_detail_tab"])("rejects the hidden auto-router tab from %s", async (tabQueryKey) => {
vi.mocked(useAuthorized).mockReturnValue({ ...baseUseAuthorizedMock, userRole: "Internal User" });
const onUrlUpdate = vi.fn();
renderWithProviders(
<KeyInfoView
keyData={MOCK_KEY_DATA}
onClose={() => {}}
keyId="test-key-id"
teams={[]}
tabQueryKey={tabQueryKey}
/>,
{ searchParams: `${tabQueryKey}=auto-router-usage`, onUrlUpdate, resetUrlUpdateQueueOnMount: false },
);
expect(screen.getByRole("tab", { name: "Overview" })).toHaveAttribute("aria-selected", "true");
expect(screen.queryByTestId("key-auto-router-usage")).not.toBeInTheDocument();
await waitFor(() => expect(onUrlUpdate.mock.lastCall?.[0].searchParams.has(tabQueryKey)).toBe(false));
});
it("keeps the team tab when changing a nested key tab", async () => {
vi.mocked(useAuthorized).mockReturnValue(baseUseAuthorizedMock);
const onUrlUpdate = vi.fn();

View file

@ -113,7 +113,7 @@ export default function KeyInfoView({
const { t } = useTranslation();
const { accessToken, userId: userID, userRole, premiumUser } = useAuthorized();
const [activeTab, setActiveTab] = useUrlTab(
["overview", "activity", "savings", "auto-router-usage", "settings"],
["overview", "activity", "savings", ...(hasProxyWideSpendView(userRole) ? ["auto-router-usage"] : []), "settings"],
"overview",
tabQueryKey,
);