diff --git a/config/routes.ts b/config/routes.ts index a62e8b42..76b41960 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -267,7 +267,6 @@ export default [ name: 'accessControl', path: '/access-control', key: 'accessControl', - access: 'canSeeAdmin', routes: [ { path: '/access-control', @@ -280,20 +279,20 @@ export default [ icon: 'icon-users', selectedIcon: 'icon-users-filled', defaultIcon: 'icon-users', + access: 'canSeeAdmin', component: './users' + }, + { + name: 'apikeys', + path: '/access-control/api-keys', + key: 'apikeys', + selectedIcon: 'icon-key-filled', + icon: 'icon-key', + defaultIcon: 'icon-key', + component: './api-keys' } ] }, - { - name: 'apikeys', - path: '/api-keys', - key: 'apikeys', - hideInMenu: true, - selectedIcon: 'icon-key-filled', - icon: 'icon-key', - defaultIcon: 'icon-key', - component: './api-keys' - }, { name: 'profile', path: '/profile', diff --git a/src/components/page-tools/index.tsx b/src/components/page-tools/index.tsx index eb5a2e4e..d3cd338f 100644 --- a/src/components/page-tools/index.tsx +++ b/src/components/page-tools/index.tsx @@ -129,6 +129,9 @@ interface FilterBarProps { onClick: () => void; onClear: () => void; }; + select?: { + showSearch?: boolean; + }; widths?: { input?: number; select?: number; @@ -148,6 +151,7 @@ export const FilterBar: React.FC = (props) => { showSelect, buttonText, buttonIcon, + select, actionType = 'button', marginBottom = 10, marginTop = 10, @@ -189,7 +193,7 @@ export const FilterBar: React.FC = (props) => { {showSelect && ( { const userMenu = { items: [ - { - key: 'apikeys', - label: ( - - - - {intl?.formatMessage?.({ id: 'menu.apikeys' })} - - - ), - onClick: () => { - history.push('/api-keys'); - } - }, { key: 'settings', label: ( diff --git a/src/pages/api-keys/hooks/use-keys-columns.tsx b/src/pages/api-keys/hooks/use-keys-columns.tsx index 84e436e2..a11dca29 100644 --- a/src/pages/api-keys/hooks/use-keys-columns.tsx +++ b/src/pages/api-keys/hooks/use-keys-columns.tsx @@ -13,6 +13,7 @@ import { ListItem } from '../config/types'; interface ColumnsHookProps { handleSelect: (val: string, record: ListItem) => void; sortOrder: string[]; + is_admin?: boolean; } const actionList: Global.ActionItem[] = [ @@ -31,7 +32,8 @@ const actionList: Global.ActionItem[] = [ const useModelsColumns = ({ handleSelect, - sortOrder + sortOrder, + is_admin }: ColumnsHookProps): ColumnsType => { const intl = useIntl(); @@ -69,7 +71,18 @@ const useModelsColumns = ({ dataIndex: 'masked_value', key: 'masked_value', render: (text: string, record: ListItem) => ( - + + {text || '-'} + + ) + }, + { + title: intl.formatMessage({ id: 'users.table.username' }), + dataIndex: 'user_name', + key: 'user_name', + hidden: !is_admin, + render: (text: string, record: ListItem) => ( + {text || '-'} ) @@ -166,7 +179,7 @@ const useModelsColumns = ({ ) } ]; - }, [intl, handleSelect]); + }, [intl, is_admin, handleSelect]); }; export default useModelsColumns; diff --git a/src/pages/api-keys/index.tsx b/src/pages/api-keys/index.tsx index 12c66e1c..25078e55 100644 --- a/src/pages/api-keys/index.tsx +++ b/src/pages/api-keys/index.tsx @@ -5,11 +5,13 @@ import { PageAction } from '@/config'; import { PaginationKey } from '@/config/settings'; import type { PageActionType } from '@/config/types'; import useTableFetch from '@/hooks/use-table-fetch'; +import useQueryUserList from '@/pages/users/services/use-query-user-list'; +import { useModel } from '@@/plugin-model'; import { useIntl } from '@umijs/max'; import useMemoizedFn from 'ahooks/lib/useMemoizedFn'; import { ConfigProvider, Table } from 'antd'; import _ from 'lodash'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import NoResult from '../_components/no-result'; import PageBox from '../_components/page-box'; import { deleteApisKey, queryApisKeysList } from './apis'; @@ -18,6 +20,8 @@ import { ListItem } from './config/types'; import useKeysColumns from './hooks/use-keys-columns'; const APIKeys: React.FC = () => { + const { initialState } = useModel('@@initialState'); + const currentUser = initialState?.currentUser; const { TABLE_SORT_DIRECTIONS, dataSource, @@ -30,13 +34,25 @@ const APIKeys: React.FC = () => { fetchData, handlePageChange, handleTableChange, + handleQueryChange, handleSearch, handleNameChange } = useTableFetch({ key: PaginationKey.APIKeys, fetchAPI: queryApisKeysList, deleteAPI: deleteApisKey, - contentForDelete: 'apikeys.table.apikeys' + contentForDelete: 'apikeys.table.apikeys', + defaultQueryParams: { + user_id: currentUser?.is_admin ? '*' : undefined + } + }); + const { + dataList: userList, + fetchData: fetchUserData, + cancelRequest: cancelUserRequest + } = useQueryUserList({ + getLabel: (item) => item.username, + getValue: (item) => item.id }); const intl = useIntl(); @@ -52,6 +68,15 @@ const APIKeys: React.FC = () => { currentData: null }); + useEffect(() => { + fetchUserData({ + page: -1 + }); + return () => { + cancelUserRequest(); + }; + }, []); + const handleAddKey = () => { setOpenAddModal({ open: true, @@ -101,6 +126,12 @@ const APIKeys: React.FC = () => { } }); + const handleUserChange = (val: string) => { + handleQueryChange({ + user_id: val || '*' + }); + }; + const renderEmpty = (type?: string) => { if (type !== 'Table') return; return ( @@ -121,7 +152,11 @@ const APIKeys: React.FC = () => { ); }; - const columns = useKeysColumns({ handleSelect: onSelect, sortOrder }); + const columns = useKeysColumns({ + handleSelect: onSelect, + sortOrder, + is_admin: currentUser?.is_admin + }); return ( <> @@ -129,10 +164,15 @@ const APIKeys: React.FC = () => { { rowSelection={rowSelection} loading={{ spinning: dataSource.loading, - size: 'middle' + size: 'default' }} sortDirections={TABLE_SORT_DIRECTIONS} showSorterTooltip={false} rowKey="id" onChange={handleTableChange} pagination={{ - size: 'middle', + size: 'default', showSizeChanger: true, pageSize: queryParams.perPage, current: queryParams.page, diff --git a/src/pages/llmodels/components/api-access-info.tsx b/src/pages/llmodels/components/api-access-info.tsx index c48a12b4..142905b8 100644 --- a/src/pages/llmodels/components/api-access-info.tsx +++ b/src/pages/llmodels/components/api-access-info.tsx @@ -198,7 +198,7 @@ const ApiAccessInfo = ({ open, data, onClose }: ApiAccessInfoProps) => { navigate('/api-keys')} + onClick={() => navigate('/access-control/api-keys')} > {intl.formatMessage({ id: 'models.table.apiAccessInfo.gotoCreate' diff --git a/src/pages/playground/components/view-common-code.tsx b/src/pages/playground/components/view-common-code.tsx index d327a39a..a70ef318 100644 --- a/src/pages/playground/components/view-common-code.tsx +++ b/src/pages/playground/components/view-common-code.tsx @@ -94,7 +94,7 @@ const ViewCodeModal: React.FC = (props) => {