mirror of
https://github.com/certd/certd.git
synced 2026-05-15 20:47:31 +08:00
chore: project query
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {Inject, Provide, Scope, ScopeEnum} from "@midwayjs/core";
|
||||
import {BaseService, NeedSuiteException, NeedVIPException, SysSettingsService} from "@certd/lib-server";
|
||||
import {InjectEntityModel} from "@midwayjs/typeorm";
|
||||
import {Repository} from "typeorm";
|
||||
import {In, Repository} from "typeorm";
|
||||
import {SiteInfoEntity} from "../entity/site-info.js";
|
||||
import {siteTester} from "./site-tester.js";
|
||||
import dayjs from "dayjs";
|
||||
@@ -344,12 +344,12 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
async checkAllByUsers(userId: any) {
|
||||
async checkAllByUsers(userId: any,projectId?: number) {
|
||||
if (!userId) {
|
||||
throw new Error("userId is required");
|
||||
}
|
||||
const sites = await this.repository.find({
|
||||
where: {userId}
|
||||
where: {userId,projectId}
|
||||
});
|
||||
this.checkList(sites,false);
|
||||
}
|
||||
@@ -418,7 +418,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
async doImport(req: { text: string; userId: number,groupId?:number }) {
|
||||
async doImport(req: { text: string; userId: number,groupId?:number,projectId?:number }) {
|
||||
if (!req.text) {
|
||||
throw new Error("text is required");
|
||||
}
|
||||
@@ -461,7 +461,8 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
httpsPort: port,
|
||||
userId: req.userId,
|
||||
remark,
|
||||
groupId: req.groupId
|
||||
groupId: req.groupId,
|
||||
projectId: req.projectId
|
||||
});
|
||||
}
|
||||
|
||||
@@ -537,4 +538,12 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
||||
|
||||
logger.info(`站点证书检查完成[${userId??'所有用户'}]`);
|
||||
}
|
||||
|
||||
async batchDelete(ids: number[], userId: number,projectId?:number): Promise<void> {
|
||||
await this.repository.delete({
|
||||
id: In(ids),
|
||||
userId,
|
||||
projectId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
||||
})
|
||||
}
|
||||
|
||||
async doImport(req: { text: string; userId:number, siteId:number }) {
|
||||
async doImport(req: { text: string; userId:number, siteId:number,projectId?:number }) {
|
||||
if (!req.text) {
|
||||
throw new Error("text is required");
|
||||
}
|
||||
@@ -289,7 +289,8 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
||||
const siteEntity = await this.siteInfoRepository.findOne({
|
||||
where: {
|
||||
id: req.siteId,
|
||||
userId:req.userId
|
||||
userId:req.userId,
|
||||
projectId:req.projectId
|
||||
}
|
||||
});
|
||||
if (!siteEntity) {
|
||||
@@ -311,6 +312,7 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
||||
siteId: req.siteId,
|
||||
from: "import",
|
||||
disabled:false,
|
||||
projectId: req.projectId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -756,6 +756,9 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
id: pipelineId,
|
||||
},
|
||||
});
|
||||
if(!pipelineEntity){
|
||||
return null
|
||||
}
|
||||
return pipelineEntity.projectId;
|
||||
}
|
||||
private async saveHistory(history: RunHistory) {
|
||||
|
||||
@@ -67,7 +67,7 @@ export class TemplateService extends BaseService<TemplateEntity> {
|
||||
|
||||
}
|
||||
|
||||
async detail(id: number, userId: number) {
|
||||
async detail(id: number, userId: number,projectId?:number) {
|
||||
const info = await this.info(id)
|
||||
if (!info) {
|
||||
throw new Error('模板不存在');
|
||||
@@ -75,6 +75,9 @@ export class TemplateService extends BaseService<TemplateEntity> {
|
||||
if (info.userId !== userId) {
|
||||
throw new Error('无权限');
|
||||
}
|
||||
if (projectId && info.projectId !== projectId) {
|
||||
throw new Error('无权限');
|
||||
}
|
||||
let pipeline = null
|
||||
if (info.pipelineId) {
|
||||
const pipelineEntity = await this.pipelineService.info(info.pipelineId);
|
||||
@@ -88,19 +91,22 @@ export class TemplateService extends BaseService<TemplateEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
async batchDelete(ids: number[], userId: number) {
|
||||
async batchDelete(ids: number[], userId: number,projectId?:number) {
|
||||
|
||||
const where: any = {
|
||||
id: In(ids),
|
||||
}
|
||||
if (userId > 0) {
|
||||
if (userId != null) {
|
||||
where.userId = userId
|
||||
}
|
||||
if (projectId) {
|
||||
where.projectId = projectId
|
||||
}
|
||||
const list = await this.getRepository().find({where})
|
||||
ids = list.map(item => item.id)
|
||||
const pipelineIds = list.map(item => item.pipelineId)
|
||||
await this.delete(ids);
|
||||
await this.pipelineService.batchDelete(pipelineIds, userId)
|
||||
await this.pipelineService.batchDelete(pipelineIds, userId, projectId)
|
||||
}
|
||||
|
||||
async createPipelineByTemplate(body: PipelineEntity) {
|
||||
|
||||
@@ -28,7 +28,7 @@ export class AuthService {
|
||||
}
|
||||
|
||||
//管理员有权限查看其他用户的数据
|
||||
async checkEntityUserId(ctx: any, service: any, ids: number| number[] = null, userKey = 'userId') {
|
||||
async checkUserIdButAllowAdmin(ctx: any, service: any, ids: number| number[] = null, userKey = 'userId') {
|
||||
const isAdmin = await this.isAdmin(ctx);
|
||||
if (isAdmin) {
|
||||
return true;
|
||||
@@ -36,7 +36,11 @@ export class AuthService {
|
||||
await service.checkUserId(ids, ctx.user.id, userKey);
|
||||
}
|
||||
|
||||
async checkEntityProjectId(service:any,ids:number| number[] = null,projectId = null){
|
||||
async checkProjectId(service:any,ids:number| number[] = null,projectId = null){
|
||||
await service.checkUserId(ids, projectId , "projectId");
|
||||
}
|
||||
|
||||
async checkUserId(service:any,ids:number| number[] = null,userId = null){
|
||||
await service.checkUserId(ids, userId , "userId");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user