Skip to content

Commit 743b6ab

Browse files
committed
feat: system plugin auth and lock version (#3265)
* feat: system plugin auth and lock version * update comment
1 parent 2922291 commit 743b6ab

File tree

2 files changed

+25
-9
lines changed
  • docSite/content/zh-cn/docs/development/upgrading
  • packages/service/core/app/plugin

2 files changed

+25
-9
lines changed

docSite/content/zh-cn/docs/development/upgrading/4815.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ weight: 809
1111
## 完整更新内容
1212

1313
1.
14-
2. 优化 - base64 图片截取判断。
14+
2. 新增 - 工具箱页面,展示所有可用的系统资源。商业版后台可更便捷的配置系统插件和自定义分类。
15+
3. 新增 - Markdown 中,HTML代码会被额外渲染,可以选择预览模式,会限制所有 script 脚本,仅做展示。
16+
4. 优化 - base64 图片截取判断。

packages/service/core/app/plugin/controller.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { SystemPluginTemplateItemType } from '@fastgpt/global/core/workflow/type
1111
import { getSystemPluginTemplates } from '../../../../plugins/register';
1212
import { getAppLatestVersion, getAppVersionById } from '../version/controller';
1313
import { PluginRuntimeType } from '@fastgpt/global/core/plugin/type';
14+
import { MongoSystemPlugin } from './systemPluginSchema';
15+
import { PluginErrEnum } from '@fastgpt/global/common/error/code/plugin';
1416

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

3840
type ChildAppType = SystemPluginTemplateItemType & { teamId?: string };
3941
const getSystemPluginTemplateById = async (
40-
pluginId: string
42+
pluginId: string,
43+
versionId?: string
4144
): Promise<SystemPluginTemplateItemType> => {
4245
const item = getSystemPluginTemplates().find((plugin) => plugin.id === pluginId);
43-
if (!item) return Promise.reject('plugin not found');
46+
if (!item) return Promise.reject(PluginErrEnum.unAuth);
4447

4548
const plugin = cloneDeep(item);
4649

4750
if (plugin.associatedPluginId) {
48-
// TODO: check is system plugin
51+
// The verification plugin is set as a system plugin
52+
const systemPlugin = await MongoSystemPlugin.findOne(
53+
{ pluginId: plugin.id, 'customConfig.associatedPluginId': plugin.associatedPluginId },
54+
'associatedPluginId'
55+
).lean();
56+
if (!systemPlugin) return Promise.reject(PluginErrEnum.unAuth);
4957

5058
const app = await MongoApp.findById(plugin.associatedPluginId).lean();
51-
if (!app) return Promise.reject('plugin not found');
52-
53-
const version = await getAppLatestVersion(plugin.associatedPluginId, app);
59+
if (!app) return Promise.reject(PluginErrEnum.unAuth);
60+
61+
const version = versionId
62+
? await getAppVersionById({
63+
appId: plugin.associatedPluginId,
64+
versionId,
65+
app
66+
})
67+
: await getAppLatestVersion(plugin.associatedPluginId, app);
5468
if (!version.versionId) return Promise.reject('App version not found');
5569

5670
plugin.workflow = {
5771
nodes: version.nodes,
5872
edges: version.edges,
5973
chatConfig: version.chatConfig
6074
};
75+
plugin.version = versionId || String(version.versionId);
6176
}
62-
6377
return plugin;
6478
};
6579

@@ -172,7 +186,7 @@ export async function getChildAppRuntimeById(
172186
pluginOrder: 0
173187
};
174188
} else {
175-
return getSystemPluginTemplateById(pluginId);
189+
return getSystemPluginTemplateById(pluginId, versionId);
176190
}
177191
})();
178192

0 commit comments

Comments
 (0)