From 4ee6e38a94c06fe37341a3a774744a644c7c0b81 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Fri, 13 Feb 2026 21:28:17 +0800 Subject: [PATCH] chore: project controller ok --- packages/core/pipeline/src/plugin/api.ts | 3 + .../lib-server/src/basic/base-controller.ts | 8 +- .../libs/lib-server/src/basic/base-service.ts | 5 +- .../src/user/access/service/access-getter.ts | 10 ++- .../src/user/access/service/access-service.ts | 18 +++-- .../src/user/addon/service/addon-service.ts | 38 ++++++---- .../src/components/project-selector/index.vue | 8 +- .../certd-client/src/layout/layout-basic.vue | 12 +-- .../src/router/source/modules/certd.ts | 6 +- .../src/vben/layouts/basic/layout.vue | 2 + .../db/migration/v10038__admin_mode.sql | 13 ++++ .../controller/user/addon/addon-controller.ts | 49 ++++++------ .../controller/user/basic/group-controller.ts | 23 ++++-- .../controller/user/cert/domain-controller.ts | 48 ++++++++---- .../user/cname/cname-record-controller.ts | 15 +++- .../mine/setting-two-factor-controller.ts | 4 +- .../user/mine/user-settings-controller.ts | 7 +- .../user/monitor/cert-info-controller.ts | 1 + .../user/monitor/site-info-controller.ts | 1 + .../user/monitor/site-ip-controller.ts | 1 + .../user/open/open-key-controller.ts | 21 +++-- .../user/pipeline/access-controller.ts | 28 ++++--- .../user/pipeline/cert-controller.ts | 5 +- .../user/pipeline/dns-provider-controller.ts | 1 - .../user/pipeline/handle-controller.ts | 12 ++- .../user/pipeline/history-controller.ts | 1 + .../user/pipeline/notification-controller.ts | 39 ++++++---- .../user/pipeline/pipeline-controller.ts | 2 + .../pipeline/pipeline-group-controller.ts | 23 ++++-- .../user/pipeline/plugin-controller.ts | 3 - .../user/pipeline/sub-domain-controller.ts | 26 ++++--- .../user/pipeline/template-controller.ts | 1 + .../src/modules/basic/entity/group.ts | 3 + .../src/modules/cert/entity/domain.ts | 3 + .../modules/cert/service/domain-service.ts | 76 ++++++++++++------- .../src/modules/cname/entity/cname-record.ts | 3 + .../src/modules/mine/entity/user-settings.ts | 3 + .../mine/service/user-settings-service.ts | 29 ++++--- .../src/modules/pipeline/entity/sub-domain.ts | 3 + .../service/getter/notification-getter.ts | 10 ++- .../service/getter/task-service-getter.ts | 12 ++- .../pipeline/service/notification-service.ts | 21 +++-- 42 files changed, 399 insertions(+), 198 deletions(-) diff --git a/packages/core/pipeline/src/plugin/api.ts b/packages/core/pipeline/src/plugin/api.ts index fec035cbd..2ce76af34 100644 --- a/packages/core/pipeline/src/plugin/api.ts +++ b/packages/core/pipeline/src/plugin/api.ts @@ -122,6 +122,9 @@ export type TaskInstanceContext = { //用户信息 user: UserInfo; + //项目id + projectId?: number; + emitter: TaskEmitter; //service 容器 diff --git a/packages/libs/lib-server/src/basic/base-controller.ts b/packages/libs/lib-server/src/basic/base-controller.ts index 092016580..1118067b8 100644 --- a/packages/libs/lib-server/src/basic/base-controller.ts +++ b/packages/libs/lib-server/src/basic/base-controller.ts @@ -65,7 +65,13 @@ export abstract class BaseController { if (!isEnterprise()) { return null } - const projectIdStr = this.ctx.headers["project-id"] as string; + let projectIdStr = this.ctx.headers["project-id"] as string; + if (!projectIdStr){ + projectIdStr = this.ctx.request.query["projectId"] as string; + } + if (!projectIdStr){ + return null + } if (!projectIdStr) { throw new Error("projectId 不能为空") } diff --git a/packages/libs/lib-server/src/basic/base-service.ts b/packages/libs/lib-server/src/basic/base-service.ts index 8efd4416c..d16733d22 100644 --- a/packages/libs/lib-server/src/basic/base-service.ts +++ b/packages/libs/lib-server/src/basic/base-service.ts @@ -233,13 +233,14 @@ export abstract class BaseService { throw new PermissionException('权限不足'); } - async batchDelete(ids: number[], userId: number) { - if(userId >0){ + async batchDelete(ids: number[], userId: number,projectId?:number) { + if(userId!=null){ const list = await this.getRepository().find({ where: { // @ts-ignore id: In(ids), userId, + projectId, }, }) // @ts-ignore diff --git a/packages/libs/lib-server/src/user/access/service/access-getter.ts b/packages/libs/lib-server/src/user/access/service/access-getter.ts index 0fd2d3f19..1bbb75ea8 100644 --- a/packages/libs/lib-server/src/user/access/service/access-getter.ts +++ b/packages/libs/lib-server/src/user/access/service/access-getter.ts @@ -2,17 +2,19 @@ import { IAccessService } from '@certd/pipeline'; export class AccessGetter implements IAccessService { userId: number; - getter: (id: any, userId?: number) => Promise; - constructor(userId: number, getter: (id: any, userId: number) => Promise) { + projectId?: number; + getter: (id: any, userId?: number, projectId?: number) => Promise; + constructor(userId: number, projectId: number, getter: (id: any, userId: number, projectId?: number) => Promise) { this.userId = userId; + this.projectId = projectId; this.getter = getter; } async getById(id: any) { - return await this.getter(id, this.userId); + return await this.getter(id, this.userId, this.projectId); } async getCommonById(id: any) { - return await this.getter(id, 0); + return await this.getter(id, 0,null); } } diff --git a/packages/libs/lib-server/src/user/access/service/access-service.ts b/packages/libs/lib-server/src/user/access/service/access-service.ts index 756e72d1d..950e5f243 100644 --- a/packages/libs/lib-server/src/user/access/service/access-service.ts +++ b/packages/libs/lib-server/src/user/access/service/access-service.ts @@ -129,10 +129,11 @@ export class AccessService extends BaseService { id: entity.id, name: entity.name, userId: entity.userId, + projectId: entity.projectId, }; } - async getAccessById(id: any, checkUserId: boolean, userId?: number): Promise { + async getAccessById(id: any, checkUserId: boolean, userId?: number, projectId?: number): Promise { const entity = await this.info(id); if (entity == null) { throw new Error(`该授权配置不存在,请确认是否已被删除:id=${id}`); @@ -145,6 +146,9 @@ export class AccessService extends BaseService { throw new PermissionException('您对该Access授权无访问权限'); } } + if (projectId != null && projectId !== entity.projectId) { + throw new PermissionException('您对该Access授权无访问权限'); + } // const access = accessRegistry.get(entity.type); const setting = this.decryptAccessEntity(entity); @@ -152,12 +156,12 @@ export class AccessService extends BaseService { id: entity.id, ...setting, }; - const accessGetter = new AccessGetter(userId, this.getById.bind(this)); + const accessGetter = new AccessGetter(userId,projectId, this.getById.bind(this)); return await newAccess(entity.type, input,accessGetter); } - async getById(id: any, userId: number): Promise { - return await this.getAccessById(id, true, userId); + async getById(id: any, userId: number, projectId?: number): Promise { + return await this.getAccessById(id, true, userId, projectId); } decryptAccessEntity(entity: AccessEntity): any { @@ -188,7 +192,7 @@ export class AccessService extends BaseService { } - async getSimpleByIds(ids: number[], userId: any) { + async getSimpleByIds(ids: number[], userId: any, projectId?: number) { if (ids.length === 0) { return []; } @@ -199,12 +203,14 @@ export class AccessService extends BaseService { where: { id: In(ids), userId, + projectId, }, select: { id: true, name: true, type: true, - userId:true + userId:true, + projectId:true, }, }); diff --git a/packages/libs/lib-server/src/user/addon/service/addon-service.ts b/packages/libs/lib-server/src/user/addon/service/addon-service.ts index 55928d9bf..c152d2fad 100644 --- a/packages/libs/lib-server/src/user/addon/service/addon-service.ts +++ b/packages/libs/lib-server/src/user/addon/service/addon-service.ts @@ -70,7 +70,8 @@ export class AddonService extends BaseService { name: entity.name, userId: entity.userId, addonType: entity.addonType, - type: entity.type + type: entity.type, + projectId: entity.projectId }; } @@ -84,7 +85,7 @@ export class AddonService extends BaseService { } - async getSimpleByIds(ids: number[], userId: any) { + async getSimpleByIds(ids: number[], userId: any,projectId?:number) { if (ids.length === 0) { return []; } @@ -94,7 +95,8 @@ export class AddonService extends BaseService { return await this.repository.find({ where: { id: In(ids), - userId + userId, + projectId }, select: { id: true, @@ -109,11 +111,12 @@ export class AddonService extends BaseService { } - async getDefault(userId: number, addonType: string): Promise { + async getDefault(userId: number, addonType: string,projectId?:number): Promise { const res = await this.repository.findOne({ where: { userId, - addonType + addonType, + projectId }, order: { isDefault: "DESC" @@ -133,11 +136,12 @@ export class AddonService extends BaseService { type: res.type, name: res.name, userId: res.userId, - setting + setting, + projectId: res.projectId }; } - async setDefault(id: number, userId: number, addonType: string) { + async setDefault(id: number, userId: number, addonType: string,projectId?:number) { if (!id) { throw new ValidateException("id不能为空"); } @@ -147,7 +151,8 @@ export class AddonService extends BaseService { await this.repository.update( { userId, - addonType + addonType, + projectId }, { isDefault: false @@ -157,7 +162,8 @@ export class AddonService extends BaseService { { id, userId, - addonType + addonType, + projectId }, { isDefault: true @@ -165,12 +171,12 @@ export class AddonService extends BaseService { ); } - async getOrCreateDefault(opts: { addonType: string, type: string, inputs: any, userId: any }) { - const { addonType, type, inputs, userId } = opts; + async getOrCreateDefault(opts: { addonType: string, type: string, inputs: any, userId: any,projectId?:number }) { + const { addonType, type, inputs, userId,projectId } = opts; const addonDefine = this.getDefineByType(type, addonType); - const defaultConfig = await this.getDefault(userId, addonType); + const defaultConfig = await this.getDefault(userId, addonType,projectId); if (defaultConfig) { return defaultConfig; } @@ -183,17 +189,19 @@ export class AddonService extends BaseService { type: type, name: addonDefine.title, setting: JSON.stringify(setting), - isDefault: true + isDefault: true, + projectId }); return this.buildAddonInstanceConfig(res); } - async getOneByType(req:{addonType:string,type:string,userId:number}) { + async getOneByType(req:{addonType:string,type:string,userId:number,projectId?:number}) { return await this.repository.findOne({ where: { addonType: req.addonType, type: req.type, - userId: req.userId + userId: req.userId, + projectId: req.projectId } }); } diff --git a/packages/ui/certd-client/src/components/project-selector/index.vue b/packages/ui/certd-client/src/components/project-selector/index.vue index 9b7805f36..dfac42954 100644 --- a/packages/ui/certd-client/src/components/project-selector/index.vue +++ b/packages/ui/certd-client/src/components/project-selector/index.vue @@ -7,9 +7,9 @@ -
+
- {{ projectStore.currentProject?.name || "..." }} + 当前项目:{{ projectStore.currentProject?.name || "..." }}
@@ -34,8 +34,8 @@ function handleMenuClick({ key }: any) {