mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-21 00:21:49 +00:00
isPageAccessibleToInternalUsers
This commit is contained in:
parent
8995904c91
commit
dd3fb8cd99
2 changed files with 43 additions and 9 deletions
|
|
@ -78,6 +78,10 @@ export default function PageVisibilitySettings({
|
|||
<Typography.Text type="secondary" style={{ fontSize: "12px", fontStyle: "italic" }}>
|
||||
By default, all pages are visible to internal users. Select specific pages to restrict visibility.
|
||||
</Typography.Text>
|
||||
<Typography.Text type="secondary" style={{ fontSize: "12px", color: "#8b5cf6" }}>
|
||||
Note: Only pages accessible to internal user roles are shown here. Admin-only pages are excluded as they
|
||||
cannot be made visible to internal users regardless of this setting.
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
|
||||
<Collapse
|
||||
|
|
|
|||
|
|
@ -4,10 +4,30 @@
|
|||
|
||||
import { menuGroups } from "./leftnav";
|
||||
import { pageDescriptions, PageMetadata } from "./page_metadata";
|
||||
import { internalUserRoles } from "@/utils/roles";
|
||||
|
||||
/**
|
||||
* Check if a page is accessible to internal users
|
||||
* A page is accessible if:
|
||||
* 1. It has no role restrictions, OR
|
||||
* 2. Its roles include at least one internal user role
|
||||
*/
|
||||
const isPageAccessibleToInternalUsers = (pageRoles?: string[]): boolean => {
|
||||
if (!pageRoles || pageRoles.length === 0) {
|
||||
return true; // No role restrictions
|
||||
}
|
||||
|
||||
// Check if any of the page's roles match internal user roles
|
||||
return pageRoles.some(role => internalUserRoles.includes(role));
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all available pages from the navigation menu configuration
|
||||
* Used by UI Settings to display available pages for visibility control
|
||||
*
|
||||
* IMPORTANT: Only returns pages that internal users can access.
|
||||
* Pages restricted to admin-only roles are excluded because internal users
|
||||
* cannot see them regardless of the UI visibility setting.
|
||||
*/
|
||||
export const getAvailablePages = (): PageMetadata[] => {
|
||||
const pages: PageMetadata[] = [];
|
||||
|
|
@ -15,7 +35,14 @@ export const getAvailablePages = (): PageMetadata[] => {
|
|||
menuGroups.forEach((group) => {
|
||||
group.items.forEach((item) => {
|
||||
// Add top-level items (skip parent containers like 'tools', 'experimental', 'settings')
|
||||
if (item.page && item.page !== "tools" && item.page !== "experimental" && item.page !== "settings") {
|
||||
// Also skip items that internal users cannot access
|
||||
if (
|
||||
item.page &&
|
||||
item.page !== "tools" &&
|
||||
item.page !== "experimental" &&
|
||||
item.page !== "settings" &&
|
||||
isPageAccessibleToInternalUsers(item.roles)
|
||||
) {
|
||||
const label = typeof item.label === "string" ? item.label : item.key;
|
||||
pages.push({
|
||||
page: item.page,
|
||||
|
|
@ -25,17 +52,20 @@ export const getAvailablePages = (): PageMetadata[] => {
|
|||
});
|
||||
}
|
||||
|
||||
// Add children items
|
||||
// Add children items (also skip those internal users cannot access)
|
||||
if (item.children) {
|
||||
const parentLabel = typeof item.label === "string" ? item.label : item.key;
|
||||
item.children.forEach((child) => {
|
||||
const childLabel = typeof child.label === "string" ? child.label : child.key;
|
||||
pages.push({
|
||||
page: child.page,
|
||||
label: childLabel,
|
||||
group: `${group.groupLabel} > ${parentLabel}`,
|
||||
description: pageDescriptions[child.page] || "No description available",
|
||||
});
|
||||
// Include if internal users can access
|
||||
if (isPageAccessibleToInternalUsers(child.roles)) {
|
||||
const childLabel = typeof child.label === "string" ? child.label : child.key;
|
||||
pages.push({
|
||||
page: child.page,
|
||||
label: childLabel,
|
||||
group: `${group.groupLabel} > ${parentLabel}`,
|
||||
description: pageDescriptions[child.page] || "No description available",
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue