Skip to content

feat: system plugin auth and lock version #3265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docSite/content/zh-cn/docs/development/upgrading/4815.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ weight: 809
## 完整更新内容

1.
2. 优化 - base64 图片截取判断。
2. 新增 - 工具箱页面,展示所有可用的系统资源。商业版后台可更便捷的配置系统插件和自定义分类。
3. 新增 - Markdown 中,HTML代码会被额外渲染,可以选择预览模式,会限制所有 script 脚本,仅做展示。
4. 优化 - base64 图片截取判断。
30 changes: 22 additions & 8 deletions packages/service/core/app/plugin/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { SystemPluginTemplateItemType } from '@fastgpt/global/core/workflow/type
import { getSystemPluginTemplates } from '../../../../plugins/register';
import { getAppLatestVersion, getAppVersionById } from '../version/controller';
import { PluginRuntimeType } from '@fastgpt/global/core/plugin/type';
import { MongoSystemPlugin } from './systemPluginSchema';
import { PluginErrEnum } from '@fastgpt/global/common/error/code/plugin';

/*
plugin id rule:
Expand All @@ -37,29 +39,41 @@ export async function splitCombinePluginId(id: string) {

type ChildAppType = SystemPluginTemplateItemType & { teamId?: string };
const getSystemPluginTemplateById = async (
pluginId: string
pluginId: string,
versionId?: string
): Promise<SystemPluginTemplateItemType> => {
const item = getSystemPluginTemplates().find((plugin) => plugin.id === pluginId);
if (!item) return Promise.reject('plugin not found');
if (!item) return Promise.reject(PluginErrEnum.unAuth);

const plugin = cloneDeep(item);

if (plugin.associatedPluginId) {
// TODO: check is system plugin
// The verification plugin is set as a system plugin
const systemPlugin = await MongoSystemPlugin.findOne(
{ pluginId: plugin.id, 'customConfig.associatedPluginId': plugin.associatedPluginId },
'associatedPluginId'
).lean();
if (!systemPlugin) return Promise.reject(PluginErrEnum.unAuth);

const app = await MongoApp.findById(plugin.associatedPluginId).lean();
if (!app) return Promise.reject('plugin not found');

const version = await getAppLatestVersion(plugin.associatedPluginId, app);
if (!app) return Promise.reject(PluginErrEnum.unAuth);

const version = versionId
? await getAppVersionById({
appId: plugin.associatedPluginId,
versionId,
app
})
: await getAppLatestVersion(plugin.associatedPluginId, app);
if (!version.versionId) return Promise.reject('App version not found');

plugin.workflow = {
nodes: version.nodes,
edges: version.edges,
chatConfig: version.chatConfig
};
plugin.version = versionId || String(version.versionId);
}

return plugin;
};

Expand Down Expand Up @@ -172,7 +186,7 @@ export async function getChildAppRuntimeById(
pluginOrder: 0
};
} else {
return getSystemPluginTemplateById(pluginId);
return getSystemPluginTemplateById(pluginId, versionId);
}
})();

Expand Down
Loading