2024-07-15 00:30:33 +08:00
|
|
|
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
2024-10-09 02:34:28 +08:00
|
|
|
import { Constants, CrudController, SysSettingsService } from '@certd/lib-server';
|
2025-01-15 01:26:39 +08:00
|
|
|
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
|
|
|
|
|
import { PipelineEntity } from '../../../modules/pipeline/entity/pipeline.js';
|
|
|
|
|
import { HistoryService } from '../../../modules/pipeline/service/history-service.js';
|
|
|
|
|
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
2025-10-24 23:10:20 +08:00
|
|
|
import { SiteInfoService } from '../../../modules/monitor/index.js';
|
|
|
|
|
import { isPlus } from '@certd/plus-core';
|
2023-01-29 13:44:19 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 证书
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
|
|
|
|
@Controller('/api/pi/pipeline')
|
2023-05-23 18:01:20 +08:00
|
|
|
export class PipelineController extends CrudController<PipelineService> {
|
2023-01-29 13:44:19 +08:00
|
|
|
@Inject()
|
|
|
|
|
service: PipelineService;
|
2023-07-03 11:45:32 +08:00
|
|
|
@Inject()
|
|
|
|
|
historyService: HistoryService;
|
2024-08-05 12:49:44 +08:00
|
|
|
@Inject()
|
|
|
|
|
authService: AuthService;
|
|
|
|
|
@Inject()
|
|
|
|
|
sysSettingsService: SysSettingsService;
|
2023-01-29 13:44:19 +08:00
|
|
|
|
2025-10-24 23:10:20 +08:00
|
|
|
@Inject()
|
|
|
|
|
siteInfoService: SiteInfoService;
|
|
|
|
|
|
2023-01-29 13:44:19 +08:00
|
|
|
getService() {
|
|
|
|
|
return this.service;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/page', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async page(@Body(ALL) body) {
|
2024-08-05 12:49:44 +08:00
|
|
|
const isAdmin = await this.authService.isAdmin(this.ctx);
|
|
|
|
|
const publicSettings = await this.sysSettingsService.getPublicSettings();
|
|
|
|
|
if (!(publicSettings.managerOtherUserPipeline && isAdmin)) {
|
2024-10-10 02:15:05 +08:00
|
|
|
body.query.userId = this.getUserId();
|
2024-08-05 12:49:44 +08:00
|
|
|
}
|
2024-08-04 02:35:45 +08:00
|
|
|
|
|
|
|
|
const title = body.query.title;
|
|
|
|
|
delete body.query.title;
|
|
|
|
|
|
2023-01-29 13:44:19 +08:00
|
|
|
const buildQuery = qb => {
|
2024-08-04 02:35:45 +08:00
|
|
|
if (title) {
|
2024-11-20 10:46:05 +08:00
|
|
|
qb.andWhere('(title like :title or content like :content)', { title: `%${title}%`, content: `%${title}%` });
|
2024-08-04 02:35:45 +08:00
|
|
|
}
|
2023-01-29 13:44:19 +08:00
|
|
|
};
|
2024-08-04 02:35:45 +08:00
|
|
|
if (!body.sort || !body.sort?.prop) {
|
|
|
|
|
body.sort = { prop: 'order', asc: false };
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-14 00:19:55 +08:00
|
|
|
const pageRet = await this.getService().page({
|
|
|
|
|
query: body.query,
|
|
|
|
|
page: body.page,
|
2024-10-14 14:00:24 +08:00
|
|
|
sort: body.sort,
|
2024-10-14 00:19:55 +08:00
|
|
|
buildQuery,
|
|
|
|
|
});
|
2024-08-06 10:12:02 +08:00
|
|
|
return this.ok(pageRet);
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-23 18:20:49 +08:00
|
|
|
@Post('/getSimpleByIds', { summary: Constants.per.authOnly })
|
|
|
|
|
async getSimpleById(@Body(ALL) body) {
|
|
|
|
|
const ret = await this.getService().getSimplePipelines(body.ids,this.getUserId() );
|
|
|
|
|
return this.ok(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/add', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async add(@Body(ALL) bean: PipelineEntity) {
|
2024-10-10 02:15:05 +08:00
|
|
|
bean.userId = this.getUserId();
|
2023-01-29 13:44:19 +08:00
|
|
|
return super.add(bean);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/update', { summary: Constants.per.authOnly })
|
2023-01-29 13:44:19 +08:00
|
|
|
async update(@Body(ALL) bean) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
|
2024-12-01 02:10:40 +08:00
|
|
|
delete bean.userId;
|
2023-01-29 13:44:19 +08:00
|
|
|
return super.update(bean);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/save', { summary: Constants.per.authOnly })
|
2025-10-24 23:10:20 +08:00
|
|
|
async save(@Body(ALL) bean: {addToMonitorEnabled: boolean, addToMonitorDomains: string} & PipelineEntity) {
|
2023-01-29 13:44:19 +08:00
|
|
|
if (bean.id > 0) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), bean.id);
|
2024-10-10 14:57:26 +08:00
|
|
|
} else {
|
|
|
|
|
bean.userId = this.getUserId();
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|
2025-10-24 23:48:32 +08:00
|
|
|
|
|
|
|
|
if(!this.isAdmin()){
|
|
|
|
|
// 非管理员用户 不允许设置流水线有效期
|
|
|
|
|
delete bean.validTime
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 01:15:05 +08:00
|
|
|
const {version} = await this.service.save(bean);
|
2025-10-24 23:10:20 +08:00
|
|
|
//是否增加证书监控
|
|
|
|
|
if (bean.addToMonitorEnabled && bean.addToMonitorDomains) {
|
|
|
|
|
const sysPublicSettings = await this.sysSettingsService.getPublicSettings();
|
|
|
|
|
if (isPlus() && sysPublicSettings.certDomainAddToMonitorEnabled) {
|
|
|
|
|
//增加证书监控
|
|
|
|
|
await this.siteInfoService.doImport({
|
|
|
|
|
text: bean.addToMonitorDomains,
|
|
|
|
|
userId: this.getUserId(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-07 01:15:05 +08:00
|
|
|
return this.ok({id:bean.id,version:version});
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/delete', { summary: Constants.per.authOnly })
|
2024-08-30 18:50:53 +08:00
|
|
|
async delete(@Query('id') id: number) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
|
2023-06-28 12:46:29 +08:00
|
|
|
await this.service.delete(id);
|
|
|
|
|
return this.ok({});
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/detail', { summary: Constants.per.authOnly })
|
2024-08-30 18:50:53 +08:00
|
|
|
async detail(@Query('id') id: number) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
|
2023-01-29 13:44:19 +08:00
|
|
|
const detail = await this.service.detail(id);
|
|
|
|
|
return this.ok(detail);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/trigger', { summary: Constants.per.authOnly })
|
2024-09-02 18:36:12 +08:00
|
|
|
async trigger(@Query('id') id: number, @Query('stepId') stepId?: string) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.getService(), id);
|
2025-10-23 00:36:20 +08:00
|
|
|
await this.service.trigger(id, stepId,true);
|
2023-01-29 13:44:19 +08:00
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2023-07-03 11:45:32 +08:00
|
|
|
|
|
|
|
|
@Post('/cancel', { summary: Constants.per.authOnly })
|
2024-08-30 18:50:53 +08:00
|
|
|
async cancel(@Query('historyId') historyId: number) {
|
2024-08-05 12:49:44 +08:00
|
|
|
await this.authService.checkEntityUserId(this.ctx, this.historyService, historyId);
|
2023-07-03 11:45:32 +08:00
|
|
|
await this.service.cancel(historyId);
|
|
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2024-10-31 22:35:05 +08:00
|
|
|
|
|
|
|
|
@Post('/count', { summary: Constants.per.authOnly })
|
|
|
|
|
async count() {
|
|
|
|
|
const count = await this.service.count({ userId: this.getUserId() });
|
|
|
|
|
return this.ok({ count });
|
|
|
|
|
}
|
2024-12-01 02:10:40 +08:00
|
|
|
|
|
|
|
|
@Post('/batchDelete', { summary: Constants.per.authOnly })
|
|
|
|
|
async batchDelete(@Body('ids') ids: number[]) {
|
|
|
|
|
await this.service.batchDelete(ids, this.getUserId());
|
|
|
|
|
return this.ok({});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('/batchUpdateGroup', { summary: Constants.per.authOnly })
|
|
|
|
|
async batchUpdateGroup(@Body('ids') ids: number[], @Body('groupId') groupId: number) {
|
|
|
|
|
await this.service.batchUpdateGroup(ids, groupId, this.getUserId());
|
|
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2025-05-27 11:08:08 +08:00
|
|
|
|
2025-06-18 12:29:43 +08:00
|
|
|
|
|
|
|
|
@Post('/batchUpdateTrigger', { summary: Constants.per.authOnly })
|
|
|
|
|
async batchUpdateTrigger(@Body('ids') ids: number[], @Body('trigger') trigger: any) {
|
|
|
|
|
await this.service.batchUpdateTrigger(ids, trigger, this.getUserId());
|
|
|
|
|
return this.ok({});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('/batchUpdateNotification', { summary: Constants.per.authOnly })
|
|
|
|
|
async batchUpdateNotification(@Body('ids') ids: number[], @Body('notification') notification: any) {
|
|
|
|
|
await this.service.batchUpdateNotifications(ids, notification, this.getUserId());
|
|
|
|
|
return this.ok({});
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-27 11:08:08 +08:00
|
|
|
@Post('/batchRerun', { summary: Constants.per.authOnly })
|
|
|
|
|
async batchRerun(@Body('ids') ids: number[]) {
|
|
|
|
|
await this.service.batchRerun(ids, this.getUserId());
|
|
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|