fix: enterprise credential

This commit is contained in:
zxhlyh 2025-08-21 16:14:53 +08:00
parent 546921bd35
commit 3c00a0e508
5 changed files with 39 additions and 10 deletions

View File

@ -52,7 +52,9 @@ const AddCustomModel = ({
variant='ghost-accent' variant='ghost-accent'
size='small' size='small'
onClick={handleClick} onClick={handleClick}
disabled={notAllowCustomCredential} className={cn(
notAllowCustomCredential && 'cursor-not-allowed opacity-50',
)}
> >
<RiAddCircleFill className='mr-1 h-3.5 w-3.5' /> <RiAddCircleFill className='mr-1 h-3.5 w-3.5' />
{t('common.modelProvider.addModel')} {t('common.modelProvider.addModel')}
@ -78,6 +80,7 @@ const AddCustomModel = ({
size='small' size='small'
className={cn( className={cn(
open && 'bg-components-button-ghost-bg-hover', open && 'bg-components-button-ghost-bg-hover',
notAllowCustomCredential && 'cursor-not-allowed opacity-50',
)} )}
> >
<RiAddCircleFill className='mr-1 h-3.5 w-3.5' /> <RiAddCircleFill className='mr-1 h-3.5 w-3.5' />
@ -85,7 +88,7 @@ const AddCustomModel = ({
</Button> </Button>
) )
return Item return Item
}, [t]) }, [t, notAllowCustomCredential])
if (noModels) if (noModels)
return ButtonComponent return ButtonComponent

View File

