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
+8 -4
View File
@@ -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<DailyUsageProps> = (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<DailyUsageProps> = (props) => {
value: item.value
}))
.filter((option) => {
if (currentUser?.is_admin) {
if (canGroupByUser) {
return true;
}
return option.value !== 'user';