mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-16 08:45:55 +08:00
fix: privilege for editor role (#6521)
This commit is contained in:
parent
a67831773f
commit
87d583f454
@ -40,7 +40,7 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
|||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const media = useBreakpoints()
|
const media = useBreakpoints()
|
||||||
const isMobile = media === MediaType.mobile
|
const isMobile = media === MediaType.mobile
|
||||||
const { isCurrentWorkspaceManager, isCurrentWorkspaceEditor } = useAppContext()
|
const { isCurrentWorkspaceEditor } = useAppContext()
|
||||||
const { appDetail, setAppDetail, setAppSiderbarExpand } = useStore(useShallow(state => ({
|
const { appDetail, setAppDetail, setAppSiderbarExpand } = useStore(useShallow(state => ({
|
||||||
appDetail: state.appDetail,
|
appDetail: state.appDetail,
|
||||||
setAppDetail: state.setAppDetail,
|
setAppDetail: state.setAppDetail,
|
||||||
@ -53,7 +53,7 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
|||||||
selectedIcon: NavIcon
|
selectedIcon: NavIcon
|
||||||
}>>([])
|
}>>([])
|
||||||
|
|
||||||
const getNavigations = useCallback((appId: string, isCurrentWorkspaceManager: boolean, isCurrentWorkspaceEditor: boolean, mode: string) => {
|
const getNavigations = useCallback((appId: string, isCurrentWorkspaceEditor: boolean, mode: string) => {
|
||||||
const navs = [
|
const navs = [
|
||||||
...(isCurrentWorkspaceEditor
|
...(isCurrentWorkspaceEditor
|
||||||
? [{
|
? [{
|
||||||
@ -70,7 +70,7 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
|||||||
icon: RiTerminalBoxLine,
|
icon: RiTerminalBoxLine,
|
||||||
selectedIcon: RiTerminalBoxFill,
|
selectedIcon: RiTerminalBoxFill,
|
||||||
},
|
},
|
||||||
...(isCurrentWorkspaceManager
|
...(isCurrentWorkspaceEditor
|
||||||
? [{
|
? [{
|
||||||
name: mode !== 'workflow'
|
name: mode !== 'workflow'
|
||||||
? t('common.appMenus.logAndAnn')
|
? t('common.appMenus.logAndAnn')
|
||||||
@ -115,13 +115,13 @@ const AppDetailLayout: FC<IAppDetailLayoutProps> = (props) => {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setAppDetail(res)
|
setAppDetail(res)
|
||||||
setNavigation(getNavigations(appId, isCurrentWorkspaceManager, isCurrentWorkspaceEditor, res.mode))
|
setNavigation(getNavigations(appId, isCurrentWorkspaceEditor, res.mode))
|
||||||
}
|
}
|
||||||
}).catch((e: any) => {
|
}).catch((e: any) => {
|
||||||
if (e.status === 404)
|
if (e.status === 404)
|
||||||
router.replace('/apps')
|
router.replace('/apps')
|
||||||
})
|
})
|
||||||
}, [appId, isCurrentWorkspaceManager, isCurrentWorkspaceEditor])
|
}, [appId, isCurrentWorkspaceEditor])
|
||||||
|
|
||||||
useUnmount(() => {
|
useUnmount(() => {
|
||||||
setAppDetail()
|
setAppDetail()
|
||||||
|
@ -25,6 +25,7 @@ import { ChevronDownDouble } from '@/app/components/base/icons/src/vender/line/a
|
|||||||
import { fetchModelProviderModelList } from '@/service/common'
|
import { fetchModelProviderModelList } from '@/service/common'
|
||||||
import { useEventEmitterContextContext } from '@/context/event-emitter'
|
import { useEventEmitterContextContext } from '@/context/event-emitter'
|
||||||
import { IS_CE_EDITION } from '@/config'
|
import { IS_CE_EDITION } from '@/config'
|
||||||
|
import { useAppContext } from '@/context/app-context'
|
||||||
|
|
||||||
export const UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST = 'UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST'
|
export const UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST = 'UPDATE_MODEL_PROVIDER_CUSTOM_MODEL_LIST'
|
||||||
type ProviderAddedCardProps = {
|
type ProviderAddedCardProps = {
|
||||||
@ -44,6 +45,7 @@ const ProviderAddedCard: FC<ProviderAddedCardProps> = ({
|
|||||||
const configurationMethods = provider.configurate_methods.filter(method => method !== ConfigurationMethodEnum.fetchFromRemote)
|
const configurationMethods = provider.configurate_methods.filter(method => method !== ConfigurationMethodEnum.fetchFromRemote)
|
||||||
const systemConfig = provider.system_configuration
|
const systemConfig = provider.system_configuration
|
||||||
const hasModelList = fetched && !!modelList.length
|
const hasModelList = fetched && !!modelList.length
|
||||||
|
const { isCurrentWorkspaceManager } = useAppContext()
|
||||||
const showQuota = systemConfig.enabled && [...MODEL_PROVIDER_QUOTA_GET_PAID].includes(provider.provider) && !IS_CE_EDITION
|
const showQuota = systemConfig.enabled && [...MODEL_PROVIDER_QUOTA_GET_PAID].includes(provider.provider) && !IS_CE_EDITION
|
||||||
|
|
||||||
const getModelList = async (providerName: string) => {
|
const getModelList = async (providerName: string) => {
|
||||||
@ -103,7 +105,7 @@ const ProviderAddedCard: FC<ProviderAddedCardProps> = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
configurationMethods.includes(ConfigurationMethodEnum.predefinedModel) && (
|
configurationMethods.includes(ConfigurationMethodEnum.predefinedModel) && isCurrentWorkspaceManager && (
|
||||||
<CredentialPanel
|
<CredentialPanel
|
||||||
onSetup={() => onOpenModal(ConfigurationMethodEnum.predefinedModel)}
|
onSetup={() => onOpenModal(ConfigurationMethodEnum.predefinedModel)}
|
||||||
provider={provider}
|
provider={provider}
|
||||||
@ -138,7 +140,7 @@ const ProviderAddedCard: FC<ProviderAddedCardProps> = ({
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
configurationMethods.includes(ConfigurationMethodEnum.customizableModel) && (
|
configurationMethods.includes(ConfigurationMethodEnum.customizableModel) && isCurrentWorkspaceManager && (
|
||||||
<AddModelButton
|
<AddModelButton
|
||||||
onClick={() => onOpenModal(ConfigurationMethodEnum.customizableModel)}
|
onClick={() => onOpenModal(ConfigurationMethodEnum.customizableModel)}
|
||||||
className='hidden group-hover:flex group-hover:text-primary-600'
|
className='hidden group-hover:flex group-hover:text-primary-600'
|
||||||
|
@ -15,6 +15,7 @@ import TooltipPlus from '@/app/components/base/tooltip-plus'
|
|||||||
import { useProviderContext, useProviderContextSelector } from '@/context/provider-context'
|
import { useProviderContext, useProviderContextSelector } from '@/context/provider-context'
|
||||||
import { disableModel, enableModel } from '@/service/common'
|
import { disableModel, enableModel } from '@/service/common'
|
||||||
import { Plan } from '@/app/components/billing/type'
|
import { Plan } from '@/app/components/billing/type'
|
||||||
|
import { useAppContext } from '@/context/app-context'
|
||||||
|
|
||||||
export type ModelListItemProps = {
|
export type ModelListItemProps = {
|
||||||
model: ModelItem
|
model: ModelItem
|
||||||
@ -28,6 +29,7 @@ const ModelListItem = ({ model, provider, isConfigurable, onConfig, onModifyLoad
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { plan } = useProviderContext()
|
const { plan } = useProviderContext()
|
||||||
const modelLoadBalancingEnabled = useProviderContextSelector(state => state.modelLoadBalancingEnabled)
|
const modelLoadBalancingEnabled = useProviderContextSelector(state => state.modelLoadBalancingEnabled)
|
||||||
|
const { isCurrentWorkspaceManager } = useAppContext()
|
||||||
|
|
||||||
const toggleModelEnablingStatus = useCallback(async (enabled: boolean) => {
|
const toggleModelEnablingStatus = useCallback(async (enabled: boolean) => {
|
||||||
if (enabled)
|
if (enabled)
|
||||||
@ -73,7 +75,7 @@ const ModelListItem = ({ model, provider, isConfigurable, onConfig, onModifyLoad
|
|||||||
<div className='shrink-0 flex items-center'>
|
<div className='shrink-0 flex items-center'>
|
||||||
{
|
{
|
||||||
model.fetch_from === ConfigurationMethodEnum.customizableModel
|
model.fetch_from === ConfigurationMethodEnum.customizableModel
|
||||||
? (
|
? (isCurrentWorkspaceManager && (
|
||||||
<Button
|
<Button
|
||||||
className='hidden group-hover:flex h-7'
|
className='hidden group-hover:flex h-7'
|
||||||
onClick={() => onConfig({ __model_name: model.model, __model_type: model.model_type })}
|
onClick={() => onConfig({ __model_name: model.model, __model_type: model.model_type })}
|
||||||
@ -81,8 +83,8 @@ const ModelListItem = ({ model, provider, isConfigurable, onConfig, onModifyLoad
|
|||||||
<Settings01 className='mr-[5px] w-3.5 h-3.5' />
|
<Settings01 className='mr-[5px] w-3.5 h-3.5' />
|
||||||
{t('common.modelProvider.config')}
|
{t('common.modelProvider.config')}
|
||||||
</Button>
|
</Button>
|
||||||
)
|
))
|
||||||
: ((modelLoadBalancingEnabled || plan.type === Plan.sandbox) && !model.deprecated && [ModelStatusEnum.active, ModelStatusEnum.disabled].includes(model.status))
|
: (isCurrentWorkspaceManager && (modelLoadBalancingEnabled || plan.type === Plan.sandbox) && !model.deprecated && [ModelStatusEnum.active, ModelStatusEnum.disabled].includes(model.status))
|
||||||
? (
|
? (
|
||||||
<Button
|
<Button
|
||||||
className='opacity-0 group-hover:opacity-100 h-[28px] transition-opacity'
|
className='opacity-0 group-hover:opacity-100 h-[28px] transition-opacity'
|
||||||
@ -101,7 +103,7 @@ const ModelListItem = ({ model, provider, isConfigurable, onConfig, onModifyLoad
|
|||||||
<Switch defaultValue={false} disabled size='md' />
|
<Switch defaultValue={false} disabled size='md' />
|
||||||
</TooltipPlus>
|
</TooltipPlus>
|
||||||
)
|
)
|
||||||
: (
|
: (isCurrentWorkspaceManager && (
|
||||||
<Switch
|
<Switch
|
||||||
className='ml-2'
|
className='ml-2'
|
||||||
defaultValue={model?.status === ModelStatusEnum.active}
|
defaultValue={model?.status === ModelStatusEnum.active}
|
||||||
@ -109,7 +111,7 @@ const ModelListItem = ({ model, provider, isConfigurable, onConfig, onModifyLoad
|
|||||||
size='md'
|
size='md'
|
||||||
onChange={onEnablingStateChange}
|
onChange={onEnablingStateChange}
|
||||||
/>
|
/>
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -14,6 +14,7 @@ import AddModelButton from './add-model-button'
|
|||||||
import ModelListItem from './model-list-item'
|
import ModelListItem from './model-list-item'
|
||||||
import { ChevronDownDouble } from '@/app/components/base/icons/src/vender/line/arrows'
|
import { ChevronDownDouble } from '@/app/components/base/icons/src/vender/line/arrows'
|
||||||
import { useModalContextSelector } from '@/context/modal-context'
|
import { useModalContextSelector } from '@/context/modal-context'
|
||||||
|
import { useAppContext } from '@/context/app-context'
|
||||||
|
|
||||||
type ModelListProps = {
|
type ModelListProps = {
|
||||||
provider: ModelProvider
|
provider: ModelProvider
|
||||||
@ -31,6 +32,7 @@ const ModelList: FC<ModelListProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const configurativeMethods = provider.configurate_methods.filter(method => method !== ConfigurationMethodEnum.fetchFromRemote)
|
const configurativeMethods = provider.configurate_methods.filter(method => method !== ConfigurationMethodEnum.fetchFromRemote)
|
||||||
|
const { isCurrentWorkspaceManager } = useAppContext()
|
||||||
const isConfigurable = configurativeMethods.includes(ConfigurationMethodEnum.customizableModel)
|
const isConfigurable = configurativeMethods.includes(ConfigurationMethodEnum.customizableModel)
|
||||||
|
|
||||||
const setShowModelLoadBalancingModal = useModalContextSelector(state => state.setShowModelLoadBalancingModal)
|
const setShowModelLoadBalancingModal = useModalContextSelector(state => state.setShowModelLoadBalancingModal)
|
||||||
@ -68,7 +70,7 @@ const ModelList: FC<ModelListProps> = ({
|
|||||||
)
|
)
|
||||||
} */}
|
} */}
|
||||||
{
|
{
|
||||||
isConfigurable && (
|
isConfigurable && isCurrentWorkspaceManager && (
|
||||||
<div className='grow flex justify-end'>
|
<div className='grow flex justify-end'>
|
||||||
<AddModelButton onClick={() => onConfig()} />
|
<AddModelButton onClick={() => onConfig()} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -19,6 +19,7 @@ import ProviderIcon from '../provider-icon'
|
|||||||
import s from './index.module.css'
|
import s from './index.module.css'
|
||||||
import { Settings01 } from '@/app/components/base/icons/src/vender/line/general'
|
import { Settings01 } from '@/app/components/base/icons/src/vender/line/general'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
|
import { useAppContext } from '@/context/app-context'
|
||||||
|
|
||||||
type ProviderCardProps = {
|
type ProviderCardProps = {
|
||||||
provider: ModelProvider
|
provider: ModelProvider
|
||||||
@ -31,6 +32,7 @@ const ProviderCard: FC<ProviderCardProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const language = useLanguage()
|
const language = useLanguage()
|
||||||
|
const { isCurrentWorkspaceManager } = useAppContext()
|
||||||
const configurateMethods = provider.configurate_methods.filter(method => method !== ConfigurationMethodEnum.fetchFromRemote)
|
const configurateMethods = provider.configurate_methods.filter(method => method !== ConfigurationMethodEnum.fetchFromRemote)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -72,6 +74,7 @@ const ProviderCard: FC<ProviderCardProps> = ({
|
|||||||
key={method}
|
key={method}
|
||||||
className={'h-7 text-xs shrink-0'}
|
className={'h-7 text-xs shrink-0'}
|
||||||
onClick={() => onOpenModal(method)}
|
onClick={() => onOpenModal(method)}
|
||||||
|
disabled={!isCurrentWorkspaceManager}
|
||||||
>
|
>
|
||||||
<Settings01 className={`mr-[5px] w-3.5 h-3.5 ${s.icon}`} />
|
<Settings01 className={`mr-[5px] w-3.5 h-3.5 ${s.icon}`} />
|
||||||
<span className='text-xs inline-flex items-center justify-center overflow-ellipsis shrink-0'>{t('common.operation.setup')}</span>
|
<span className='text-xs inline-flex items-center justify-center overflow-ellipsis shrink-0'>{t('common.operation.setup')}</span>
|
||||||
@ -83,6 +86,7 @@ const ProviderCard: FC<ProviderCardProps> = ({
|
|||||||
key={method}
|
key={method}
|
||||||
className='px-0 h-7 text-xs'
|
className='px-0 h-7 text-xs'
|
||||||
onClick={() => onOpenModal(method)}
|
onClick={() => onOpenModal(method)}
|
||||||
|
disabled={!isCurrentWorkspaceManager}
|
||||||
>
|
>
|
||||||
<RiAddLine className='mr-[5px] w-3.5 h-3.5' />
|
<RiAddLine className='mr-[5px] w-3.5 h-3.5' />
|
||||||
{t('common.modelProvider.addModel')}
|
{t('common.modelProvider.addModel')}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user