From 5fc104a99283e06362d7df40fd67d1e53a1e9a66 Mon Sep 17 00:00:00 2001 From: NFish Date: Mon, 13 Oct 2025 16:17:42 +0800 Subject: [PATCH] Fix/web app permission check (#26821) --- .../base/chat/embedded-chatbot/context.tsx | 14 ++++----- .../base/chat/embedded-chatbot/hooks.tsx | 29 ++++--------------- .../base/chat/embedded-chatbot/index.tsx | 2 -- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/web/app/components/base/chat/embedded-chatbot/context.tsx b/web/app/components/base/chat/embedded-chatbot/context.tsx index 544da253af..d6c35e172e 100644 --- a/web/app/components/base/chat/embedded-chatbot/context.tsx +++ b/web/app/components/base/chat/embedded-chatbot/context.tsx @@ -17,12 +17,9 @@ import type { import { noop } from 'lodash-es' export type EmbeddedChatbotContextValue = { - userCanAccess?: boolean - appInfoError?: any - appInfoLoading?: boolean - appMeta?: AppMeta - appData?: AppData - appParams?: ChatConfig + appMeta: AppMeta | null + appData: AppData | null + appParams: ChatConfig | null appChatListDataLoading?: boolean currentConversationId: string currentConversationItem?: ConversationItem @@ -59,7 +56,10 @@ export type EmbeddedChatbotContextValue = { } export const EmbeddedChatbotContext = createContext({ - userCanAccess: false, + appData: null, + appMeta: null, + appParams: null, + appChatListDataLoading: false, currentConversationId: '', appPrevChatList: [], pinnedConversationList: [], diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index aa7006db25..6987955b74 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -18,9 +18,6 @@ import { CONVERSATION_ID_INFO } from '../constants' import { buildChatItemTree, getProcessedInputsFromUrlParams, getProcessedSystemVariablesFromUrlParams, getProcessedUserVariablesFromUrlParams } from '../utils' import { getProcessedFilesFromResponse } from '../../file-uploader/utils' import { - fetchAppInfo, - fetchAppMeta, - fetchAppParams, fetchChatList, fetchConversations, generationConversationName, @@ -36,8 +33,7 @@ import { InputVarType } from '@/app/components/workflow/types' import { TransferMethod } from '@/types/app' import { addFileInfos, sortAgentSorts } from '@/app/components/tools/utils' import { noop } from 'lodash-es' -import { useGetUserCanAccessApp } from '@/service/access-control' -import { useGlobalPublicStore } from '@/context/global-public-context' +import { useWebAppStore } from '@/context/web-app-context' function getFormattedChatList(messages: any[]) { const newChatList: ChatItem[] = [] @@ -67,18 +63,10 @@ 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: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ - appId: appInfo?.app_id, - isInstalledApp, - enabled: systemFeatures.webapp_auth.enabled, - }) - - const appData = useMemo(() => { - return appInfo - }, [appInfo]) - const appId = useMemo(() => appData?.app_id, [appData]) + const appInfo = useWebAppStore(s => s.appInfo) + const appMeta = useWebAppStore(s => s.appMeta) + const appParams = useWebAppStore(s => s.appParams) + const appId = useMemo(() => appInfo?.app_id, [appInfo]) const [userId, setUserId] = useState() const [conversationId, setConversationId] = useState() @@ -145,8 +133,6 @@ export const useEmbeddedChatbot = () => { return currentConversationId }, [currentConversationId, newConversationId]) - const { data: appParams } = useSWR(['appParams', isInstalledApp, appId], () => fetchAppParams(isInstalledApp, appId)) - const { data: appMeta } = useSWR(['appMeta', isInstalledApp, appId], () => fetchAppMeta(isInstalledApp, appId)) const { data: appPinnedConversationData } = useSWR(['appConversationData', isInstalledApp, appId, true], () => fetchConversations(isInstalledApp, appId, undefined, true, 100)) const { data: appConversationData, isLoading: appConversationDataLoading, mutate: mutateAppConversationData } = useSWR(['appConversationData', isInstalledApp, appId, false], () => fetchConversations(isInstalledApp, appId, undefined, false, 100)) const { data: appChatListData, isLoading: appChatListDataLoading } = useSWR(chatShouldReloadKey ? ['appChatList', chatShouldReloadKey, isInstalledApp, appId] : null, () => fetchChatList(chatShouldReloadKey, isInstalledApp, appId)) @@ -398,16 +384,13 @@ export const useEmbeddedChatbot = () => { }, [isInstalledApp, appId, t, notify]) return { - appInfoError, - appInfoLoading: appInfoLoading || (systemFeatures.webapp_auth.enabled && isCheckingPermission), - userCanAccess: systemFeatures.webapp_auth.enabled ? userCanAccessResult?.result : true, isInstalledApp, allowResetChat, appId, currentConversationId, currentConversationItem, handleConversationIdInfoChange, - appData, + appData: appInfo, appParams: appParams || {} as ChatConfig, appMeta, appPinnedConversationData, diff --git a/web/app/components/base/chat/embedded-chatbot/index.tsx b/web/app/components/base/chat/embedded-chatbot/index.tsx index 4c8c0a2455..df188e35d4 100644 --- a/web/app/components/base/chat/embedded-chatbot/index.tsx +++ b/web/app/components/base/chat/embedded-chatbot/index.tsx @@ -101,7 +101,6 @@ const EmbeddedChatbotWrapper = () => { const { appData, - userCanAccess, appParams, appMeta, appChatListDataLoading, @@ -135,7 +134,6 @@ const EmbeddedChatbotWrapper = () => { } = useEmbeddedChatbot() return