diff --git a/packages/libs/lib-server/src/system/settings/service/models.ts b/packages/libs/lib-server/src/system/settings/service/models.ts index 71dd0d6be..37cf86868 100644 --- a/packages/libs/lib-server/src/system/settings/service/models.ts +++ b/packages/libs/lib-server/src/system/settings/service/models.ts @@ -15,6 +15,7 @@ export class SysPublicSettings extends BaseSettings { static __title__ = '系统公共设置'; static __access__ = 'public'; registerEnabled = false; + limitUserPipelineCount = 0; managerOtherUserPipeline = false; icpNo?: string; // triggerOnStartup = false; diff --git a/packages/libs/lib-server/src/system/settings/service/sys-settings-service.ts b/packages/libs/lib-server/src/system/settings/service/sys-settings-service.ts index 6d89ffbbd..35c9e98f5 100644 --- a/packages/libs/lib-server/src/system/settings/service/sys-settings-service.ts +++ b/packages/libs/lib-server/src/system/settings/service/sys-settings-service.ts @@ -127,14 +127,12 @@ export class SysSettingsService extends BaseService { async reloadPrivateSettings() { const bean = await this.getPrivateSettings(); - if (bean.httpProxy || bean.httpsProxy) { - const opts = { - httpProxy: bean.httpProxy, - httpsProxy: bean.httpsProxy, - }; - setGlobalProxy(opts); - agents.setGlobalProxy(opts); - } + const opts = { + httpProxy: bean.httpProxy, + httpsProxy: bean.httpsProxy, + }; + setGlobalProxy(opts); + agents.setGlobalProxy(opts); } async updateByKey(key: string, setting: any) { diff --git a/packages/ui/certd-client/src/views/sys/settings/api.ts b/packages/ui/certd-client/src/views/sys/settings/api.ts index 17711b5ab..78213015a 100644 --- a/packages/ui/certd-client/src/views/sys/settings/api.ts +++ b/packages/ui/certd-client/src/views/sys/settings/api.ts @@ -5,6 +5,7 @@ export type SysSettings = { public: SysPublicSetting; private: SysPrivateSetting export type SysPublicSetting = { registerEnabled?: boolean; + limitUserPipelineCount?: number; managerOtherUserPipeline?: boolean; icpNo?: string; }; diff --git a/packages/ui/certd-client/src/views/sys/settings/index.vue b/packages/ui/certd-client/src/views/sys/settings/index.vue index f7cddd965..39cd188b6 100644 --- a/packages/ui/certd-client/src/views/sys/settings/index.vue +++ b/packages/ui/certd-client/src/views/sys/settings/index.vue @@ -16,6 +16,10 @@ + + +
0为不限制
+
@@ -30,7 +34,7 @@
- 测试 + 测试
一般这两个代理填一样的
@@ -57,7 +61,7 @@ defineOptions({ const formState = reactive>({ public: { registerEnabled: false, - limitUserPipelineCount: 10, + limitUserPipelineCount: 0, managerOtherUserPipeline: false, icpNo: "" }, @@ -101,13 +105,19 @@ async function stopOtherUserTimer() { }); } +const testProxyLoading = ref(false); async function testProxy() { - const res = await api.TestProxy(); - const content = `测试google:${res.google === true ? "成功" : "失败" + res.google},测试百度:${res.baidu === true ? "成功" : "失败:" + res.baidu}`; - notification.success({ - message: "测试完成", - description: content - }); + testProxyLoading.value = true; + try { + const res = await api.TestProxy(); + const content = `测试google:${res.google === true ? "成功" : "失败" + res.google},测试百度:${res.baidu === true ? "成功" : "失败:" + res.baidu}`; + notification.success({ + message: "测试完成", + description: content + }); + } finally { + testProxyLoading.value = false; + } } diff --git a/packages/ui/certd-server/src/controller/sys/settings/sys-settings-controller.ts b/packages/ui/certd-server/src/controller/sys/settings/sys-settings-controller.ts index 129bed890..cb99d353b 100644 --- a/packages/ui/certd-server/src/controller/sys/settings/sys-settings-controller.ts +++ b/packages/ui/certd-server/src/controller/sys/settings/sys-settings-controller.ts @@ -111,7 +111,9 @@ export class SysSettingsController extends CrudController { await http.request({ url: google, method: 'GET', - timeout: 4000, + timeout: 5000, + logRes: false, + logParams: false, }); googleRes = true; } catch (e) { @@ -123,7 +125,9 @@ export class SysSettingsController extends CrudController { await http.request({ url: baidu, method: 'GET', - timeout: 4000, + timeout: 5000, + logRes: false, + logParams: false, }); baiduRes = true; } catch (e) { diff --git a/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts index 038aa520d..83ebd30f0 100644 --- a/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts +++ b/packages/ui/certd-server/src/modules/pipeline/service/pipeline-service.ts @@ -1,7 +1,7 @@ import { Config, Inject, Provide, Scope, ScopeEnum, sleep } from '@midwayjs/core'; import { InjectEntityModel } from '@midwayjs/typeorm'; import { In, Repository } from 'typeorm'; -import { BaseService, NeedVIPException, PageReq } from '@certd/lib-server'; +import { BaseService, NeedVIPException, PageReq, SysPublicSettings, SysSettingsService } from '@certd/lib-server'; import { PipelineEntity } from '../entity/pipeline.js'; import { PipelineDetail } from '../entity/vo/pipeline-detail.js'; import { Executor, isPlus, logger, Pipeline, ResultType, RunHistory, UserInfo } from '@certd/pipeline'; @@ -47,6 +47,9 @@ export class PipelineService extends BaseService { @Inject() pluginConfigGetter: PluginConfigGetter; + @Inject() + sysSettingsService: SysSettingsService; + @Inject() userService: UserService; @@ -121,16 +124,27 @@ export class PipelineService extends BaseService { old = await this.info(bean.id); } const isUpdate = bean.id > 0 && old != null; - if (!isPlus()) { - let count = await this.repository.count(); - if (!isUpdate) { - //如果是添加要加1 - count += 1; + if (!isUpdate) { + //如果是添加,校验数量 + if (!isPlus()) { + const count = await this.repository.count(); + if (count >= freeCount) { + throw new NeedVIPException(`基础版最多只能创建${freeCount}条流水线`); + } } - if (count > freeCount) { - throw new NeedVIPException('基础版最多只能创建10个pipeline'); + const userId = bean.userId; + const userIsAdmin = await this.userService.isAdmin(userId); + if (!userIsAdmin) { + //非管理员用户,限制pipeline数量 + const count = await this.repository.count({ where: { userId } }); + const sysPublic = await this.sysSettingsService.getSetting(SysPublicSettings); + const limitUserPipelineCount = sysPublic.limitUserPipelineCount; + if (limitUserPipelineCount && limitUserPipelineCount > 0 && count >= limitUserPipelineCount) { + throw new NeedVIPException(`您最多只能创建${limitUserPipelineCount}条流水线`); + } } } + if (!isUpdate) { //如果是添加,先保存一下,获取到id,更新pipeline.id await this.addOrUpdate(bean);