feat(usage): treat org owners as managers on the Usage page

The Usage page gated cross-user features (default ``scope=all``,
the user filter, the per-user breakdown dimension) on
``currentUser.is_admin`` alone. The backend's
``_can_use_all_scope`` already grants the same surface to Org
owners — the page just never asked. Result: a non-admin Org owner
landed on ``scope=self`` with no user filter and no per-user
group-by, even though the API would have happily served them the
org-wide picture.

Switch the three sites to ``useAccess().canSeeOrgAdmin``, which
already encodes "platform admin OR owner of the selected
(non-Personal) Org". One predicate, no new helper.

Sites:
- ``index.tsx``: ``initialScope`` defaults to ``all`` for managers.
- ``filter-bar.tsx``: the user filter + nested API-key cascader
  surface (vs the flat API-key picker for members).
- ``daily-usage.tsx``: the ``user`` group-by option in the chart.
This commit is contained in:
gitlawr
2026-05-25 13:56:25 +08:00
committed by jialin
parent 9c519d937d
commit 6af18275c4
3 changed files with 23 additions and 15 deletions
+6 -5
View File
@@ -1,8 +1,7 @@
import { baseColorMap } from '@/pages/dashboard/config';
import { formatLargeNumber } from '@/utils';
import { useModel } from '@@/plugin-model';
import { SimpleCard } from '@gpustack/core-ui';
import { useIntl } from '@umijs/max';
import { useAccess, useIntl } from '@umijs/max';
import React, { useEffect, useMemo, useState } from 'react';
import BreakdownTabs from './components/breakdown-tabs';
import DailyUsage from './components/daily-usage';
@@ -16,8 +15,7 @@ type DateType = 'date' | 'week' | 'month' | 'quarter' | 'year';
const Usage: React.FC = () => {
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