Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -912,9 +912,9 @@ def _construct_invitation_link(self, invitation_id: str, base_url: str) -> str:
"""
Construct invitation link for the user

# http://localhost:4000/ui?invitation_id=7a096b3a-37c6-440f-9dd1-ba22e8043f6b
# http://localhost:4000/ui/onboarding?invitation_id=7a096b3a-37c6-440f-9dd1-ba22e8043f6b
"""
return f"{base_url}/ui?invitation_id={invitation_id}"
return f"{base_url}/ui/onboarding?invitation_id={invitation_id}"

async def send_email(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ async def mock_find_many(*args, **kwargs):
result = await base_email_logger._get_invitation_link(
user_id="test-user", base_url="http://test.com"
)
assert result == "http://test.com/ui?invitation_id=test-invitation-id"
assert (
result == "http://test.com/ui/onboarding?invitation_id=test-invitation-id"
)

# Test with None user_id
result = await base_email_logger._get_invitation_link(
Expand All @@ -370,7 +372,7 @@ def test_construct_invitation_link(base_email_logger):
result = base_email_logger._construct_invitation_link(
invitation_id="test-id-123", base_url="http://test.com"
)
assert result == "http://test.com/ui?invitation_id=test-id-123"
assert result == "http://test.com/ui/onboarding?invitation_id=test-id-123"


@pytest.mark.asyncio
Expand Down Expand Up @@ -406,7 +408,10 @@ async def mock_find_many_empty(*args, **kwargs):
assert call_args["user_api_key_dict"].user_id == "test-user"

# Verify the returned link uses the new invitation ID
assert result == "http://test.com/ui?invitation_id=new-invitation-id"
assert (
result
== "http://test.com/ui/onboarding?invitation_id=new-invitation-id"
)


@pytest.mark.asyncio
Expand Down Expand Up @@ -437,7 +442,10 @@ async def mock_find_many_existing(*args, **kwargs):
mock_create_invitation.assert_not_called()

# Verify the returned link uses the existing invitation ID
assert result == "http://test.com/ui?invitation_id=existing-invitation-id"
assert (
result
== "http://test.com/ui/onboarding?invitation_id=existing-invitation-id"
)


@pytest.mark.asyncio
Expand Down Expand Up @@ -473,7 +481,10 @@ async def mock_find_many_none(*args, **kwargs):
assert call_args["user_api_key_dict"].user_id == "test-user"

# Verify the returned link uses the new invitation ID
assert result == "http://test.com/ui?invitation_id=new-invitation-from-none"
assert (
result
== "http://test.com/ui/onboarding?invitation_id=new-invitation-from-none"
)


@pytest.mark.asyncio
Expand All @@ -493,7 +504,7 @@ async def test_get_email_params_user_invitation(
with mock.patch.object(
base_email_logger,
"_get_invitation_link",
return_value="http://test.com/ui?invitation_id=test-id",
return_value="http://test.com/ui/onboarding?invitation_id=test-id",
):
# Test with user invitation event
result = await base_email_logger._get_email_params(
Expand All @@ -507,7 +518,9 @@ async def test_get_email_params_user_invitation(
== "https://litellm-listing.s3.amazonaws.com/litellm_logo.png"
)
assert result.support_contact == "support@berri.ai"
assert result.base_url == "http://test.com/ui?invitation_id=test-id"
assert (
result.base_url == "http://test.com/ui/onboarding?invitation_id=test-id"
)
assert result.recipient_email == "test@example.com"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

interface BulkCreateUsersProps {
accessToken: string;
teams: any[] | null;

Check warning on line 20 in ui/litellm-dashboard/src/components/bulk_create_users_button.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
possibleUIRoles: null | Record<string, Record<string, string>>;
onUsersCreated?: () => void;
}
Expand Down Expand Up @@ -51,7 +51,7 @@
teams,
possibleUIRoles,
onUsersCreated,
}) => {

Check warning on line 54 in ui/litellm-dashboard/src/components/bulk_create_users_button.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Arrow function has a complexity of 23. Maximum allowed is 20
const [isModalVisible, setIsModalVisible] = useState(false);
const [parsedData, setParsedData] = useState<UserData[]>([]);
const [isProcessing, setIsProcessing] = useState(false);
Expand Down Expand Up @@ -166,7 +166,7 @@
try {
const userData = results.data
.slice(1)
.map((row: any, index: number) => {

Check warning on line 169 in ui/litellm-dashboard/src/components/bulk_create_users_button.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Arrow function has a complexity of 30. Maximum allowed is 20

Check warning on line 169 in ui/litellm-dashboard/src/components/bulk_create_users_button.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
// Skip empty rows
if (row.length === 0 || (row.length === 1 && row[0] === "")) {
return null;
Expand Down Expand Up @@ -291,7 +291,7 @@
setFileError(null);
};

const handleBulkCreate = async () => {

Check warning on line 294 in ui/litellm-dashboard/src/components/bulk_create_users_button.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Async arrow function has a complexity of 38. Maximum allowed is 20
setIsProcessing(true);
const updatedData = parsedData.map((user) => ({ ...user, status: "pending" }));
setParsedData(updatedData);
Expand Down Expand Up @@ -361,10 +361,10 @@

// Create invitation link for the user
try {
if (!uiSettings?.SSO_ENABLED) {

Check warning on line 364 in ui/litellm-dashboard/src/components/bulk_create_users_button.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Blocks are nested too deeply (5). Maximum allowed is 4
// Regular invitation flow
const invitationData = await invitationCreateCall(accessToken, user_id);
const invitationUrl = new URL(`/ui?invitation_id=${invitationData.id}`, baseUrl).toString();
const invitationUrl = new URL(`/ui/onboarding?invitation_id=${invitationData.id}`, baseUrl).toString();

setParsedData((current) =>
current.map((u, i) =>
Expand Down Expand Up @@ -420,7 +420,7 @@
}
} catch (error) {
console.error("Caught error:", error);
const errorMessage = (error as any)?.response?.data?.error || (error as Error)?.message || String(error);

Check warning on line 423 in ui/litellm-dashboard/src/components/bulk_create_users_button.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
setParsedData((current) =>
current.map((u, i) => (i === index ? { ...u, status: "failed", error: errorMessage } : u)),
);
Expand Down Expand Up @@ -487,7 +487,7 @@
{
title: "Status",
key: "status",
render: (_: any, record: UserData) => {

Check warning on line 490 in ui/litellm-dashboard/src/components/bulk_create_users_button.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
if (!record.isValid) {
return (
<div>
Expand Down
59 changes: 59 additions & 0 deletions ui/litellm-dashboard/src/components/onboarding_link.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { describe, it, expect } from "vitest";
import { buildOnboardingUrl } from "./onboarding_link";

describe("buildOnboardingUrl", () => {
it("points the invitation link at the dedicated /ui/onboarding route", () => {
expect(
buildOnboardingUrl({
baseUrl: "http://localhost:4000/",
invitationId: "inv-123",
hasUserSetupSso: false,
resetPassword: false,
}),
).toBe("http://localhost:4000/ui/onboarding?invitation_id=inv-123");
});

it("preserves a server_root_path prefix before /ui/onboarding", () => {
expect(
buildOnboardingUrl({
baseUrl: "https://proxy.example.com/litellm",
invitationId: "inv-123",
hasUserSetupSso: false,
resetPassword: false,
}),
).toBe("https://proxy.example.com/litellm/ui/onboarding?invitation_id=inv-123");
});

it("appends action=reset_password for the reset-password flow", () => {
expect(
buildOnboardingUrl({
baseUrl: "http://localhost:4000/",
invitationId: "inv-123",
hasUserSetupSso: false,
resetPassword: true,
}),
).toBe("http://localhost:4000/ui/onboarding?invitation_id=inv-123&action=reset_password");
});

it("sends SSO users to the dashboard root, not the onboarding form", () => {
expect(
buildOnboardingUrl({
baseUrl: "http://localhost:4000/",
invitationId: "inv-123",
hasUserSetupSso: true,
resetPassword: false,
}),
).toBe("http://localhost:4000/ui");
});

it("returns an empty string when no base URL is known yet", () => {
expect(
buildOnboardingUrl({
baseUrl: "",
invitationId: "inv-123",
hasUserSetupSso: false,
resetPassword: false,
}),
).toBe("");
});
});
48 changes: 30 additions & 18 deletions ui/litellm-dashboard/src/components/onboarding_link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ interface OnboardingProps {
modalType?: "invitation" | "resetPassword";
}

export function buildOnboardingUrl({
baseUrl,
invitationId,
hasUserSetupSso,
resetPassword,
}: {
baseUrl: string;
invitationId: string | undefined;
hasUserSetupSso: boolean;
resetPassword: boolean;
}): string {
if (!baseUrl) {
return "";
}
const basePath = new URL(baseUrl).pathname;
const uiPath = basePath && basePath !== "/" ? `${basePath}/ui` : "ui";
if (hasUserSetupSso) {
return new URL(uiPath, baseUrl).toString();
}
const action = resetPassword ? "&action=reset_password" : "";
return new URL(`${uiPath}/onboarding?invitation_id=${invitationId}${action}`, baseUrl).toString();
Comment thread
ryan-crabbe-berri marked this conversation as resolved.
Resolved
}

export default function OnboardingModal({
isInvitationLinkModalVisible,
setIsInvitationLinkModalVisible,
Expand All @@ -41,24 +64,13 @@ export default function OnboardingModal({
setIsInvitationLinkModalVisible(false);
};

const getInvitationUrl = () => {
if (!baseUrl) {
return "";
}
const baseUrlObj = new URL(baseUrl);
const basePath = baseUrlObj.pathname; // This will be "/litellm" or ""
const path = basePath && basePath !== "/" ? `${basePath}/ui` : "ui";
// Get the path from the base URL
if (invitationLinkData?.has_user_setup_sso) {
return new URL(path, baseUrl).toString();
}
let urlPath = `${path}?invitation_id=${invitationLinkData?.id}`;
if (modalType === "resetPassword") {
urlPath += "&action=reset_password";
}
const url = new URL(urlPath, baseUrl).toString();
return url;
};
const getInvitationUrl = () =>
buildOnboardingUrl({
baseUrl,
invitationId: invitationLinkData?.id,
hasUserSetupSso: invitationLinkData?.has_user_setup_sso ?? false,
resetPassword: modalType === "resetPassword",
});

return (
<Modal
Expand Down
Loading