diff --git a/web/app/(commonLayout)/apps/AppCard.tsx b/web/app/(commonLayout)/apps/AppCard.tsx index 315520e10f..468c8244c0 100644 --- a/web/app/(commonLayout)/apps/AppCard.tsx +++ b/web/app/(commonLayout)/apps/AppCard.tsx @@ -34,6 +34,7 @@ import { AppTypeIcon } from '@/app/components/app/type-selector' import Tooltip from '@/app/components/base/tooltip' import AccessControl from '@/app/components/app/app-access-control' import { AccessMode } from '@/models/access-control' +import { useGlobalPublicStore } from '@/context/global-public-context' export type AppCardProps = { app: App @@ -43,6 +44,7 @@ export type AppCardProps = { const AppCard = ({ app, onRefresh }: AppCardProps) => { const { t } = useTranslation() const { notify } = useContext(ToastContext) + const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) const { isCurrentWorkspaceEditor } = useAppContext() const { onPlanInfoChanged } = useProviderContext() const { push } = useRouter() @@ -208,13 +210,13 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => { e.preventDefault() exportCheck() } - const onClickSwitch = async (e: React.MouseEvent) => { + const onClickSwitch = async (e: React.MouseEvent) => { e.stopPropagation() props.onClick?.() e.preventDefault() setShowSwitchModal(true) } - const onClickDelete = async (e: React.MouseEvent) => { + const onClickDelete = async (e: React.MouseEvent) => { e.stopPropagation() props.onClick?.() e.preventDefault() @@ -242,49 +244,49 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => { } } return ( -
- - - - {(app.mode === 'completion' || app.mode === 'chat') && ( <> - -
+
+ )} - - - + { - isCurrentWorkspaceEditor && <> - - + } -
{t('common.operation.delete')} -
+
) } diff --git a/web/app/components/app/app-publisher/index.tsx b/web/app/components/app/app-publisher/index.tsx index 5b1adb5717..b24c865c42 100644 --- a/web/app/components/app/app-publisher/index.tsx +++ b/web/app/components/app/app-publisher/index.tsx @@ -44,6 +44,7 @@ import type { PublishWorkflowParams } from '@/types/workflow' import { useAppWhiteListSubjects, useGetUserCanAccessApp } from '@/service/access-control' import { AccessMode } from '@/models/access-control' import { fetchAppDetail } from '@/service/apps' +import { useGlobalPublicStore } from '@/context/global-public-context' export type AppPublisherProps = { disabled?: boolean @@ -85,17 +86,18 @@ const AppPublisher = ({ const [open, setOpen] = useState(false) const appDetail = useAppStore(state => state.appDetail) const setAppDetail = useAppStore(s => s.setAppDetail) + const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) const { app_base_url: appBaseURL = '', access_token: accessToken = '' } = appDetail?.site ?? {} const appMode = (appDetail?.mode !== 'completion' && appDetail?.mode !== 'workflow') ? 'chat' : appDetail.mode const appURL = `${appBaseURL}${basePath}/${appMode}/${accessToken}` const isChatApp = ['chat', 'agent-chat', 'completion'].includes(appDetail?.mode || '') const { data: userCanAccessApp, isLoading: isGettingUserCanAccessApp, refetch } = useGetUserCanAccessApp({ appId: appDetail?.id, enabled: false }) - const { data: appAccessSubjects, isLoading: isGettingAppWhiteListSubjects } = useAppWhiteListSubjects(appDetail?.id, open && appDetail?.access_mode === AccessMode.SPECIFIC_GROUPS_MEMBERS) + const { data: appAccessSubjects, isLoading: isGettingAppWhiteListSubjects } = useAppWhiteListSubjects(appDetail?.id, open && systemFeatures.webapp_auth.enabled && appDetail?.access_mode === AccessMode.SPECIFIC_GROUPS_MEMBERS) useEffect(() => { - if (open && appDetail) + if (systemFeatures.webapp_auth.enabled && open && appDetail) refetch() - }, [open, appDetail, refetch]) + }, [open, appDetail, refetch, systemFeatures]) const [showAppAccessControl, setShowAppAccessControl] = useState(false) const [isAppAccessSet, setIsAppAccessSet] = useState(true) diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx index 2794e5a054..5ed72650be 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -44,6 +44,7 @@ import { InputVarType } from '@/app/components/workflow/types' import { TransferMethod } from '@/types/app' import { noop } from 'lodash-es' import { useGetAppAccessMode, useGetUserCanAccessApp } from '@/service/access-control' +import { useGlobalPublicStore } from '@/context/global-public-context' function getFormattedChatList(messages: any[]) { const newChatList: ChatItem[] = [] @@ -73,9 +74,18 @@ function getFormattedChatList(messages: any[]) { export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { const isInstalledApp = useMemo(() => !!installedAppInfo, [installedAppInfo]) + const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) const { data: appInfo, isLoading: appInfoLoading, error: appInfoError } = useSWR(installedAppInfo ? null : 'appInfo', fetchAppInfo) - const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode({ appId: installedAppInfo?.app.id || appInfo?.app_id, isInstalledApp }) - const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ appId: installedAppInfo?.app.id || appInfo?.app_id, isInstalledApp }) + const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode({ + appId: installedAppInfo?.app.id || appInfo?.app_id, + isInstalledApp, + enabled: systemFeatures.webapp_auth.enabled, + }) + const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ + appId: installedAppInfo?.app.id || appInfo?.app_id, + isInstalledApp, + enabled: systemFeatures.webapp_auth.enabled, + }) useAppFavicon({ enable: !installedAppInfo, diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index 5ac0cc9f48..e00c40e771 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -37,6 +37,7 @@ import { TransferMethod } from '@/types/app' import { addFileInfos, sortAgentSorts } from '@/app/components/tools/utils' import { noop } from 'lodash-es' import { useGetAppAccessMode, useGetUserCanAccessApp } from '@/service/access-control' +import { useGlobalPublicStore } from '@/context/global-public-context' function getFormattedChatList(messages: any[]) { const newChatList: ChatItem[] = [] @@ -66,9 +67,18 @@ function getFormattedChatList(messages: any[]) { export const useEmbeddedChatbot = () => { const isInstalledApp = false + const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) const { data: appInfo, isLoading: appInfoLoading, error: appInfoError } = useSWR('appInfo', fetchAppInfo) - const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode({ appId: appInfo?.app_id, isInstalledApp }) - const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ appId: appInfo?.app_id, isInstalledApp }) + const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode({ + appId: appInfo?.app_id, + isInstalledApp, + enabled: systemFeatures.webapp_auth.enabled, + }) + const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ + appId: appInfo?.app_id, + isInstalledApp, + enabled: systemFeatures.webapp_auth.enabled, + }) const appData = useMemo(() => { return appInfo diff --git a/web/app/components/share/text-generation/index.tsx b/web/app/components/share/text-generation/index.tsx index ce715b66fd..d4c33dff22 100644 --- a/web/app/components/share/text-generation/index.tsx +++ b/web/app/components/share/text-generation/index.tsx @@ -41,6 +41,7 @@ import LogoSite from '@/app/components/base/logo/logo-site' import cn from '@/utils/classnames' import { useGetAppAccessMode, useGetUserCanAccessApp } from '@/service/access-control' import { AccessMode } from '@/models/access-control' +import { useGlobalPublicStore } from '@/context/global-public-context' const GROUP_SIZE = 5 // to avoid RPM(Request per minute) limit. The group task finished then the next group. enum TaskStatus { @@ -101,6 +102,7 @@ const TextGeneration: FC = ({ doSetInputs(newInputs) inputsRef.current = newInputs }, []) + const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) const [appId, setAppId] = useState('') const [siteInfo, setSiteInfo] = useState(null) const [canReplaceLogo, setCanReplaceLogo] = useState(false) @@ -109,8 +111,16 @@ const TextGeneration: FC = ({ const [moreLikeThisConfig, setMoreLikeThisConfig] = useState(null) const [textToSpeechConfig, setTextToSpeechConfig] = useState(null) - const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode({ appId, isInstalledApp }) - const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ appId, isInstalledApp }) + const { isPending: isGettingAccessMode, data: appAccessMode } = useGetAppAccessMode({ + appId, + isInstalledApp, + enabled: systemFeatures.webapp_auth.enabled, + }) + const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ + appId, + isInstalledApp, + enabled: systemFeatures.webapp_auth.enabled, + }) // save message const [savedMessages, setSavedMessages] = useState([]) diff --git a/web/service/access-control.ts b/web/service/access-control.ts index 5b9e3bab00..865909d2f9 100644 --- a/web/service/access-control.ts +++ b/web/service/access-control.ts @@ -69,17 +69,17 @@ export const useUpdateAccessMode = () => { }) } -export const useGetAppAccessMode = ({ appId, isInstalledApp = true }: { appId?: string; isInstalledApp?: boolean }) => { +export const useGetAppAccessMode = ({ appId, isInstalledApp = true, enabled }: { appId?: string; isInstalledApp?: boolean; enabled: boolean }) => { return useQuery({ queryKey: [NAME_SPACE, 'app-access-mode', appId], queryFn: () => getAppAccessMode(appId!, isInstalledApp), - enabled: !!appId, + enabled: !!appId && enabled, staleTime: 0, gcTime: 0, }) } -export const useGetUserCanAccessApp = ({ appId, isInstalledApp = true, enabled = true }: { appId?: string; isInstalledApp?: boolean; enabled?: boolean }) => { +export const useGetUserCanAccessApp = ({ appId, isInstalledApp = true, enabled }: { appId?: string; isInstalledApp?: boolean; enabled: boolean }) => { return useQuery({ queryKey: [NAME_SPACE, 'user-can-access-app', appId], queryFn: () => getUserCanAccess(appId!, isInstalledApp),