Feat: add check before install plugin (#20014)
parent
83719cab73
commit
614c5e087e
@ -0,0 +1,46 @@
|
|||||||
|
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||||
|
import type { SystemFeatures } from '@/types/feature'
|
||||||
|
import { InstallationScope } from '@/types/feature'
|
||||||
|
import type { Plugin, PluginManifestInMarket } from '../../types'
|
||||||
|
|
||||||
|
type PluginProps = (Plugin | PluginManifestInMarket) & { from: 'github' | 'marketplace' | 'package' }
|
||||||
|
|
||||||
|
export function pluginInstallLimit(plugin: PluginProps, systemFeatures: SystemFeatures) {
|
||||||
|
if (systemFeatures.plugin_installation_permission.restrict_to_marketplace_only) {
|
||||||
|
if (plugin.from === 'github' || plugin.from === 'package')
|
||||||
|
return { canInstall: false }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (systemFeatures.plugin_installation_permission.plugin_installation_scope === InstallationScope.ALL) {
|
||||||
|
return {
|
||||||
|
canInstall: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (systemFeatures.plugin_installation_permission.plugin_installation_scope === InstallationScope.NONE) {
|
||||||
|
return {
|
||||||
|
canInstall: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const verification = plugin.verification || {}
|
||||||
|
if (!plugin.verification || !plugin.verification.authorized_category)
|
||||||
|
verification.authorized_category = 'langgenius'
|
||||||
|
|
||||||
|
if (systemFeatures.plugin_installation_permission.plugin_installation_scope === InstallationScope.OFFICIAL_ONLY) {
|
||||||
|
return {
|
||||||
|
canInstall: verification.authorized_category === 'langgenius',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (systemFeatures.plugin_installation_permission.plugin_installation_scope === InstallationScope.OFFICIAL_AND_PARTNER) {
|
||||||
|
return {
|
||||||
|
canInstall: verification.authorized_category === 'langgenius' || verification.authorized_category === 'partner',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
canInstall: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function usePluginInstallLimit(plugin: PluginProps) {
|
||||||
|
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
|
||||||
|
return pluginInstallLimit(plugin, systemFeatures)
|
||||||
|
}
|
||||||
@ -1,30 +0,0 @@
|
|||||||
'use client'
|
|
||||||
import type { FC } from 'react'
|
|
||||||
import classNames from '@/utils/classnames'
|
|
||||||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
|
||||||
import { useTheme } from 'next-themes'
|
|
||||||
|
|
||||||
type LoginLogoProps = {
|
|
||||||
className?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const LoginLogo: FC<LoginLogoProps> = ({
|
|
||||||
className,
|
|
||||||
}) => {
|
|
||||||
const { systemFeatures } = useGlobalPublicStore()
|
|
||||||
const { theme } = useTheme()
|
|
||||||
|
|
||||||
let src = theme === 'light' ? '/logo/logo-site.png' : `/logo/logo-site-${theme}.png`
|
|
||||||
if (systemFeatures.branding.enabled)
|
|
||||||
src = systemFeatures.branding.login_page_logo
|
|
||||||
|
|
||||||
return (
|
|
||||||
<img
|
|
||||||
src={src}
|
|
||||||
className={classNames('block w-auto h-10', className)}
|
|
||||||
alt='logo'
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default LoginLogo
|
|
||||||
Loading…
Reference in New Issue