diff --git a/src/pages/usage/components/daily-usage.tsx b/src/pages/usage/components/daily-usage.tsx index def1cd58..dc0e3280 100644 --- a/src/pages/usage/components/daily-usage.tsx +++ b/src/pages/usage/components/daily-usage.tsx @@ -1,7 +1,7 @@ import useCoolColors from '@/hooks/use-cool-colors'; import BarChart from '@/pages/_components/bar-chart'; import { BaseSelect, CardWrapper } from '@gpustack/core-ui'; -import { useIntl, useModel } from '@umijs/max'; +import { useAccess, useIntl } from '@umijs/max'; import { Segmented } from 'antd'; import dayjs from 'dayjs'; import React, { useMemo } from 'react'; @@ -80,8 +80,12 @@ const DailyUsage: React.FC = (props) => { onGranularityChange } = props; const generateCoolColors = useCoolColors(); - const { initialState } = useModel('@@initialState'); - const { currentUser } = initialState || {}; + // ``canSeeOrgAdmin`` widens to Org owners of the selected Org + // (Personal Org excluded). Mirrors the BE's + // ``_can_use_all_scope`` gate for the per-user breakdown + // dimension. + const access = useAccess(); + const canGroupByUser = !!access.canSeeOrgAdmin; const labelFormatter = (v: any) => { if (granularity === 'month') { @@ -253,7 +257,7 @@ const DailyUsage: React.FC = (props) => { value: item.value })) .filter((option) => { - if (currentUser?.is_admin) { + if (canGroupByUser) { return true; } return option.value !== 'user'; diff --git a/src/pages/usage/components/filter-bar.tsx b/src/pages/usage/components/filter-bar.tsx index 1d8500da..c909fef9 100644 --- a/src/pages/usage/components/filter-bar.tsx +++ b/src/pages/usage/components/filter-bar.tsx @@ -1,5 +1,4 @@ import useRangePickerPreset from '@/pages/dashboard/hooks/use-rangepicker-preset'; -import { useModel } from '@@/plugin-model'; import { DownloadOutlined, SyncOutlined } from '@ant-design/icons'; import { AutoTooltip, @@ -7,7 +6,7 @@ import { IconFont, SimpleSelect } from '@gpustack/core-ui'; -import { useIntl } from '@umijs/max'; +import { useAccess, useIntl } from '@umijs/max'; import { Button, DatePicker, Dropdown, MenuProps } from 'antd'; import dayjs from 'dayjs'; import React from 'react'; @@ -119,8 +118,12 @@ const FilterBar: React.FC = (props) => { ] }); - const initialInfo = useModel('@@initialState'); - const { initialState } = initialInfo || {}; + // ``canSeeOrgAdmin`` already encodes "platform admin OR owner of the + // selected (non-Personal) Org" via the access seam. Mirrors the + // backend's ``_can_use_all_scope`` predicate for the user-filter + // drill-down surface. + const access = useAccess(); + const canManageUsers = !!access.canSeeOrgAdmin; const exportMenuItems: MenuProps['items'] = [ { @@ -252,7 +255,7 @@ const FilterBar: React.FC = (props) => { optionLabelRender={singleOptionRender} onChange={onRoutesChange} /> - {initialState?.currentUser?.is_admin && ( + {canManageUsers && ( <> = (props) => { )} - {!initialState?.currentUser?.is_admin && ( + {!canManageUsers && ( { const intl = useIntl(); - const initialInfo = useModel('@@initialState'); - const { initialState } = initialInfo || {}; + const access = useAccess(); const { exportTable } = useExportTable(); const [openExportModal, setOpenExportModal] = useState(false); const [breakdownRefreshKey, setBreakdownRefreshKey] = useState(0); @@ -66,7 +64,10 @@ const Usage: React.FC = () => { const { filters, commonFilters, fetchData, timeSeriesData, filterBar } = useUsageFilters({ - initialScope: initialState?.currentUser?.is_admin ? 'all' : 'self', + // ``canSeeOrgAdmin`` widens to Org owners of the selected Org in + // the enterprise build (Personal Org excluded). Mirrors the BE's + // ``_can_use_all_scope`` gate one-to-one. + initialScope: access.canSeeOrgAdmin ? 'all' : 'self', metaData, chartFilters, summaryColumns