mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 18:59:07 +08:00
fix: install plugins permissions (#18870)
This commit is contained in:
parent
bed47dffb9
commit
58a929edd5
@ -8,6 +8,7 @@ import { useTranslation } from 'react-i18next'
|
|||||||
import InstallMulti from './install-multi'
|
import InstallMulti from './install-multi'
|
||||||
import { useInstallOrUpdate } from '@/service/use-plugins'
|
import { useInstallOrUpdate } from '@/service/use-plugins'
|
||||||
import useRefreshPluginList from '../../hooks/use-refresh-plugin-list'
|
import useRefreshPluginList from '../../hooks/use-refresh-plugin-list'
|
||||||
|
import { useCanInstallPluginFromMarketplace } from '@/app/components/plugins/plugin-page/use-permission'
|
||||||
const i18nPrefix = 'plugin.installModal'
|
const i18nPrefix = 'plugin.installModal'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -74,6 +75,7 @@ const Install: FC<Props> = ({
|
|||||||
installedInfo: installedInfo!,
|
installedInfo: installedInfo!,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const { canInstallPluginFromMarketplace } = useCanInstallPluginFromMarketplace()
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='flex flex-col items-start justify-center gap-4 self-stretch px-6 py-3'>
|
<div className='flex flex-col items-start justify-center gap-4 self-stretch px-6 py-3'>
|
||||||
@ -101,7 +103,7 @@ const Install: FC<Props> = ({
|
|||||||
<Button
|
<Button
|
||||||
variant='primary'
|
variant='primary'
|
||||||
className='flex min-w-[72px] space-x-0.5'
|
className='flex min-w-[72px] space-x-0.5'
|
||||||
disabled={!canInstall || isInstalling || selectedPlugins.length === 0}
|
disabled={!canInstall || isInstalling || selectedPlugins.length === 0 || !canInstallPluginFromMarketplace}
|
||||||
onClick={handleInstall}
|
onClick={handleInstall}
|
||||||
>
|
>
|
||||||
{isInstalling && <RiLoader2Line className='h-4 w-4 animate-spin-slow' />}
|
{isInstalling && <RiLoader2Line className='h-4 w-4 animate-spin-slow' />}
|
||||||
|
@ -144,10 +144,18 @@ const PluginPage = ({
|
|||||||
return activeTab === PLUGIN_PAGE_TABS_MAP.marketplace || values.includes(activeTab)
|
return activeTab === PLUGIN_PAGE_TABS_MAP.marketplace || values.includes(activeTab)
|
||||||
}, [activeTab])
|
}, [activeTab])
|
||||||
|
|
||||||
|
const handleFileChange = (file: File | null) => {
|
||||||
|
if (!file || !file.name.endsWith('.difypkg')) {
|
||||||
|
setCurrentFile(null)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentFile(file)
|
||||||
|
}
|
||||||
const uploaderProps = useUploader({
|
const uploaderProps = useUploader({
|
||||||
onFileChange: setCurrentFile,
|
onFileChange: handleFileChange,
|
||||||
containerRef,
|
containerRef,
|
||||||
enabled: isPluginsTab,
|
enabled: isPluginsTab && canManagement,
|
||||||
})
|
})
|
||||||
|
|
||||||
const { dragging, fileUploader, fileChangeHandle, removeFile } = uploaderProps
|
const { dragging, fileUploader, fileChangeHandle, removeFile } = uploaderProps
|
||||||
|
@ -3,6 +3,8 @@ import { useAppContext } from '@/context/app-context'
|
|||||||
import Toast from '../../base/toast'
|
import Toast from '../../base/toast'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useInvalidatePermissions, useMutationPermissions, usePermissions } from '@/service/use-plugins'
|
import { useInvalidatePermissions, useMutationPermissions, usePermissions } from '@/service/use-plugins'
|
||||||
|
import { useSelector as useAppContextSelector } from '@/context/app-context'
|
||||||
|
import { useMemo } from 'react'
|
||||||
|
|
||||||
const hasPermission = (permission: PermissionType | undefined, isAdmin: boolean) => {
|
const hasPermission = (permission: PermissionType | undefined, isAdmin: boolean) => {
|
||||||
if (!permission)
|
if (!permission)
|
||||||
@ -43,4 +45,17 @@ const usePermission = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useCanInstallPluginFromMarketplace = () => {
|
||||||
|
const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures)
|
||||||
|
const { canManagement } = usePermission()
|
||||||
|
|
||||||
|
const canInstallPluginFromMarketplace = useMemo(() => {
|
||||||
|
return enable_marketplace && canManagement
|
||||||
|
}, [enable_marketplace, canManagement])
|
||||||
|
|
||||||
|
return {
|
||||||
|
canInstallPluginFromMarketplace,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default usePermission
|
export default usePermission
|
||||||
|
Loading…
x
Reference in New Issue
Block a user