@ -114,9 +114,8 @@ const Authorized = ({
const Trigger = useMemo(() => { const Trigger = useMemo(() => {
const Item = ( const Item = (
<Button <Button
className='grow' className={cn('grow', notAllowCustomCredential && 'cursor-not-allowed')}
size='small' size='small'
disabled={notAllowCustomCredential}
> >
<RiEqualizer2Line className='mr-1 h-3.5 w-3.5' /> <RiEqualizer2Line className='mr-1 h-3.5 w-3.5' />
{t('common.operation.config')} {t('common.operation.config')}

View File

@ -18,6 +18,7 @@ import { ConfigurationMethodEnum } from '@/app/components/header/account-setting
import Authorized from './authorized' import Authorized from './authorized'
import { useAuth, useCredentialStatus } from './hooks' import { useAuth, useCredentialStatus } from './hooks'
import Tooltip from '@/app/components/base/tooltip' import Tooltip from '@/app/components/base/tooltip'
import cn from '@/utils/classnames'
type ConfigProviderProps = { type ConfigProviderProps = {
provider: ModelProvider, provider: ModelProvider,
@ -48,11 +49,10 @@ const ConfigProvider = ({
const ButtonComponent = useMemo(() => { const ButtonComponent = useMemo(() => {
const Item = ( const Item = (
<Button <Button
className='grow' className={cn('grow', notAllowCustomCredential && 'cursor-not-allowed opacity-50')}
size='small' size='small'
onClick={handleClick} onClick={handleClick}
variant={!authorized ? 'secondary-accent' : 'secondary'} variant={!authorized ? 'secondary-accent' : 'secondary'}
disabled={notAllowCustomCredential}
> >
<RiEqualizer2Line className='mr-1 h-3.5 w-3.5' /> <RiEqualizer2Line className='mr-1 h-3.5 w-3.5' />
{t('common.operation.setup')} {t('common.operation.setup')}

View File

@ -15,6 +15,7 @@ import type {
} from '../declarations' } from '../declarations'
import { ConfigurationMethodEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { ConfigurationMethodEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import Tooltip from '@/app/components/base/tooltip'
type SwitchCredentialInLoadBalancingProps = { type SwitchCredentialInLoadBalancingProps = {
provider: ModelProvider provider: ModelProvider
@ -39,17 +40,24 @@ const SwitchCredentialInLoadBalancing = ({
const renderTrigger = useCallback(() => { const renderTrigger = useCallback(() => {
const selectedCredentialId = customModelCredential?.credential_id const selectedCredentialId = customModelCredential?.credential_id
const authRemoved = !selectedCredentialId && !!credentials?.length const authRemoved = !selectedCredentialId && !!credentials?.length
return ( let color = 'green'
if (customModelCredential?.not_allowed_to_use)
color = 'gray'
if (authRemoved)
color = 'red'
const Item = (
<Button <Button
variant='secondary' variant='secondary'
className={cn( className={cn(
'shrink-0 space-x-1', 'shrink-0 space-x-1',
authRemoved && 'text-components-button-destructive-secondary-text', authRemoved && 'text-components-button-destructive-secondary-text',
customModelCredential?.not_allowed_to_use && 'cursor-not-allowed opacity-50',
)} )}
> >
<Indicator <Indicator
className='mr-2' className='mr-2'
color={authRemoved ? 'red' : 'green'} color={color as any}
/> />
{ {
authRemoved ? t('common.modelProvider.auth.authRemoved') : customModelCredential?.credential_name authRemoved ? t('common.modelProvider.auth.authRemoved') : customModelCredential?.credential_name
@ -57,6 +65,17 @@ const SwitchCredentialInLoadBalancing = ({
<RiArrowDownSLine className='h-4 w-4' /> <RiArrowDownSLine className='h-4 w-4' />
</Button> </Button>
) )
if (customModelCredential?.not_allowed_to_use) {
return (
<Tooltip
asChild
popupContent={t('plugin.auth.credentialUnavailable')}
>
{Item}
</Tooltip>
)
}
return Item
}, [customModelCredential, t, credentials]) }, [customModelCredential, t, credentials])
return ( return (

View File

@ -29,6 +29,7 @@ import { useProviderContextSelector } from '@/context/provider-context'
import { IS_CE_EDITION } from '@/config' import { IS_CE_EDITION } from '@/config'
import { AddCredentialInLoadBalancing } from '@/app/components/header/account-setting/model-provider-page/model-auth' import { AddCredentialInLoadBalancing } from '@/app/components/header/account-setting/model-provider-page/model-auth'
import { useModelModalHandler } from '@/app/components/header/account-setting/model-provider-page/hooks' import { useModelModalHandler } from '@/app/components/header/account-setting/model-provider-page/hooks'
import Badge from '@/app/components/base/badge/index'
export type ModelLoadBalancingConfigsProps = { export type ModelLoadBalancingConfigsProps = {
draftConfig?: ModelLoadBalancingConfig draftConfig?: ModelLoadBalancingConfig
@ -173,6 +174,7 @@ const ModelLoadBalancingConfigs = ({
<div className='flex flex-col gap-1 px-3 pb-3'> <div className='flex flex-col gap-1 px-3 pb-3'>
{validDraftConfigList.map((config, index) => { {validDraftConfigList.map((config, index) => {
const isProviderManaged = config.name === '__inherit__' const isProviderManaged = config.name === '__inherit__'
const credential = modelCredential.available_credentials.find(c => c.credential_id === config.credential_id)
return ( return (
<div key={config.id || index} className='group flex h-10 items-center rounded-lg border border-components-panel-border bg-components-panel-on-panel-item-bg px-3 shadow-xs'> <div key={config.id || index} className='group flex h-10 items-center rounded-lg border border-components-panel-border bg-components-panel-on-panel-item-bg px-3 shadow-xs'>
<div className='flex grow items-center'> <div className='flex grow items-center'>
@ -191,15 +193,20 @@ const ModelLoadBalancingConfigs = ({
{isProviderManaged ? t('common.modelProvider.defaultConfig') : config.name} {isProviderManaged ? t('common.modelProvider.defaultConfig') : config.name}
</div> </div>
{isProviderManaged && ( {isProviderManaged && (
<span className='rounded-[5px] border border-divider-regular px-1 text-2xs uppercase text-text-tertiary'>{t('common.modelProvider.providerManaged')}</span> <Badge className='ml-2'>{t('common.modelProvider.providerManaged')}</Badge>
)} )}
{
credential?.from_enterprise && (
<Badge className='ml-2'>Enterprise</Badge>
)
}
</div> </div>
<div className='flex items-center gap-1'> <div className='flex items-center gap-1'>
{!isProviderManaged && ( {!isProviderManaged && (
<> <>
<div className='flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100'> <div className='flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100'>
{ {
config.credential_id && ( config.credential_id && !credential?.not_allowed_to_use && (
<span <span
className='flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg bg-components-button-secondary-bg text-text-tertiary transition-colors hover:bg-components-button-secondary-bg-hover' className='flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg bg-components-button-secondary-bg text-text-tertiary transition-colors hover:bg-components-button-secondary-bg-hover'
onClick={() => { onClick={() => {
@ -238,6 +245,7 @@ const ModelLoadBalancingConfigs = ({
size='md' size='md'
className='justify-self-end' className='justify-self-end'
onChange={value => toggleConfigEntryEnabled(index, value)} onChange={value => toggleConfigEntryEnabled(index, value)}
disabled={credential?.not_allowed_to_use}
/> />
</> </>
) )