mirror of
https://github.com/certd/certd.git
synced 2026-07-15 02:07:38 +08:00
chore: format
This commit is contained in:
@@ -1,13 +1,5 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import {
|
||||
AddonDefine,
|
||||
AddonRequestHandleReq,
|
||||
AddonService,
|
||||
Constants,
|
||||
CrudController,
|
||||
newAddon,
|
||||
ValidateException
|
||||
} from "@certd/lib-server";
|
||||
import { AddonDefine, AddonRequestHandleReq, AddonService, Constants, CrudController, newAddon, ValidateException } from "@certd/lib-server";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { checkPlus } from "@certd/plus-core";
|
||||
import { http, logger, utils } from "@certd/basic";
|
||||
@@ -19,14 +11,14 @@ import { ApiTags } from "@midwayjs/swagger";
|
||||
*/
|
||||
@Provide()
|
||||
@Controller("/api/addon")
|
||||
@ApiTags(['addon'])
|
||||
@ApiTags(["addon"])
|
||||
export class AddonController extends CrudController<AddonService> {
|
||||
@Inject()
|
||||
service: AddonService;
|
||||
@Inject()
|
||||
authService: AuthService;
|
||||
@Inject()
|
||||
taskServiceBuilder:TaskServiceBuilder
|
||||
taskServiceBuilder: TaskServiceBuilder;
|
||||
|
||||
getService(): AddonService {
|
||||
return this.service;
|
||||
@@ -34,7 +26,7 @@ export class AddonController extends CrudController<AddonService> {
|
||||
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询Addon分页列表" })
|
||||
async page(@Body(ALL) body) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
delete body.query.userId;
|
||||
body.query.projectId = projectId;
|
||||
@@ -45,14 +37,14 @@ export class AddonController extends CrudController<AddonService> {
|
||||
query: body.query,
|
||||
page: body.page,
|
||||
sort: body.sort,
|
||||
buildQuery
|
||||
buildQuery,
|
||||
});
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询Addon列表" })
|
||||
async list(@Body(ALL) body) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId;
|
||||
@@ -61,7 +53,7 @@ export class AddonController extends CrudController<AddonService> {
|
||||
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加Addon" })
|
||||
async add(@Body(ALL) bean) {
|
||||
const {userId,projectId} = await this.getProjectUserIdRead();
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId;
|
||||
const type = bean.type;
|
||||
@@ -129,7 +121,7 @@ export class AddonController extends CrudController<AddonService> {
|
||||
value: item.name,
|
||||
label: item.title,
|
||||
needPlus: item.needPlus ?? false,
|
||||
icon: item.icon
|
||||
icon: item.icon,
|
||||
});
|
||||
}
|
||||
dict = dict.sort(a => {
|
||||
@@ -142,43 +134,42 @@ export class AddonController extends CrudController<AddonService> {
|
||||
async simpleInfo(@Query("addonType") addonType: string, @Query("id") id: number) {
|
||||
if (id === 0) {
|
||||
//获取默认
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getDefault(userId, addonType,projectId);
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getDefault(userId, addonType, projectId);
|
||||
if (!res) {
|
||||
throw new ValidateException("默认Addon配置不存在");
|
||||
}
|
||||
const simple = await this.service.getSimpleInfo(res.id);
|
||||
return this.ok(simple);
|
||||
}
|
||||
await this.checkOwner(this.getService(), id, "read",true);
|
||||
await this.checkOwner(this.getService(), id, "read", true);
|
||||
const res = await this.service.getSimpleInfo(id);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post("/getDefaultId", { description: Constants.per.authOnly, summary: "查询Addon插件默认配置ID" })
|
||||
async getDefaultId(@Query("addonType") addonType: string) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getDefault(userId, addonType,projectId);
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getDefault(userId, addonType, projectId);
|
||||
return this.ok(res?.id);
|
||||
}
|
||||
|
||||
@Post("/setDefault", { description: Constants.per.authOnly, summary: "设置Addon插件默认配置" })
|
||||
async setDefault(@Query("addonType") addonType: string, @Query("id") id: number) {
|
||||
const {projectId,userId} = await this.checkOwner(this.getService(), id, "write",true);
|
||||
const res = await this.service.setDefault(id, userId, addonType,projectId);
|
||||
const { projectId, userId } = await this.checkOwner(this.getService(), id, "write", true);
|
||||
const res = await this.service.setDefault(id, userId, addonType, projectId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
|
||||
@Post("/options", { description: Constants.per.authOnly, summary: "查询Addon插件配置字典" })
|
||||
async options(@Query("addonType") addonType: string) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const res = await this.service.list({
|
||||
query: {
|
||||
userId,
|
||||
addonType,
|
||||
projectId
|
||||
}
|
||||
projectId,
|
||||
},
|
||||
});
|
||||
for (const item of res) {
|
||||
delete item.setting;
|
||||
@@ -186,25 +177,24 @@ export class AddonController extends CrudController<AddonService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
|
||||
@Post("/handle", { description: Constants.per.authOnly, summary: "Addon插件处理请求" })
|
||||
async handle(@Body(ALL) body: AddonRequestHandleReq) {
|
||||
let inputAddon = body.input.addon;
|
||||
if (body.input.id > 0) {
|
||||
await this.checkOwner(this.getService(), body.input.id, "write",true);
|
||||
await this.checkOwner(this.getService(), body.input.id, "write", true);
|
||||
const oldEntity = await this.service.info(body.input.id);
|
||||
if (oldEntity) {
|
||||
inputAddon = JSON.parse(oldEntity.setting);
|
||||
}
|
||||
}
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const serviceGetter = this.taskServiceBuilder.create({ userId,projectId });
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const serviceGetter = this.taskServiceBuilder.create({ userId, projectId });
|
||||
|
||||
const ctx = {
|
||||
http: http,
|
||||
logger: logger,
|
||||
utils: utils,
|
||||
serviceGetter
|
||||
serviceGetter,
|
||||
};
|
||||
const addon = await newAddon(body.addonType, body.typeName, inputAddon, ctx);
|
||||
const res = await addon.onRequest(body);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { Constants, CrudController } from '@certd/lib-server';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { GroupService } from '../../../modules/basic/service/group-service.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Constants, CrudController } from "@certd/lib-server";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { GroupService } from "../../../modules/basic/service/group-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 通知
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/basic/group')
|
||||
@ApiTags(['basic-group'])
|
||||
@Controller("/api/basic/group")
|
||||
@ApiTags(["basic-group"])
|
||||
export class GroupController extends CrudController<GroupService> {
|
||||
@Inject()
|
||||
service: GroupService;
|
||||
@@ -20,14 +20,14 @@ export class GroupController extends CrudController<GroupService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询分组分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询分组分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.projectId = projectId;
|
||||
delete body.query.userId;
|
||||
const buildQuery = qb => {
|
||||
qb.andWhere('user_id = :userId', { userId });
|
||||
qb.andWhere("user_id = :userId", { userId });
|
||||
};
|
||||
const res = await this.service.page({
|
||||
query: body.query,
|
||||
@@ -38,45 +38,45 @@ export class GroupController extends CrudController<GroupService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询分组列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询分组列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.projectId = projectId;
|
||||
body.query.userId = userId;
|
||||
return await super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加分组" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加分组" })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
bean.projectId = projectId;
|
||||
bean.userId = userId;
|
||||
return await super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新分组" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新分组" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.getService(), bean.id, "write");
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
return await super.update(bean);
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询分组详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询分组详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read");
|
||||
return await super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除分组" })
|
||||
async delete(@Query('id') id: number) {
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除分组" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
return await super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/all', { description: Constants.per.authOnly, summary: "查询所有分组" })
|
||||
async all(@Query('type') type: string) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有分组" })
|
||||
async all(@Query("type") type: string) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const list: any = await this.service.find({
|
||||
where: {
|
||||
projectId,
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
import { Constants, isEnterprise } from '@certd/lib-server';
|
||||
import { Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { In } from 'typeorm';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { UserService } from '../../../modules/sys/authority/service/user-service.js';
|
||||
import { BasicController } from '../../basic/code-controller.js';
|
||||
import { RoleService } from '../../../modules/sys/authority/service/role-service.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { Constants, isEnterprise } from "@certd/lib-server";
|
||||
import { Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
||||
import { In } from "typeorm";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { UserService } from "../../../modules/sys/authority/service/user-service.js";
|
||||
import { BasicController } from "../../basic/code-controller.js";
|
||||
import { RoleService } from "../../../modules/sys/authority/service/role-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 通知
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/basic/user')
|
||||
@ApiTags(['basic-user'])
|
||||
@Controller("/api/basic/user")
|
||||
@ApiTags(["basic-user"])
|
||||
export class BasicUserController extends BasicController {
|
||||
@Inject()
|
||||
service: UserService;
|
||||
@Inject()
|
||||
authService: AuthService;
|
||||
@Inject()
|
||||
@Inject()
|
||||
roleService: RoleService;
|
||||
|
||||
getService(): UserService {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/getSimpleUserByIds', { description: Constants.per.authOnly, summary: "根据ID列表获取用户简单信息" })
|
||||
async getSimpleUserByIds(@Body('ids') ids: number[]) {
|
||||
if(!isEnterprise()){
|
||||
throw new Error('非企业模式不能获取用户信息');
|
||||
@Post("/getSimpleUserByIds", { description: Constants.per.authOnly, summary: "根据ID列表获取用户简单信息" })
|
||||
async getSimpleUserByIds(@Body("ids") ids: number[]) {
|
||||
if (!isEnterprise()) {
|
||||
throw new Error("非企业模式不能获取用户信息");
|
||||
}
|
||||
const users = await this.service.find({
|
||||
select: {
|
||||
@@ -45,10 +45,10 @@ export class BasicUserController extends BasicController {
|
||||
return this.ok(users);
|
||||
}
|
||||
|
||||
@Post('/getSimpleUsers', {description: Constants.per.authOnly, summary: "获取所有用户简单信息"})
|
||||
@Post("/getSimpleUsers", { description: Constants.per.authOnly, summary: "获取所有用户简单信息" })
|
||||
async getSimpleUsers() {
|
||||
if(!isEnterprise()){
|
||||
throw new Error('非企业模式不能获取所有用户信息');
|
||||
if (!isEnterprise()) {
|
||||
throw new Error("非企业模式不能获取所有用户信息");
|
||||
}
|
||||
const users = await this.service.find({
|
||||
select: {
|
||||
@@ -62,7 +62,7 @@ export class BasicUserController extends BasicController {
|
||||
return this.ok(users);
|
||||
}
|
||||
|
||||
@Post('/getSimpleRoles', {description: Constants.per.authOnly, summary: "获取所有角色简单信息"})
|
||||
@Post("/getSimpleRoles", { description: Constants.per.authOnly, summary: "获取所有角色简单信息" })
|
||||
async getSimpleRoles() {
|
||||
const roles = await this.roleService.find({
|
||||
select: {
|
||||
@@ -72,5 +72,4 @@ export class BasicUserController extends BasicController {
|
||||
});
|
||||
return this.ok(roles);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { Constants, CrudController } from '@certd/lib-server';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Constants, CrudController } from "@certd/lib-server";
|
||||
import { DomainService } from "../../../modules/cert/service/domain-service.js";
|
||||
import { checkPlus } from '@certd/plus-core';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { parseDomainByPsl } from '@certd/plugin-lib';
|
||||
import { checkPlus } from "@certd/plus-core";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { parseDomainByPsl } from "@certd/plugin-lib";
|
||||
|
||||
/**
|
||||
* 授权
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/cert/domain')
|
||||
@ApiTags(['cert'])
|
||||
@Controller("/api/cert/domain")
|
||||
@ApiTags(["cert"])
|
||||
export class DomainController extends CrudController<DomainService> {
|
||||
@Inject()
|
||||
service: DomainService;
|
||||
@@ -19,7 +19,7 @@ export class DomainController extends CrudController<DomainService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询域名分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询域名分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
@@ -30,7 +30,7 @@ export class DomainController extends CrudController<DomainService> {
|
||||
|
||||
const bq = qb => {
|
||||
if (domain) {
|
||||
qb.andWhere('domain like :domain', { domain: `%${domain}%` });
|
||||
qb.andWhere("domain like :domain", { domain: `%${domain}%` });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -43,7 +43,7 @@ export class DomainController extends CrudController<DomainService> {
|
||||
return this.ok(pageRet);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询域名列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询域名列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
@@ -53,7 +53,7 @@ export class DomainController extends CrudController<DomainService> {
|
||||
return this.ok(list);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加域名" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加域名" })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
bean.projectId = projectId;
|
||||
@@ -61,7 +61,7 @@ export class DomainController extends CrudController<DomainService> {
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新域名" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新域名" })
|
||||
async update(@Body(ALL) bean: any) {
|
||||
await this.checkOwner(this.getService(), bean.id, "write");
|
||||
delete bean.userId;
|
||||
@@ -69,19 +69,19 @@ export class DomainController extends CrudController<DomainService> {
|
||||
return super.update(bean);
|
||||
}
|
||||
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询域名详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询域名详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read");
|
||||
return super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除域名" })
|
||||
async delete(@Query('id') id: number) {
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除域名" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/deleteByIds', { description: Constants.per.authOnly, summary: "批量删除域名" })
|
||||
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除域名" })
|
||||
async deleteByIds(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
await this.service.delete(body.ids, {
|
||||
@@ -91,8 +91,7 @@ export class DomainController extends CrudController<DomainService> {
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
|
||||
@Post('/import/start', { description: Constants.per.authOnly, summary: "开始域名导入任务" })
|
||||
@Post("/import/start", { description: Constants.per.authOnly, summary: "开始域名导入任务" })
|
||||
async importStart(@Body(ALL) body: any) {
|
||||
checkPlus();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
@@ -101,24 +100,23 @@ export class DomainController extends CrudController<DomainService> {
|
||||
key,
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
}
|
||||
};
|
||||
await this.service.startDomainImportTask(req);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/import/status', { description: Constants.per.authOnly, summary: "查询域名导入任务状态" })
|
||||
@Post("/import/status", { description: Constants.per.authOnly, summary: "查询域名导入任务状态" })
|
||||
async importStatus() {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const req = {
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
}
|
||||
};
|
||||
const task = await this.service.getDomainImportTaskStatus(req);
|
||||
return this.ok(task);
|
||||
}
|
||||
|
||||
|
||||
@Post('/import/delete', { description: Constants.per.authOnly, summary: "删除域名导入任务" })
|
||||
@Post("/import/delete", { description: Constants.per.authOnly, summary: "删除域名导入任务" })
|
||||
async importDelete(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const { key } = body;
|
||||
@@ -126,12 +124,12 @@ export class DomainController extends CrudController<DomainService> {
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
key,
|
||||
}
|
||||
};
|
||||
await this.service.deleteDomainImportTask(req);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/import/save', { description: Constants.per.authOnly, summary: "保存域名导入任务" })
|
||||
@Post("/import/save", { description: Constants.per.authOnly, summary: "保存域名导入任务" })
|
||||
async importSave(@Body(ALL) body: any) {
|
||||
checkPlus();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
@@ -139,61 +137,59 @@ export class DomainController extends CrudController<DomainService> {
|
||||
const req = {
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
dnsProviderType, dnsProviderAccessId, key
|
||||
}
|
||||
dnsProviderType,
|
||||
dnsProviderAccessId,
|
||||
key,
|
||||
};
|
||||
const item = await this.service.saveDomainImportTask(req);
|
||||
return this.ok(item);
|
||||
}
|
||||
|
||||
|
||||
@Post('/sync/expiration/start', { description: Constants.per.authOnly, summary: "开始同步域名过期时间任务" })
|
||||
@Post("/sync/expiration/start", { description: Constants.per.authOnly, summary: "开始同步域名过期时间任务" })
|
||||
async syncExpirationStart(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
await this.service.startSyncExpirationTask({
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
})
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
@Post('/sync/expiration/status', { description: Constants.per.authOnly, summary: "查询同步域名过期时间任务状态" })
|
||||
@Post("/sync/expiration/status", { description: Constants.per.authOnly, summary: "查询同步域名过期时间任务状态" })
|
||||
async syncExpirationStatus(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const status = await this.service.getSyncExpirationTaskStatus({
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
})
|
||||
});
|
||||
return this.ok(status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Post('/setting/save', { description: Constants.per.authOnly, summary: "保存域名监控设置" })
|
||||
@Post("/setting/save", { description: Constants.per.authOnly, summary: "保存域名监控设置" })
|
||||
async settingSave(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
await this.service.monitorSettingSave({
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
setting: {...body},
|
||||
})
|
||||
setting: { ...body },
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/setting/get', { description: Constants.per.authOnly, summary: "查询域名监控设置" })
|
||||
@Post("/setting/get", { description: Constants.per.authOnly, summary: "查询域名监控设置" })
|
||||
async settingGet() {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const setting = await this.service.monitorSettingGet({
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
})
|
||||
});
|
||||
return this.ok(setting);
|
||||
}
|
||||
|
||||
@Post('/isSubdomain', { description: Constants.per.authOnly, summary: "判断是否为子域名" })
|
||||
@Post("/isSubdomain", { description: Constants.per.authOnly, summary: "判断是否为子域名" })
|
||||
async isSubdomain(@Body(ALL) body: any) {
|
||||
const { domain } = body;
|
||||
const parsed = parseDomainByPsl(domain)
|
||||
const mainDomain = parsed.domain || ''
|
||||
const parsed = parseDomainByPsl(domain);
|
||||
const mainDomain = parsed.domain || "";
|
||||
return this.ok(mainDomain !== domain);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController, Constants } from '@certd/lib-server';
|
||||
import { CnameRecordService } from '../../../modules/cname/service/cname-record-service.js';
|
||||
import { CnameProviderService } from '../../../modules/cname/service/cname-provider-service.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
||||
import { BaseController, Constants } from "@certd/lib-server";
|
||||
import { CnameRecordService } from "../../../modules/cname/service/cname-record-service.js";
|
||||
import { CnameProviderService } from "../../../modules/cname/service/cname-provider-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 授权
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/cname/provider')
|
||||
@ApiTags(['pipeline-cname'])
|
||||
@Controller("/api/cname/provider")
|
||||
@ApiTags(["pipeline-cname"])
|
||||
export class CnameProviderController extends BaseController {
|
||||
@Inject()
|
||||
service: CnameRecordService;
|
||||
@@ -20,7 +20,7 @@ export class CnameProviderController extends BaseController {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询CNAME提供商列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询CNAME提供商列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const res = await this.providerService.list({});
|
||||
return this.ok(res);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { Constants, CrudController } from '@certd/lib-server';
|
||||
import { CnameRecordService } from '../../../modules/cname/service/cname-record-service.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Constants, CrudController } from "@certd/lib-server";
|
||||
import { CnameRecordService } from "../../../modules/cname/service/cname-record-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 授权
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/cname/record')
|
||||
@ApiTags(['pipeline-cname'])
|
||||
@Controller("/api/cname/record")
|
||||
@ApiTags(["pipeline-cname"])
|
||||
export class CnameRecordController extends CrudController<CnameRecordService> {
|
||||
@Inject()
|
||||
service: CnameRecordService;
|
||||
@@ -17,9 +17,9 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询CNAME记录分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询CNAME记录分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const {userId,projectId} = await this.getProjectUserIdRead();
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId;
|
||||
@@ -28,7 +28,7 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
||||
|
||||
const bq = qb => {
|
||||
if (domain) {
|
||||
qb.andWhere('domain like :domain', { domain: `%${domain}%` });
|
||||
qb.andWhere("domain like :domain", { domain: `%${domain}%` });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -41,9 +41,9 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
||||
return this.ok(pageRet);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询CNAME记录列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询CNAME记录列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const {userId,projectId} = await this.getProjectUserIdRead();
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId;
|
||||
@@ -51,15 +51,15 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
||||
return this.ok(list);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加CNAME记录" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加CNAME记录" })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
const {userId,projectId} = await this.getProjectUserIdWrite();
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId;
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新CNAME记录" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新CNAME记录" })
|
||||
async update(@Body(ALL) bean: any) {
|
||||
await this.checkOwner(this.getService(), bean.id, "write");
|
||||
delete bean.userId;
|
||||
@@ -67,50 +67,50 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
||||
return super.update(bean);
|
||||
}
|
||||
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询CNAME记录详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询CNAME记录详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read");
|
||||
return super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除CNAME记录" })
|
||||
async delete(@Query('id') id: number) {
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除CNAME记录" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/deleteByIds', { description: Constants.per.authOnly, summary: "批量删除CNAME记录" })
|
||||
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除CNAME记录" })
|
||||
async deleteByIds(@Body(ALL) body: any) {
|
||||
const {userId,projectId} = await this.getProjectUserIdWrite();
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
await this.service.delete(body.ids, {
|
||||
userId,
|
||||
projectId,
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
@Post('/getByDomain', { description: Constants.per.authOnly, summary: "根据域名获取CNAME记录" })
|
||||
@Post("/getByDomain", { description: Constants.per.authOnly, summary: "根据域名获取CNAME记录" })
|
||||
async getByDomain(@Body(ALL) body: { domain: string; createOnNotFound: boolean }) {
|
||||
const {userId,projectId} = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getByDomain(body.domain, userId,projectId, body.createOnNotFound);
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getByDomain(body.domain, userId, projectId, body.createOnNotFound);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/verify', { description: Constants.per.authOnly, summary: "验证CNAME记录" })
|
||||
@Post("/verify", { description: Constants.per.authOnly, summary: "验证CNAME记录" })
|
||||
async verify(@Body(ALL) body: { id: number }) {
|
||||
await this.checkOwner(this.getService(), body.id, "read");
|
||||
const res = await this.service.verify(body.id);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/resetStatus', { description: Constants.per.authOnly, summary: "重置CNAME记录状态" })
|
||||
@Post("/resetStatus", { description: Constants.per.authOnly, summary: "重置CNAME记录状态" })
|
||||
async resetStatus(@Body(ALL) body: { id: number }) {
|
||||
await this.checkOwner(this.getService(), body.id, "read");
|
||||
const res = await this.service.resetStatus(body.id);
|
||||
return this.ok(res);
|
||||
}
|
||||
@Post('/import', { description: Constants.per.authOnly, summary: "导入CNAME记录" })
|
||||
@Post("/import", { description: Constants.per.authOnly, summary: "导入CNAME记录" })
|
||||
async import(@Body(ALL) body: { domainList: string; cnameProviderId: any }) {
|
||||
const {userId,projectId} = await this.getProjectUserIdWrite();
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
const res = await this.service.doImport({
|
||||
userId,
|
||||
projectId,
|
||||
@@ -119,5 +119,4 @@ export class CnameRecordController extends CrudController<CnameRecordService> {
|
||||
});
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController, Constants } from '@certd/lib-server';
|
||||
import { UserService } from '../../../modules/sys/authority/service/user-service.js';
|
||||
import { RoleService } from '../../../modules/sys/authority/service/role-service.js';
|
||||
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
|
||||
import { HistoryService } from '../../../modules/pipeline/service/history-service.js';
|
||||
import { CertInfoService } from '../../../modules/monitor/index.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { Controller, Inject, Post, Provide } from "@midwayjs/core";
|
||||
import { BaseController, Constants } from "@certd/lib-server";
|
||||
import { UserService } from "../../../modules/sys/authority/service/user-service.js";
|
||||
import { RoleService } from "../../../modules/sys/authority/service/role-service.js";
|
||||
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
|
||||
import { HistoryService } from "../../../modules/pipeline/service/history-service.js";
|
||||
import { CertInfoService } from "../../../modules/monitor/index.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
export type ChartItem = {
|
||||
name: string;
|
||||
@@ -30,8 +30,8 @@ export type UserStatisticCount = {
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/statistic/')
|
||||
@ApiTags(['dashboard'])
|
||||
@Controller("/api/statistic/")
|
||||
@ApiTags(["dashboard"])
|
||||
export class StatisticController extends BaseController {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
@@ -46,17 +46,17 @@ export class StatisticController extends BaseController {
|
||||
@Inject()
|
||||
certInfoService: CertInfoService;
|
||||
|
||||
@Post('/count', { description: Constants.per.authOnly, summary: "查询仪表盘统计数据" })
|
||||
@Post("/count", { description: Constants.per.authOnly, summary: "查询仪表盘统计数据" })
|
||||
public async count() {
|
||||
const {userId,projectId} = await this.getProjectUserIdRead();
|
||||
const pipelineCount = await this.pipelineService.count({ userId,projectId });
|
||||
const pipelineStatusCount = await this.pipelineService.statusCount({ userId,projectId });
|
||||
const pipelineEnableCount = await this.pipelineService.enableCount({ userId,projectId });
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
const pipelineCount = await this.pipelineService.count({ userId, projectId });
|
||||
const pipelineStatusCount = await this.pipelineService.statusCount({ userId, projectId });
|
||||
const pipelineEnableCount = await this.pipelineService.enableCount({ userId, projectId });
|
||||
|
||||
const historyCount = await this.historyService.countPerDay({ userId,projectId, days: 7 });
|
||||
const expiringList = await this.pipelineService.latestExpiringList({ userId,projectId, count: 5 });
|
||||
const historyCount = await this.historyService.countPerDay({ userId, projectId, days: 7 });
|
||||
const expiringList = await this.pipelineService.latestExpiringList({ userId, projectId, count: 5 });
|
||||
|
||||
const certCount = await this.certInfoService.count({ userId,projectId });
|
||||
const certCount = await this.certInfoService.count({ userId, projectId });
|
||||
|
||||
const count: UserStatisticCount = {
|
||||
pipelineCount,
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { BaseController, Constants } from '@certd/lib-server';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { ProjectService } from '../../../modules/sys/enterprise/service/project-service.js';
|
||||
import { ProjectMemberService } from '../../../modules/sys/enterprise/service/project-member-service.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { BaseController, Constants } from "@certd/lib-server";
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { ProjectService } from "../../../modules/sys/enterprise/service/project-service.js";
|
||||
import { ProjectMemberService } from "../../../modules/sys/enterprise/service/project-member-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/enterprise/project')
|
||||
@ApiTags(['enterprise-project'])
|
||||
@Controller("/api/enterprise/project")
|
||||
@ApiTags(["enterprise-project"])
|
||||
export class UserProjectController extends BaseController {
|
||||
@Inject()
|
||||
service: ProjectService;
|
||||
|
||||
@Inject()
|
||||
projectMemberService: ProjectMemberService;
|
||||
|
||||
|
||||
@Inject()
|
||||
authService: AuthService;
|
||||
|
||||
@@ -24,54 +24,52 @@ export class UserProjectController extends BaseController {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param body
|
||||
* @returns
|
||||
/**
|
||||
* @param body
|
||||
* @returns
|
||||
*/
|
||||
@Post('/detail', { description: Constants.per.authOnly, summary: "查询项目详情" })
|
||||
@Post("/detail", { description: Constants.per.authOnly, summary: "查询项目详情" })
|
||||
async detail(@Body(ALL) body: any) {
|
||||
const {projectId} = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getDetail(projectId,this.getUserId());
|
||||
const { projectId } = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getDetail(projectId, this.getUserId());
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 我的项目
|
||||
* @param body
|
||||
* @returns
|
||||
* @param body
|
||||
* @returns
|
||||
*/
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询我的项目列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询我的项目列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const userId= this.getUserId();
|
||||
const userId = this.getUserId();
|
||||
const res = await this.service.getUserProjects(userId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param body 所有项目
|
||||
* @returns
|
||||
* @returns
|
||||
*/
|
||||
@Post('/all', { description: Constants.per.authOnly, summary: "查询所有项目" })
|
||||
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有项目" })
|
||||
async all(@Body(ALL) body: any) {
|
||||
const userId= this.getUserId();
|
||||
const userId = this.getUserId();
|
||||
const res = await this.service.getAllWithStatus(userId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/applyJoin', { description: Constants.per.authOnly, summary: "申请加入项目" })
|
||||
@Post("/applyJoin", { description: Constants.per.authOnly, summary: "申请加入项目" })
|
||||
async applyJoin(@Body(ALL) body: any) {
|
||||
const userId= this.getUserId();
|
||||
const userId = this.getUserId();
|
||||
const res = await this.service.applyJoin({ userId, projectId: body.projectId });
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/updateMember', { description: Constants.per.authOnly, summary: "更新项目成员" })
|
||||
@Post("/updateMember", { description: Constants.per.authOnly, summary: "更新项目成员" })
|
||||
async updateMember(@Body(ALL) body: any) {
|
||||
const {projectId} = await this.getProjectUserIdAdmin();
|
||||
const {status,permission,userId} = body;
|
||||
const { projectId } = await this.getProjectUserIdAdmin();
|
||||
const { status, permission, userId } = body;
|
||||
const member = await this.projectMemberService.findOne({
|
||||
where: {
|
||||
projectId,
|
||||
@@ -79,7 +77,7 @@ export class UserProjectController extends BaseController {
|
||||
},
|
||||
});
|
||||
if (!member) {
|
||||
throw new Error('成员不存在');
|
||||
throw new Error("成员不存在");
|
||||
}
|
||||
const res = await this.projectMemberService.update({
|
||||
id: member.id,
|
||||
@@ -89,17 +87,17 @@ export class UserProjectController extends BaseController {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/approveJoin', { description: Constants.per.authOnly, summary: "审批加入项目申请" })
|
||||
@Post("/approveJoin", { description: Constants.per.authOnly, summary: "审批加入项目申请" })
|
||||
async approveJoin(@Body(ALL) body: any) {
|
||||
const {projectId} = await this.getProjectUserIdAdmin();
|
||||
const {status,permission,userId} = body;
|
||||
const res = await this.service.approveJoin({ userId, projectId: projectId,status,permission });
|
||||
const { projectId } = await this.getProjectUserIdAdmin();
|
||||
const { status, permission, userId } = body;
|
||||
const res = await this.service.approveJoin({ userId, projectId: projectId, status, permission });
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除项目成员" })
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除项目成员" })
|
||||
async delete(@Body(ALL) body: any) {
|
||||
const {projectId} = await this.getProjectUserIdAdmin();
|
||||
const { projectId } = await this.getProjectUserIdAdmin();
|
||||
await this.projectMemberService.deleteWhere({
|
||||
projectId,
|
||||
userId: this.getUserId(),
|
||||
@@ -107,15 +105,14 @@ export class UserProjectController extends BaseController {
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/leave', { description: Constants.per.authOnly, summary: "离开项目" })
|
||||
@Post("/leave", { description: Constants.per.authOnly, summary: "离开项目" })
|
||||
async leave(@Body(ALL) body: any) {
|
||||
const {projectId} = body
|
||||
const userId = this.getUserId();
|
||||
const { projectId } = body;
|
||||
const userId = this.getUserId();
|
||||
await this.projectMemberService.deleteWhere({
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-14
@@ -1,4 +1,4 @@
|
||||
import { CrudController, SysSettingsService,Constants } from "@certd/lib-server";
|
||||
import { CrudController, SysSettingsService, Constants } from "@certd/lib-server";
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { ProjectMemberEntity } from "../../../modules/sys/enterprise/entity/project-member.js";
|
||||
import { ProjectMemberService } from "../../../modules/sys/enterprise/service/project-member-service.js";
|
||||
@@ -9,7 +9,7 @@ import { ApiTags } from "@midwayjs/swagger";
|
||||
*/
|
||||
@Provide()
|
||||
@Controller("/api/enterprise/projectMember")
|
||||
@ApiTags(['enterprise-project-member'])
|
||||
@ApiTags(["enterprise-project-member"])
|
||||
export class ProjectMemberController extends CrudController<ProjectMemberEntity> {
|
||||
@Inject()
|
||||
service: ProjectMemberService;
|
||||
@@ -26,7 +26,7 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
||||
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询项目成员分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const {projectId} = await this.getProjectUserIdRead();
|
||||
const { projectId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.projectId = projectId;
|
||||
return await super.page(body);
|
||||
@@ -34,7 +34,7 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
||||
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询项目成员列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const {projectId} = await this.getProjectUserIdRead();
|
||||
const { projectId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.projectId = projectId;
|
||||
return super.list(body);
|
||||
@@ -56,12 +56,12 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新项目成员" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新项目成员" })
|
||||
async update(@Body(ALL) bean: any) {
|
||||
if (!bean.id) {
|
||||
throw new Error("id is required");
|
||||
}
|
||||
const projectId = await this.service.getProjectId(bean.id)
|
||||
const projectId = await this.service.getProjectId(bean.id);
|
||||
await this.projectService.checkAdminPermission({
|
||||
userId: this.getUserId(),
|
||||
projectId: projectId,
|
||||
@@ -77,13 +77,13 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
||||
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询项目成员详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
if (!id) {
|
||||
if (!id) {
|
||||
throw new Error("id is required");
|
||||
}
|
||||
const projectId = await this.service.getProjectId(id)
|
||||
const projectId = await this.service.getProjectId(id);
|
||||
await this.projectService.checkReadPermission({
|
||||
userId: this.getUserId(),
|
||||
projectId:projectId,
|
||||
projectId: projectId,
|
||||
});
|
||||
return super.info(id);
|
||||
}
|
||||
@@ -93,10 +93,10 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
||||
if (!id) {
|
||||
throw new Error("id is required");
|
||||
}
|
||||
const projectId = await this.service.getProjectId(id)
|
||||
const projectId = await this.service.getProjectId(id);
|
||||
await this.projectService.checkAdminPermission({
|
||||
userId: this.getUserId(),
|
||||
projectId:projectId,
|
||||
projectId: projectId,
|
||||
});
|
||||
return super.delete(id);
|
||||
}
|
||||
@@ -107,14 +107,14 @@ export class ProjectMemberController extends CrudController<ProjectMemberEntity>
|
||||
if (!id) {
|
||||
throw new Error("id is required");
|
||||
}
|
||||
const projectId = await this.service.getProjectId(id)
|
||||
const projectId = await this.service.getProjectId(id);
|
||||
await this.projectService.checkAdminPermission({
|
||||
userId: this.getUserId(),
|
||||
projectId:projectId,
|
||||
projectId: projectId,
|
||||
});
|
||||
await this.service.delete(id as any);
|
||||
}
|
||||
|
||||
|
||||
return this.ok({});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,43 @@
|
||||
import { BaseController, Constants } from '@certd/lib-server';
|
||||
import { Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { TransferService } from '../../../modules/sys/enterprise/service/transfer-service.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { BaseController, Constants } from "@certd/lib-server";
|
||||
import { Controller, Inject, Post, Provide } from "@midwayjs/core";
|
||||
import { TransferService } from "../../../modules/sys/enterprise/service/transfer-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/enterprise/transfer')
|
||||
@ApiTags(['enterprise-project'])
|
||||
@Controller("/api/enterprise/transfer")
|
||||
@ApiTags(["enterprise-project"])
|
||||
export class TransferController extends BaseController {
|
||||
@Inject()
|
||||
service: TransferService;
|
||||
|
||||
|
||||
getService(): TransferService {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
/**
|
||||
* 我自己的资源
|
||||
* @param body
|
||||
* @returns
|
||||
/**
|
||||
* 我自己的资源
|
||||
* @param body
|
||||
* @returns
|
||||
*/
|
||||
@Post('/selfResources', { description: Constants.per.authOnly, summary: "查询我自己的资源" })
|
||||
@Post("/selfResources", { description: Constants.per.authOnly, summary: "查询我自己的资源" })
|
||||
async selfResources() {
|
||||
const userId = this.getUserId();
|
||||
const res = await this.service.getUserResources(userId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 迁移项目
|
||||
* @param body
|
||||
* @returns
|
||||
/**
|
||||
* 迁移项目
|
||||
* @param body
|
||||
* @returns
|
||||
*/
|
||||
@Post('/doTransfer', { description: Constants.per.authOnly, summary: "迁移项目资源" })
|
||||
@Post("/doTransfer", { description: Constants.per.authOnly, summary: "迁移项目资源" })
|
||||
async doTransfer() {
|
||||
const {projectId} = await this.getProjectUserIdRead();
|
||||
const userId = this.getUserId();
|
||||
await this.service.transferAll(userId,projectId);
|
||||
const { projectId } = await this.getProjectUserIdRead();
|
||||
const userId = this.getUserId();
|
||||
await this.service.transferAll(userId, projectId);
|
||||
return this.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
import { Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '@certd/lib-server';
|
||||
import { Constants } from '@certd/lib-server';
|
||||
import { EmailService } from '../../../modules/basic/service/email-service.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
||||
import { BaseController } from "@certd/lib-server";
|
||||
import { Constants } from "@certd/lib-server";
|
||||
import { EmailService } from "../../../modules/basic/service/email-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/mine/email')
|
||||
@ApiTags(['mine'])
|
||||
@Controller("/api/mine/email")
|
||||
@ApiTags(["mine"])
|
||||
export class EmailController extends BaseController {
|
||||
@Inject()
|
||||
emailService: EmailService;
|
||||
|
||||
@Post('/test', { description: Constants.per.authOnly, summary: "测试邮件发送" })
|
||||
public async test(@Body('receiver') receiver) {
|
||||
@Post("/test", { description: Constants.per.authOnly, summary: "测试邮件发送" })
|
||||
public async test(@Body("receiver") receiver) {
|
||||
const userId = super.getUserId();
|
||||
await this.emailService.test(userId, receiver);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询邮件列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询邮件列表" })
|
||||
public async list() {
|
||||
const userId = super.getUserId();
|
||||
const res = await this.emailService.list(userId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加邮件" })
|
||||
public async add(@Body('email') email) {
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加邮件" })
|
||||
public async add(@Body("email") email) {
|
||||
const userId = super.getUserId();
|
||||
await this.emailService.add(userId, email);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除邮件" })
|
||||
public async delete(@Body('email') email) {
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除邮件" })
|
||||
public async delete(@Body("email") email) {
|
||||
const userId = super.getUserId();
|
||||
await this.emailService.delete(userId, email);
|
||||
return this.ok({});
|
||||
|
||||
@@ -5,8 +5,8 @@ import { UserService } from "../../../modules/sys/authority/service/user-service
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
@Provide()
|
||||
@Controller('/api/mine/passkey')
|
||||
@ApiTags(['mine'])
|
||||
@Controller("/api/mine/passkey")
|
||||
@ApiTags(["mine"])
|
||||
export class MinePasskeyController extends BaseController {
|
||||
@Inject()
|
||||
passkeyService: PasskeyService;
|
||||
@@ -14,56 +14,43 @@ export class MinePasskeyController extends BaseController {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
|
||||
@Post('/generateRegistration', { description: Constants.per.authOnly, summary: "生成Passkey注册选项" })
|
||||
@Post("/generateRegistration", { description: Constants.per.authOnly, summary: "生成Passkey注册选项" })
|
||||
public async generateRegistration(
|
||||
@Body(ALL)
|
||||
body: any,
|
||||
@RequestIP()
|
||||
remoteIp: string
|
||||
) {
|
||||
const userId = this.getUserId()
|
||||
const userId = this.getUserId();
|
||||
const user = await this.userService.info(userId);
|
||||
|
||||
|
||||
if (!user) {
|
||||
throw new Error('用户不存在');
|
||||
throw new Error("用户不存在");
|
||||
}
|
||||
|
||||
const options = await this.passkeyService.generateRegistrationOptions(
|
||||
userId,
|
||||
user.username,
|
||||
remoteIp,
|
||||
this.ctx
|
||||
);
|
||||
const options = await this.passkeyService.generateRegistrationOptions(userId, user.username, remoteIp, this.ctx);
|
||||
|
||||
return this.ok({
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
@Post('/verifyRegistration', { description: Constants.per.authOnly, summary: "验证Passkey注册" })
|
||||
@Post("/verifyRegistration", { description: Constants.per.authOnly, summary: "验证Passkey注册" })
|
||||
public async verifyRegistration(
|
||||
@Body(ALL)
|
||||
body: any
|
||||
) {
|
||||
const userId = this.getUserId()
|
||||
const userId = this.getUserId();
|
||||
const response = body.response;
|
||||
const challenge = body.challenge;
|
||||
const deviceName = body.deviceName;
|
||||
|
||||
const result = await this.passkeyService.registerPasskey(
|
||||
userId,
|
||||
response,
|
||||
challenge,
|
||||
deviceName,
|
||||
this.ctx
|
||||
);
|
||||
const result = await this.passkeyService.registerPasskey(userId, response, challenge, deviceName, this.ctx);
|
||||
|
||||
return this.ok(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Post('/register', { description: Constants.per.authOnly, summary: "注册Passkey" })
|
||||
@Post("/register", { description: Constants.per.authOnly, summary: "注册Passkey" })
|
||||
public async registerPasskey(
|
||||
@Body(ALL)
|
||||
body: any
|
||||
@@ -73,30 +60,23 @@ export class MinePasskeyController extends BaseController {
|
||||
const deviceName = body.deviceName;
|
||||
const challenge = body.challenge;
|
||||
|
||||
const result = await this.passkeyService.registerPasskey(
|
||||
userId,
|
||||
response,
|
||||
challenge,
|
||||
deviceName,
|
||||
this.ctx
|
||||
);
|
||||
const result = await this.passkeyService.registerPasskey(userId, response, challenge, deviceName, this.ctx);
|
||||
|
||||
return this.ok(result);
|
||||
}
|
||||
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询Passkey列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询Passkey列表" })
|
||||
public async getPasskeys() {
|
||||
const userId = this.getUserId();
|
||||
const passkeys = await this.passkeyService.find({
|
||||
select: ['id', 'deviceName', 'registeredAt', 'transports', 'passkeyId' ,'updateTime'],
|
||||
select: ["id", "deviceName", "registeredAt", "transports", "passkeyId", "updateTime"],
|
||||
where: { userId },
|
||||
order: { registeredAt: 'DESC' },
|
||||
order: { registeredAt: "DESC" },
|
||||
});
|
||||
return this.ok(passkeys);
|
||||
}
|
||||
|
||||
@Post('/unbind', { description: Constants.per.authOnly, summary: "解绑Passkey" })
|
||||
@Post("/unbind", { description: Constants.per.authOnly, summary: "解绑Passkey" })
|
||||
public async unbindPasskey(@Body(ALL) body: any) {
|
||||
const userId = this.getUserId();
|
||||
const passkeyId = body.id;
|
||||
@@ -106,11 +86,10 @@ export class MinePasskeyController extends BaseController {
|
||||
});
|
||||
|
||||
if (!passkey) {
|
||||
throw new Error('Passkey不存在');
|
||||
throw new Error("Passkey不存在");
|
||||
}
|
||||
|
||||
await this.passkeyService.delete([passkey.id]);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-16
@@ -4,14 +4,14 @@ import { UserSettingsService } from "../../../modules/mine/service/user-settings
|
||||
import { UserTwoFactorSetting } from "../../../modules/mine/service/models.js";
|
||||
import { merge } from "lodash-es";
|
||||
import { TwoFactorService } from "../../../modules/mine/service/two-factor-service.js";
|
||||
import {isPlus} from "@certd/plus-core";
|
||||
import { isPlus } from "@certd/plus-core";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller("/api/user/settings/twoFactor")
|
||||
@ApiTags(['mine'])
|
||||
@ApiTags(["mine"])
|
||||
export class UserTwoFactorSettingController extends BaseController {
|
||||
@Inject()
|
||||
service: UserSettingsService;
|
||||
@@ -19,50 +19,48 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
@Inject()
|
||||
twoFactorService: TwoFactorService;
|
||||
|
||||
|
||||
|
||||
@Post("/get", { description: Constants.per.authOnly, summary: "获取双因子认证设置" })
|
||||
async get() {
|
||||
const userId = this.getUserId();
|
||||
const setting = await this.service.getSetting<UserTwoFactorSetting>(userId,null, UserTwoFactorSetting);
|
||||
const setting = await this.service.getSetting<UserTwoFactorSetting>(userId, null, UserTwoFactorSetting);
|
||||
return this.ok(setting);
|
||||
}
|
||||
|
||||
@Post("/save", { description: Constants.per.authOnly, summary: "保存双因子认证设置" })
|
||||
async save(@Body(ALL) bean: any) {
|
||||
if (!isPlus()) {
|
||||
throw new Error('本功能需要开通Certd专业版')
|
||||
throw new Error("本功能需要开通Certd专业版");
|
||||
}
|
||||
const userId = this.getUserId();
|
||||
const setting = new UserTwoFactorSetting();
|
||||
merge(setting, bean);
|
||||
|
||||
// 禁用时清除
|
||||
if(!setting.authenticator.enabled){
|
||||
setting.authenticator.secret = null;
|
||||
setting.authenticator.verified = false;
|
||||
if (!setting.authenticator.enabled) {
|
||||
setting.authenticator.secret = null;
|
||||
setting.authenticator.verified = false;
|
||||
}
|
||||
|
||||
await this.service.saveSetting(userId,null, setting);
|
||||
await this.service.saveSetting(userId, null, setting);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post("/authenticator/qrcode", { description: Constants.per.authOnly, summary: "获取验证器二维码" })
|
||||
async authenticatorQrcode() {
|
||||
const userId = this.getUserId();
|
||||
const {qrcode,link,secret} = await this.twoFactorService.getAuthenticatorQrCode(userId);
|
||||
return this.ok({qrcode,link,secret});
|
||||
const { qrcode, link, secret } = await this.twoFactorService.getAuthenticatorQrCode(userId);
|
||||
return this.ok({ qrcode, link, secret });
|
||||
}
|
||||
|
||||
@Post("/authenticator/save", { description: Constants.per.authOnly, summary: "保存验证器设置" })
|
||||
async authenticatorSave(@Body(ALL) bean: any) {
|
||||
if (!isPlus()) {
|
||||
throw new Error('本功能需要开通Certd专业版')
|
||||
throw new Error("本功能需要开通Certd专业版");
|
||||
}
|
||||
const userId = this.getUserId();
|
||||
await this.twoFactorService.saveAuthenticator({
|
||||
userId,
|
||||
verifyCode: bean.verifyCode,
|
||||
userId,
|
||||
verifyCode: bean.verifyCode,
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
@@ -73,5 +71,4 @@ export class UserTwoFactorSettingController extends BaseController {
|
||||
await this.twoFactorService.offAuthenticator(userId);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import { ApiTags } from "@midwayjs/swagger";
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/user/settings')
|
||||
@ApiTags(['mine'])
|
||||
@Controller("/api/user/settings")
|
||||
@ApiTags(["mine"])
|
||||
export class UserSettingsController extends CrudController<UserSettingsService> {
|
||||
@Inject()
|
||||
service: UserSettingsService;
|
||||
@@ -20,54 +20,54 @@ export class UserSettingsController extends CrudController<UserSettingsService>
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询用户设置分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询用户设置分页列表" })
|
||||
async page(@Body(ALL) body) {
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = this.getUserId();
|
||||
return super.page(body);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询用户设置列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询用户设置列表" })
|
||||
async list(@Body(ALL) body) {
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = this.getUserId();
|
||||
return super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加用户设置" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加用户设置" })
|
||||
async add(@Body(ALL) bean) {
|
||||
bean.userId = this.getUserId();
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新用户设置" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新用户设置" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.service.checkUserId(bean.id, this.getUserId());
|
||||
delete bean.userId;
|
||||
return super.update(bean);
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询用户设置详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询用户设置详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
return super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除用户设置" })
|
||||
async delete(@Query('id') id: number) {
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除用户设置" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.service.checkUserId(id, this.getUserId());
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/save', { description: Constants.per.authOnly, summary: "保存用户设置" })
|
||||
@Post("/save", { description: Constants.per.authOnly, summary: "保存用户设置" })
|
||||
async save(@Body(ALL) bean: UserSettingsEntity) {
|
||||
bean.userId = this.getUserId();
|
||||
await this.service.save(bean);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/get', { description: Constants.per.authOnly, summary: "获取用户设置" })
|
||||
async get(@Query('key') key: string) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
@Post("/get", { description: Constants.per.authOnly, summary: "获取用户设置" })
|
||||
async get(@Query("key") key: string) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const entity = await this.service.getByKey(key, userId, projectId);
|
||||
return this.ok(entity);
|
||||
}
|
||||
@@ -81,14 +81,13 @@ export class UserSettingsController extends CrudController<UserSettingsService>
|
||||
@Post("/grant/save", { description: Constants.per.authOnly, summary: "保存授权设置" })
|
||||
async grantSettingsSave(@Body(ALL) bean: UserGrantSetting) {
|
||||
if (!isPlus()) {
|
||||
throw new Error('本功能需要开通Certd专业版')
|
||||
throw new Error("本功能需要开通Certd专业版");
|
||||
}
|
||||
const userId = this.getUserId();
|
||||
const setting = new UserGrantSetting();
|
||||
merge(setting, bean);
|
||||
|
||||
await this.service.saveSetting(userId,null, setting);
|
||||
await this.service.saveSetting(userId, null, setting);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ import { CertReader } from "@certd/plugin-lib";
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/monitor/cert')
|
||||
@ApiTags(['cert'])
|
||||
@Controller("/api/monitor/cert")
|
||||
@ApiTags(["cert"])
|
||||
export class CertInfoController extends CrudController<CertInfoService> {
|
||||
@Inject()
|
||||
service: CertInfoService;
|
||||
@@ -30,12 +30,12 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询证书分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询证书分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.projectId = projectId;
|
||||
body.query.userId = userId;
|
||||
const domains = body.query?.domains;
|
||||
delete body.query.domains;
|
||||
@@ -49,21 +49,21 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
query: body.query,
|
||||
page: body.page,
|
||||
sort: body.sort,
|
||||
buildQuery: (bq) => {
|
||||
buildQuery: bq => {
|
||||
if (domains) {
|
||||
bq.andWhere('domains like :domains', { domains: `%${domains}%` });
|
||||
bq.andWhere("domains like :domains", { domains: `%${domains}%` });
|
||||
}
|
||||
if (expiresLeft) {
|
||||
const willExpire = dayjs().add(DEFAULT_WILL_EXPIRE_DAYS, 'day').valueOf();
|
||||
const willExpire = dayjs().add(DEFAULT_WILL_EXPIRE_DAYS, "day").valueOf();
|
||||
if (expiresLeft === "expired") {
|
||||
bq.andWhere('expires_time < :now', { now: Date.now() });
|
||||
bq.andWhere("expires_time < :now", { now: Date.now() });
|
||||
} else if (expiresLeft === "expiring") {
|
||||
bq.andWhere('expires_time <= :willExpire and expires_time > :now', { willExpire, now: Date.now() });
|
||||
bq.andWhere("expires_time <= :willExpire and expires_time > :now", { willExpire, now: Date.now() });
|
||||
} else if (expiresLeft === "noExpired") {
|
||||
bq.andWhere('expires_time > :willExpire', { willExpire });
|
||||
bq.andWhere("expires_time > :willExpire", { willExpire });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const records = res.records;
|
||||
@@ -79,71 +79,70 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询证书列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询证书列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.projectId = projectId;
|
||||
body.query.userId = userId;
|
||||
return await super.list(body);
|
||||
}
|
||||
|
||||
|
||||
@Post('/getOptionsByIds', { description: Constants.per.authOnly, summary: "根据ID列表获取证书选项" })
|
||||
async getOptionsByIds(@Body(ALL) body: {ids:any[]}) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
@Post("/getOptionsByIds", { description: Constants.per.authOnly, summary: "根据ID列表获取证书选项" })
|
||||
async getOptionsByIds(@Body(ALL) body: { ids: any[] }) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const list = await this.service.list({
|
||||
query:{
|
||||
query: {
|
||||
projectId,
|
||||
userId,
|
||||
},
|
||||
buildQuery: (bq: SelectQueryBuilder<any>) => {
|
||||
bq.andWhere('id in (:...ids)', { ids: body.ids });
|
||||
}
|
||||
})
|
||||
bq.andWhere("id in (:...ids)", { ids: body.ids });
|
||||
},
|
||||
});
|
||||
|
||||
const safeList =list.map((item:any) => {
|
||||
const domainsArr = item.domains? item.domains.split(',') : [];
|
||||
const safeList = list.map((item: any) => {
|
||||
const domainsArr = item.domains ? item.domains.split(",") : [];
|
||||
return {
|
||||
id: item.id,
|
||||
domain: item.domain,
|
||||
domains:domainsArr,
|
||||
domains: domainsArr,
|
||||
userId: item.userId,
|
||||
}
|
||||
})
|
||||
};
|
||||
});
|
||||
return this.ok(safeList);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加证书" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加证书" })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
bean.projectId = projectId
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
bean.projectId = projectId;
|
||||
bean.userId = userId;
|
||||
return await super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新证书" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新证书" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.service,bean.id,"write");
|
||||
await this.checkOwner(this.service, bean.id, "write");
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
return await super.update(bean);
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询证书详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询证书详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "read");
|
||||
return await super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除证书" })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"write");
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除证书" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "write");
|
||||
return await super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/all', { description: Constants.per.authOnly, summary: "查询所有证书" })
|
||||
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有证书" })
|
||||
async all() {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const list: any = await this.service.find({
|
||||
where: {
|
||||
projectId,
|
||||
@@ -153,32 +152,30 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
return this.ok(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Post('/getCert', { description: Constants.per.authOnly, summary: "获取证书信息" })
|
||||
async getCert(@Query('id') id: number) {
|
||||
await this.checkOwner(this.getService(),id,"read");
|
||||
@Post("/getCert", { description: Constants.per.authOnly, summary: "获取证书信息" })
|
||||
async getCert(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read");
|
||||
const certInfoEntity = await this.service.info(id);
|
||||
const certInfo = JSON.parse(certInfoEntity.certInfo);
|
||||
if (certInfo?.crt) {
|
||||
const certReader = new CertReader(certInfo);
|
||||
certInfo.detail = certReader.detail
|
||||
certInfo.detail = certReader.detail;
|
||||
}
|
||||
return this.ok(certInfo);
|
||||
}
|
||||
|
||||
@Get('/download', { description: Constants.per.authOnly, summary: "下载证书文件" })
|
||||
async download(@Query('id') id: number) {
|
||||
const {userId,projectId} =await this.checkOwner(this.getService(),id,"read");
|
||||
const certInfo = await this.getService().info(id)
|
||||
@Get("/download", { description: Constants.per.authOnly, summary: "下载证书文件" })
|
||||
async download(@Query("id") id: number) {
|
||||
const { userId, projectId } = await this.checkOwner(this.getService(), id, "read");
|
||||
const certInfo = await this.getService().info(id);
|
||||
if (certInfo == null) {
|
||||
throw new CommonException('file not found');
|
||||
throw new CommonException("file not found");
|
||||
}
|
||||
if (certInfo.userId !== userId) {
|
||||
throw new CommonException('file not found');
|
||||
throw new CommonException("file not found");
|
||||
}
|
||||
if (projectId && certInfo.projectId !== projectId) {
|
||||
throw new CommonException('file not found');
|
||||
throw new CommonException("file not found");
|
||||
}
|
||||
// koa send file
|
||||
// 下载文件的名称
|
||||
@@ -186,12 +183,12 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
// 要下载的文件的完整路径
|
||||
const path = certInfo.certFile;
|
||||
if (!path) {
|
||||
throw new CommonException('file not found');
|
||||
throw new CommonException("file not found");
|
||||
}
|
||||
logger.info(`download:${path}`);
|
||||
// 以流的形式下载文件
|
||||
this.ctx.attachment(path);
|
||||
this.ctx.set('Content-Type', 'application/octet-stream');
|
||||
this.ctx.set("Content-Type", "application/octet-stream");
|
||||
|
||||
return fs.createReadStream(path);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import { AuthService } from "../../../modules/sys/authority/service/auth-service
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/monitor/job-history')
|
||||
@ApiTags(['monitor'])
|
||||
@Controller("/api/monitor/job-history")
|
||||
@ApiTags(["monitor"])
|
||||
export class JobHistoryController extends CrudController<JobHistoryService> {
|
||||
@Inject()
|
||||
service: JobHistoryService;
|
||||
@@ -22,12 +22,12 @@ export class JobHistoryController extends CrudController<JobHistoryService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询监控运行历史分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询监控运行历史分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId
|
||||
body.query.projectId = projectId;
|
||||
const res = await this.service.page({
|
||||
query: body.query,
|
||||
page: body.page,
|
||||
@@ -36,30 +36,30 @@ export class JobHistoryController extends CrudController<JobHistoryService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询监控运行历史列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询监控运行历史列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId
|
||||
body.query.projectId = projectId;
|
||||
return await super.list(body);
|
||||
}
|
||||
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询监控运行历史详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询监控运行历史详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "read");
|
||||
return await super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除监控运行历史" })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"write");
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除监控运行历史" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "write");
|
||||
return await super.delete(id);
|
||||
}
|
||||
@Post('/batchDelete', { description: Constants.per.authOnly, summary: "批量删除监控运行历史" })
|
||||
async batchDelete(@Body('ids') ids: number[]) {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
await this.service.batchDelete(ids,userId,projectId);
|
||||
@Post("/batchDelete", { description: Constants.per.authOnly, summary: "批量删除监控运行历史" })
|
||||
async batchDelete(@Body("ids") ids: number[]) {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
await this.service.batchDelete(ids, userId, projectId);
|
||||
return this.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@ import { AuthService } from "../../../modules/sys/authority/service/auth-service
|
||||
import { SiteInfoService } from "../../../modules/monitor/service/site-info-service.js";
|
||||
import { UserSiteMonitorSetting } from "../../../modules/mine/service/models.js";
|
||||
import { merge } from "lodash-es";
|
||||
import {SiteIpService} from "../../../modules/monitor/service/site-ip-service.js";
|
||||
import { SiteIpService } from "../../../modules/monitor/service/site-ip-service.js";
|
||||
import { utils } from "@certd/basic";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/monitor/site')
|
||||
@ApiTags(['monitor'])
|
||||
@Controller("/api/monitor/site")
|
||||
@ApiTags(["monitor"])
|
||||
export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
@Inject()
|
||||
service: SiteInfoService;
|
||||
@@ -25,11 +25,11 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询站点监控分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询站点监控分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.projectId = projectId;
|
||||
body.query.userId = userId;
|
||||
const certDomains = body.query.certDomains;
|
||||
const domain = body.query.domain;
|
||||
@@ -41,34 +41,34 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
query: body.query,
|
||||
page: body.page,
|
||||
sort: body.sort,
|
||||
buildQuery: (bq) => {
|
||||
buildQuery: bq => {
|
||||
if (domain) {
|
||||
bq.andWhere('domain like :domain', { domain: `%${domain}%` });
|
||||
bq.andWhere("domain like :domain", { domain: `%${domain}%` });
|
||||
}
|
||||
if (certDomains) {
|
||||
bq.andWhere('cert_domains like :cert_domains', { cert_domains: `%${certDomains}%` });
|
||||
bq.andWhere("cert_domains like :cert_domains", { cert_domains: `%${certDomains}%` });
|
||||
}
|
||||
if (name) {
|
||||
bq.andWhere('name like :name', { name: `%${name}%` });
|
||||
bq.andWhere("name like :name", { name: `%${name}%` });
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询站点监控列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询站点监控列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.projectId = projectId;
|
||||
body.query.userId = userId;
|
||||
return await super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加站点监控" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加站点监控" })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
bean.projectId = projectId
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
bean.projectId = projectId;
|
||||
bean.userId = userId;
|
||||
const res = await this.service.add(bean);
|
||||
const entity = await this.service.info(res.id);
|
||||
@@ -78,9 +78,9 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新站点监控" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新站点监控" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.service,bean.id,"write");
|
||||
await this.checkOwner(this.service, bean.id, "write");
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
await this.service.update(bean);
|
||||
@@ -90,89 +90,86 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
}
|
||||
return this.ok();
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询站点监控详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询站点监控详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "read");
|
||||
return await super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除站点监控" })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"write");
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除站点监控" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "write");
|
||||
return await super.delete(id);
|
||||
}
|
||||
|
||||
|
||||
@Post('/batchDelete', { description: Constants.per.authOnly, summary: "批量删除站点监控" })
|
||||
@Post("/batchDelete", { description: Constants.per.authOnly, summary: "批量删除站点监控" })
|
||||
async batchDelete(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
await this.service.batchDelete(body.ids,userId,projectId);
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
await this.service.batchDelete(body.ids, userId, projectId);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/check', { description: Constants.per.authOnly, summary: "检查站点监控" })
|
||||
async check(@Body('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
@Post("/check", { description: Constants.per.authOnly, summary: "检查站点监控" })
|
||||
async check(@Body("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "read");
|
||||
await this.service.check(id, true, 0);
|
||||
await utils.sleep(1000);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/checkAll', { description: Constants.per.authOnly, summary: "检查所有站点监控" })
|
||||
@Post("/checkAll", { description: Constants.per.authOnly, summary: "检查所有站点监控" })
|
||||
async checkAll() {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
this.service.triggerJobOnce(userId,projectId);
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
this.service.triggerJobOnce(userId, projectId);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/import', { description: Constants.per.authOnly, summary: "导入站点监控" })
|
||||
@Post("/import", { description: Constants.per.authOnly, summary: "导入站点监控" })
|
||||
async doImport(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
await this.service.doImport({
|
||||
text:body.text,
|
||||
groupId:body.groupId,
|
||||
text: body.text,
|
||||
groupId: body.groupId,
|
||||
userId,
|
||||
projectId
|
||||
})
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
|
||||
@Post('/ipCheckChange', { description: Constants.per.authOnly, summary: "修改IP检查设置" })
|
||||
async ipCheckChange(@Body(ALL) bean: any) {
|
||||
await this.checkOwner(this.service,bean.id,"read");
|
||||
await this.service.ipCheckChange({
|
||||
id: bean.id,
|
||||
ipCheck: bean.ipCheck
|
||||
projectId,
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/disabledChange', { description: Constants.per.authOnly, summary: "修改禁用状态" })
|
||||
@Post("/ipCheckChange", { description: Constants.per.authOnly, summary: "修改IP检查设置" })
|
||||
async ipCheckChange(@Body(ALL) bean: any) {
|
||||
await this.checkOwner(this.service, bean.id, "read");
|
||||
await this.service.ipCheckChange({
|
||||
id: bean.id,
|
||||
ipCheck: bean.ipCheck,
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post("/disabledChange", { description: Constants.per.authOnly, summary: "修改禁用状态" })
|
||||
async disabledChange(@Body(ALL) bean: any) {
|
||||
await this.checkOwner(this.service,bean.id,"write");
|
||||
await this.checkOwner(this.service, bean.id, "write");
|
||||
await this.service.disabledChange({
|
||||
id: bean.id,
|
||||
disabled: bean.disabled
|
||||
disabled: bean.disabled,
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post("/setting/get", { description: Constants.per.authOnly, summary: "获取站点监控设置" })
|
||||
async get() {
|
||||
const { userId, projectId } = await this.getProjectUserIdRead()
|
||||
const setting = await this.service.getSetting(userId, projectId)
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
const setting = await this.service.getSetting(userId, projectId);
|
||||
return this.ok(setting);
|
||||
}
|
||||
|
||||
@Post("/setting/save", { description: Constants.per.authOnly, summary: "保存站点监控设置" })
|
||||
async save(@Body(ALL) bean: any) {
|
||||
const { userId, projectId} = await this.getProjectUserIdWrite()
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
const setting = new UserSiteMonitorSetting();
|
||||
merge(setting, bean);
|
||||
|
||||
await this.service.saveSetting(userId, projectId,setting);
|
||||
await this.service.saveSetting(userId, projectId, setting);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import { ApiTags } from "@midwayjs/swagger";
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/monitor/site/ip')
|
||||
@ApiTags(['monitor'])
|
||||
@Controller("/api/monitor/site/ip")
|
||||
@ApiTags(["monitor"])
|
||||
export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
@Inject()
|
||||
service: SiteIpService;
|
||||
@@ -22,12 +22,12 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询站点IP分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询站点IP分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId
|
||||
body.query.projectId = projectId;
|
||||
const res = await this.service.page({
|
||||
query: body.query,
|
||||
page: body.page,
|
||||
@@ -36,98 +36,94 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询站点IP列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询站点IP列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId
|
||||
body.query.projectId = projectId;
|
||||
return await super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加站点IP" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加站点IP" })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId
|
||||
bean.from = "manual"
|
||||
bean.projectId = projectId;
|
||||
bean.from = "manual";
|
||||
const res = await this.service.add(bean);
|
||||
const siteEntity = await this.siteInfoService.info(bean.siteId);
|
||||
if(!siteEntity.disabled){
|
||||
const {domain, httpsPort} = siteEntity;
|
||||
this.service.check(res.id,domain, httpsPort);
|
||||
if (!siteEntity.disabled) {
|
||||
const { domain, httpsPort } = siteEntity;
|
||||
this.service.check(res.id, domain, httpsPort);
|
||||
}
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新站点IP" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新站点IP" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.service,bean.id,"write");
|
||||
await this.checkOwner(this.service, bean.id, "write");
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
await this.service.update(bean);
|
||||
const siteEntity = await this.siteInfoService.info(bean.siteId);
|
||||
if(!siteEntity.disabled){
|
||||
const {domain, httpsPort} = siteEntity;
|
||||
this.service.check(siteEntity.id,domain, httpsPort);
|
||||
if (!siteEntity.disabled) {
|
||||
const { domain, httpsPort } = siteEntity;
|
||||
this.service.check(siteEntity.id, domain, httpsPort);
|
||||
}
|
||||
return this.ok();
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询站点IP详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询站点IP详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "read");
|
||||
return await super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除站点IP" })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"write");
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除站点IP" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "write");
|
||||
const entity = await this.service.info(id);
|
||||
const res = await super.delete(id);
|
||||
await this.service.updateIpCount(entity.siteId)
|
||||
return res
|
||||
await this.service.updateIpCount(entity.siteId);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Post('/check', { description: Constants.per.authOnly, summary: "检查站点IP" })
|
||||
async check(@Body('id') id: number) {
|
||||
await this.checkOwner(this.service,id,"read");
|
||||
@Post("/check", { description: Constants.per.authOnly, summary: "检查站点IP" })
|
||||
async check(@Body("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "read");
|
||||
const entity = await this.service.info(id);
|
||||
const siteEntity = await this.siteInfoService.info(entity.siteId);
|
||||
const domain = siteEntity.domain;
|
||||
const port = siteEntity.httpsPort;
|
||||
this.service.check(id,domain,port);
|
||||
this.service.check(id, domain, port);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/checkAll', { description: Constants.per.authOnly, summary: "检查所有站点IP" })
|
||||
async checkAll(@Body('siteId') siteId: number) {
|
||||
await this.getProjectUserIdRead()
|
||||
@Post("/checkAll", { description: Constants.per.authOnly, summary: "检查所有站点IP" })
|
||||
async checkAll(@Body("siteId") siteId: number) {
|
||||
await this.getProjectUserIdRead();
|
||||
const siteEntity = await this.siteInfoService.info(siteId);
|
||||
await this.service.syncAndCheck(siteEntity);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/sync', { description: Constants.per.authOnly, summary: "同步站点IP" })
|
||||
async sync(@Body('siteId') siteId: number) {
|
||||
await this.getProjectUserIdWrite()
|
||||
const entity = await this.siteInfoService.info(siteId)
|
||||
@Post("/sync", { description: Constants.per.authOnly, summary: "同步站点IP" })
|
||||
async sync(@Body("siteId") siteId: number) {
|
||||
await this.getProjectUserIdWrite();
|
||||
const entity = await this.siteInfoService.info(siteId);
|
||||
await this.service.sync(entity);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/import', { description: Constants.per.authOnly, summary: "导入站点IP" })
|
||||
@Post("/import", { description: Constants.per.authOnly, summary: "导入站点IP" })
|
||||
async doImport(@Body(ALL) body: any) {
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite()
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
await this.service.doImport({
|
||||
text:body.text,
|
||||
text: body.text,
|
||||
userId,
|
||||
siteId:body.siteId,
|
||||
projectId
|
||||
})
|
||||
siteId: body.siteId,
|
||||
projectId,
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { Constants, CrudController } from '@certd/lib-server';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { OpenKeyService } from '../../../modules/open/service/open-key-service.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Constants, CrudController } from "@certd/lib-server";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { OpenKeyService } from "../../../modules/open/service/open-key-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/open/key')
|
||||
@ApiTags(['open'])
|
||||
@Controller("/api/open/key")
|
||||
@ApiTags(["open"])
|
||||
export class OpenKeyController extends CrudController<OpenKeyService> {
|
||||
@Inject()
|
||||
service: OpenKeyService;
|
||||
@@ -19,9 +19,9 @@ export class OpenKeyController extends CrudController<OpenKeyService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询开放API密钥分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询开放API密钥分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.projectId = projectId;
|
||||
body.query.userId = userId;
|
||||
@@ -36,13 +36,13 @@ export class OpenKeyController extends CrudController<OpenKeyService> {
|
||||
|
||||
private keySecretDesensitization(list: any[]) {
|
||||
for (const item of list) {
|
||||
item.keySecret = item.keySecret?.substring(0, 4) + '*********************************' + item.keySecret?.substring(item.keySecret.length - 4);
|
||||
item.keySecret = item.keySecret?.substring(0, 4) + "*********************************" + item.keySecret?.substring(item.keySecret.length - 4);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询开放API密钥列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询开放API密钥列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.projectId = projectId;
|
||||
body.query.userId = userId;
|
||||
@@ -51,16 +51,16 @@ export class OpenKeyController extends CrudController<OpenKeyService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加开放API密钥" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加开放API密钥" })
|
||||
async add(@Body(ALL) body: any) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.projectId = projectId;
|
||||
body.userId = userId;
|
||||
const res = await this.service.add(body);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新开放API密钥" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新开放API密钥" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.getService(), bean.id, "write");
|
||||
delete bean.userId;
|
||||
@@ -68,8 +68,8 @@ export class OpenKeyController extends CrudController<OpenKeyService> {
|
||||
await this.service.update(bean);
|
||||
return this.ok();
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询开放API密钥详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询开放API密钥详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
const info = await this.checkPermission(id);
|
||||
return this.ok(info);
|
||||
}
|
||||
@@ -77,32 +77,31 @@ export class OpenKeyController extends CrudController<OpenKeyService> {
|
||||
private async checkPermission(id: number) {
|
||||
const info = await this.service.info(id);
|
||||
if (!info) {
|
||||
throw new Error('密钥不存在');
|
||||
throw new Error("密钥不存在");
|
||||
}
|
||||
if (info.scope === 'user'){
|
||||
await this.checkOwner(this.getService(), id, "write");;
|
||||
}else{
|
||||
if (info.scope === "user") {
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
} else {
|
||||
await this.checkOwner(this.getService(), id, "read");
|
||||
}
|
||||
return info
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除开放API密钥" })
|
||||
async delete(@Query('id') id: number) {
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除开放API密钥" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
return await super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/getApiToken', { description: Constants.per.authOnly, summary: "获取API测试令牌" })
|
||||
async getApiToken(@Body('id') id: number) {
|
||||
@Post("/getApiToken", { description: Constants.per.authOnly, summary: "获取API测试令牌" })
|
||||
async getApiToken(@Body("id") id: number) {
|
||||
await this.checkPermission(id);
|
||||
const token = await this.service.getApiToken(id);
|
||||
return this.ok(token);
|
||||
}
|
||||
|
||||
@Post('/getSecret', { description: Constants.per.authOnly, summary: "获取密钥" })
|
||||
async getSecret(@Body('id') id: number) {
|
||||
@Post("/getSecret", { description: Constants.per.authOnly, summary: "获取密钥" })
|
||||
async getSecret(@Body("id") id: number) {
|
||||
const info = await this.checkPermission(id);
|
||||
return this.ok(info.keySecret);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { Constants, CrudController } from '@certd/lib-server';
|
||||
import { AccessService } from '@certd/lib-server';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { AccessDefine } from '@certd/pipeline';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Constants, CrudController } from "@certd/lib-server";
|
||||
import { AccessService } from "@certd/lib-server";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { AccessDefine } from "@certd/pipeline";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 授权
|
||||
*/
|
||||
@Provide()
|
||||
@ApiTags(['pipeline-access'])
|
||||
@Controller('/api/pi/access')
|
||||
@ApiTags(["pipeline-access"])
|
||||
@Controller("/api/pi/access")
|
||||
export class AccessController extends CrudController<AccessService> {
|
||||
@Inject()
|
||||
service: AccessService;
|
||||
@@ -21,18 +21,18 @@ export class AccessController extends CrudController<AccessService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询授权配置分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询授权配置分页列表" })
|
||||
async page(@Body(ALL) body) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
delete body.query.userId;
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId;
|
||||
let name = body.query?.name;
|
||||
const name = body.query?.name;
|
||||
delete body.query.name;
|
||||
const buildQuery = qb => {
|
||||
if (name) {
|
||||
qb.andWhere('name like :name', { name: `%${name.trim()}%` });
|
||||
qb.andWhere("name like :name", { name: `%${name.trim()}%` });
|
||||
}
|
||||
};
|
||||
const res = await this.service.page({
|
||||
@@ -44,60 +44,60 @@ export class AccessController extends CrudController<AccessService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询授权配置列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询授权配置列表" })
|
||||
async list(@Body(ALL) body) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId;
|
||||
return super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加授权配置" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加授权配置" })
|
||||
async add(@Body(ALL) bean) {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite()
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId;
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新授权配置" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新授权配置" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.getService(), bean.id, "write");
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
return super.update(bean);
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询授权配置详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询授权配置详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read");
|
||||
return super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除授权配置" })
|
||||
async delete(@Query('id') id: number) {
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除授权配置" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/define', { description: Constants.per.authOnly, summary: "查询授权插件定义" })
|
||||
async define(@Query('type') type: string) {
|
||||
@Post("/define", { description: Constants.per.authOnly, summary: "查询授权插件定义" })
|
||||
async define(@Query("type") type: string) {
|
||||
const access = this.service.getDefineByType(type);
|
||||
return this.ok(access);
|
||||
}
|
||||
|
||||
@Post('/getSecretPlain', { description: Constants.per.authOnly, summary: "获取授权配置明文密钥" })
|
||||
@Post("/getSecretPlain", { description: Constants.per.authOnly, summary: "获取授权配置明文密钥" })
|
||||
async getSecretPlain(@Body(ALL) body: { id: number; key: string }) {
|
||||
const {userId, projectId} = await this.checkOwner(this.getService(), body.id, "read");
|
||||
const value = await this.service.getById(body.id, userId, projectId);
|
||||
const { userId, projectId } = await this.checkOwner(this.getService(), body.id, "read");
|
||||
const value = await this.service.getById(body.id, userId, projectId);
|
||||
return this.ok(value[body.key]);
|
||||
}
|
||||
|
||||
@Post('/accessTypeDict', { description: Constants.per.authOnly, summary: "查询授权类型字典" })
|
||||
@Post("/accessTypeDict", { description: Constants.per.authOnly, summary: "查询授权类型字典" })
|
||||
async getAccessTypeDict() {
|
||||
let list: AccessDefine[] = this.service.getDefineList();
|
||||
list = list.sort((a,b) => {
|
||||
return (a.order??10) - (b.order??10);
|
||||
list = list.sort((a, b) => {
|
||||
return (a.order ?? 10) - (b.order ?? 10);
|
||||
});
|
||||
const dict = [];
|
||||
for (const item of list) {
|
||||
@@ -110,17 +110,17 @@ export class AccessController extends CrudController<AccessService> {
|
||||
return this.ok(dict);
|
||||
}
|
||||
|
||||
@Post('/simpleInfo', { description: Constants.per.authOnly, summary: "查询授权配置简单信息" })
|
||||
async simpleInfo(@Query('id') id: number) {
|
||||
@Post("/simpleInfo", { description: Constants.per.authOnly, summary: "查询授权配置简单信息" })
|
||||
async simpleInfo(@Query("id") id: number) {
|
||||
// await this.authService.checkUserIdButAllowAdmin(this.ctx, this.service, id);
|
||||
// await this.checkOwner(this.getService(), id, "read",true);
|
||||
const res = await this.service.getSimpleInfo(id);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/getDictByIds', { description: Constants.per.authOnly, summary: "根据ID列表获取授权配置字典" })
|
||||
async getDictByIds(@Body('ids') ids: number[]) {
|
||||
const { userId, projectId } = await this.getProjectUserIdRead()
|
||||
@Post("/getDictByIds", { description: Constants.per.authOnly, summary: "根据ID列表获取授权配置字典" })
|
||||
async getDictByIds(@Body("ids") ids: number[]) {
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getSimpleByIds(ids, userId, projectId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@@ -1,64 +1,60 @@
|
||||
import { Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
|
||||
import { BaseController, Constants, PermissionException } from '@certd/lib-server';
|
||||
import { StorageService } from '../../../modules/pipeline/service/storage-service.js';
|
||||
import { Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
|
||||
import { BaseController, Constants, PermissionException } from "@certd/lib-server";
|
||||
import { StorageService } from "../../../modules/pipeline/service/storage-service.js";
|
||||
import { CertReader } from "@certd/plugin-cert";
|
||||
import { UserSettingsService } from '../../../modules/mine/service/user-settings-service.js';
|
||||
import { UserGrantSetting } from '../../../modules/mine/service/models.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { UserSettingsService } from "../../../modules/mine/service/user-settings-service.js";
|
||||
import { UserGrantSetting } from "../../../modules/mine/service/models.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
@Provide()
|
||||
@Controller('/api/pi/cert')
|
||||
@ApiTags(['pipeline-cert'])
|
||||
@Controller("/api/pi/cert")
|
||||
@ApiTags(["pipeline-cert"])
|
||||
export class CertController extends BaseController {
|
||||
@Inject()
|
||||
pipelineService: PipelineService;
|
||||
@Inject()
|
||||
storeService: StorageService;
|
||||
|
||||
|
||||
@Inject()
|
||||
userSettingsService: UserSettingsService;
|
||||
|
||||
|
||||
@Post('/get', { description: Constants.per.authOnly, summary: "获取证书" })
|
||||
async getCert(@Query('id') id: number) {
|
||||
|
||||
const {userId} = await this.getProjectUserIdRead()
|
||||
@Post("/get", { description: Constants.per.authOnly, summary: "获取证书" })
|
||||
async getCert(@Query("id") id: number) {
|
||||
const { userId } = await this.getProjectUserIdRead();
|
||||
|
||||
const pipleinUserId = await this.pipelineService.getPipelineUserId(id);
|
||||
|
||||
if (pipleinUserId !== userId) {
|
||||
// 如果是管理员,检查用户是否有授权管理员查看
|
||||
const isAdmin = await this.isAdmin()
|
||||
const isAdmin = await this.isAdmin();
|
||||
if (!isAdmin) {
|
||||
throw new PermissionException();
|
||||
}
|
||||
// 是否允许管理员查看
|
||||
const setting = await this.userSettingsService.getSetting<UserGrantSetting>(pipleinUserId,null, UserGrantSetting, false);
|
||||
const setting = await this.userSettingsService.getSetting<UserGrantSetting>(pipleinUserId, null, UserGrantSetting, false);
|
||||
if (setting?.allowAdminViewCerts !== true) {
|
||||
//不允许管理员查看
|
||||
throw new PermissionException("该流水线的用户还未授权管理员查看证书,请先让用户在”设置->授权委托“中打开开关");
|
||||
}
|
||||
}
|
||||
const privateVars = await this.storeService.getPipelinePrivateVars(id);
|
||||
|
||||
|
||||
const certInfo = privateVars.cert;
|
||||
if (certInfo?.crt) {
|
||||
const certReader = new CertReader(certInfo);
|
||||
certInfo.detail = certReader.detail
|
||||
certInfo.detail = certReader.detail;
|
||||
}
|
||||
|
||||
return this.ok(certInfo);
|
||||
}
|
||||
|
||||
|
||||
@Post('/readCertDetail', { description: Constants.per.authOnly, summary: "读取证书详情" })
|
||||
async readCertDetail(@Body('crt') crt: string) {
|
||||
@Post("/readCertDetail", { description: Constants.per.authOnly, summary: "读取证书详情" })
|
||||
async readCertDetail(@Body("crt") crt: string) {
|
||||
if (!crt) {
|
||||
throw new Error('crt is required');
|
||||
throw new Error("crt is required");
|
||||
}
|
||||
const certDetail = CertReader.readCertDetail(crt)
|
||||
const certDetail = CertReader.readCertDetail(crt);
|
||||
return this.ok(certDetail);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import { ALL, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { DnsProviderService } from '../../../modules/pipeline/service/dns-provider-service.js';
|
||||
import { BaseController } from '@certd/lib-server';
|
||||
import { Constants } from '@certd/lib-server';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { DnsProviderService } from "../../../modules/pipeline/service/dns-provider-service.js";
|
||||
import { BaseController } from "@certd/lib-server";
|
||||
import { Constants } from "@certd/lib-server";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 插件
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/pi/dnsProvider')
|
||||
@ApiTags(['pipeline-dns-provider'])
|
||||
@Controller("/api/pi/dnsProvider")
|
||||
@ApiTags(["pipeline-dns-provider"])
|
||||
export class DnsProviderController extends BaseController {
|
||||
@Inject()
|
||||
service: DnsProviderService;
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询DNS提供商列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询DNS提供商列表" })
|
||||
async list(@Query(ALL) query: any) {
|
||||
const list = this.service.getList();
|
||||
return this.ok(list);
|
||||
}
|
||||
|
||||
@Post('/dnsProviderTypeDict', { description: Constants.per.authOnly, summary: "查询DNS提供商类型字典" })
|
||||
@Post("/dnsProviderTypeDict", { description: Constants.per.authOnly, summary: "查询DNS提供商类型字典" })
|
||||
async getDnsProviderTypeDict() {
|
||||
const list = this.service.getList();
|
||||
const dict = [];
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
import {ALL, Body, Controller, Inject, Post, Provide} from '@midwayjs/core';
|
||||
import {AccessGetter, AccessService, BaseController, Constants} from '@certd/lib-server';
|
||||
import {
|
||||
AccessRequestHandleReq,
|
||||
IAccessService,
|
||||
ITaskPlugin,
|
||||
newAccess,
|
||||
newNotification,
|
||||
NotificationRequestHandleReq,
|
||||
pluginRegistry,
|
||||
PluginRequestHandleReq,
|
||||
TaskInstanceContext,
|
||||
} from '@certd/pipeline';
|
||||
import {EmailService} from '../../../modules/basic/service/email-service.js';
|
||||
import {http, HttpRequestConfig, logger, mergeUtils, utils} from '@certd/basic';
|
||||
import {NotificationService} from '../../../modules/pipeline/service/notification-service.js';
|
||||
import {TaskServiceBuilder} from "../../../modules/pipeline/service/getter/task-service-getter.js";
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
||||
import { AccessGetter, AccessService, BaseController, Constants } from "@certd/lib-server";
|
||||
import { AccessRequestHandleReq, IAccessService, ITaskPlugin, newAccess, newNotification, NotificationRequestHandleReq, pluginRegistry, PluginRequestHandleReq, TaskInstanceContext } from "@certd/pipeline";
|
||||
import { EmailService } from "../../../modules/basic/service/email-service.js";
|
||||
import { http, HttpRequestConfig, logger, mergeUtils, utils } from "@certd/basic";
|
||||
import { NotificationService } from "../../../modules/pipeline/service/notification-service.js";
|
||||
import { TaskServiceBuilder } from "../../../modules/pipeline/service/getter/task-service-getter.js";
|
||||
import { cloneDeep } from "lodash-es";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
|
||||
@Provide()
|
||||
@Controller('/api/pi/handle')
|
||||
@ApiTags(['pipeline-handle'])
|
||||
@Controller("/api/pi/handle")
|
||||
@ApiTags(["pipeline-handle"])
|
||||
export class HandleController extends BaseController {
|
||||
@Inject()
|
||||
accessService: AccessService;
|
||||
@@ -38,28 +28,28 @@ export class HandleController extends BaseController {
|
||||
@Inject()
|
||||
notificationService: NotificationService;
|
||||
|
||||
@Post('/access', { description: Constants.per.authOnly, summary: "处理授权请求" })
|
||||
@Post("/access", { description: Constants.per.authOnly, summary: "处理授权请求" })
|
||||
async accessRequest(@Body(ALL) body: AccessRequestHandleReq) {
|
||||
let {projectId,userId} = await this.getProjectUserIdRead()
|
||||
if (body.fromType === 'sys') {
|
||||
let { projectId, userId } = await this.getProjectUserIdRead();
|
||||
if (body.fromType === "sys") {
|
||||
//系统级别的请求
|
||||
const pass = await this.authService.checkPermission(this.ctx, "sys:settings:view");
|
||||
if (!pass) {
|
||||
throw new Error('权限不足');
|
||||
throw new Error("权限不足");
|
||||
}
|
||||
projectId = null
|
||||
userId = 0
|
||||
projectId = null;
|
||||
userId = 0;
|
||||
}
|
||||
|
||||
|
||||
let inputAccess = body.input;
|
||||
if (body.record.id > 0) {
|
||||
const oldEntity = await this.accessService.info(body.record.id);
|
||||
if (oldEntity) {
|
||||
if (oldEntity.userId !== userId && oldEntity.userId !== this.getUserId()) {
|
||||
throw new Error('您没有权限使用该授权');
|
||||
throw new Error("您没有权限使用该授权");
|
||||
}
|
||||
if (oldEntity.projectId && oldEntity.projectId !== projectId) {
|
||||
throw new Error('您没有权限使用该授权(projectId不匹配)');
|
||||
throw new Error("您没有权限使用该授权(projectId不匹配)");
|
||||
}
|
||||
const param: any = {
|
||||
type: body.typeName,
|
||||
@@ -69,8 +59,8 @@ export class HandleController extends BaseController {
|
||||
inputAccess = this.accessService.decryptAccessEntity(param);
|
||||
}
|
||||
}
|
||||
const accessGetter = new AccessGetter(userId,projectId, this.accessService.getById.bind(this.accessService));
|
||||
const access = await newAccess(body.typeName, inputAccess,accessGetter);
|
||||
const accessGetter = new AccessGetter(userId, projectId, this.accessService.getById.bind(this.accessService));
|
||||
const access = await newAccess(body.typeName, inputAccess, accessGetter);
|
||||
|
||||
// mergeUtils.merge(access, body.input);
|
||||
const res = await access.onRequest(body);
|
||||
@@ -78,7 +68,7 @@ export class HandleController extends BaseController {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/notification', { description: Constants.per.authOnly, summary: "处理通知请求" })
|
||||
@Post("/notification", { description: Constants.per.authOnly, summary: "处理通知请求" })
|
||||
async notificationRequest(@Body(ALL) body: NotificationRequestHandleReq) {
|
||||
const input = body.input;
|
||||
|
||||
@@ -94,9 +84,9 @@ export class HandleController extends BaseController {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/plugin', { description: Constants.per.authOnly, summary: "处理插件请求" })
|
||||
@Post("/plugin", { description: Constants.per.authOnly, summary: "处理插件请求" })
|
||||
async pluginRequest(@Body(ALL) body: PluginRequestHandleReq) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const pluginDefine = pluginRegistry.get(body.typeName);
|
||||
const pluginCls = await pluginDefine.target();
|
||||
if (pluginCls == null) {
|
||||
@@ -117,14 +107,14 @@ export class HandleController extends BaseController {
|
||||
});
|
||||
};
|
||||
|
||||
const taskServiceGetter = this.taskServiceBuilder.create({userId,projectId})
|
||||
const taskServiceGetter = this.taskServiceBuilder.create({ userId, projectId });
|
||||
|
||||
const accessGetter = await taskServiceGetter.get<IAccessService>("accessService")
|
||||
const accessGetter = await taskServiceGetter.get<IAccessService>("accessService");
|
||||
//@ts-ignore
|
||||
const taskCtx: TaskInstanceContext = {
|
||||
pipeline: undefined,
|
||||
step: undefined,
|
||||
define: cloneDeep( pluginDefine.define),
|
||||
define: cloneDeep(pluginDefine.define),
|
||||
lastStatus: undefined,
|
||||
http,
|
||||
download,
|
||||
@@ -136,7 +126,7 @@ export class HandleController extends BaseController {
|
||||
userContext: undefined,
|
||||
fileStore: undefined,
|
||||
signal: undefined,
|
||||
user: {id:userId,role:"user"},
|
||||
user: { id: userId, role: "user" },
|
||||
projectId,
|
||||
// pipelineContext: this.pipelineContext,
|
||||
// userContext: this.contextFactory.getContext('user', this.options.userId),
|
||||
@@ -147,7 +137,7 @@ export class HandleController extends BaseController {
|
||||
// }),
|
||||
// signal: this.abort.signal,
|
||||
utils,
|
||||
serviceGetter:taskServiceGetter
|
||||
serviceGetter: taskServiceGetter,
|
||||
};
|
||||
instance.setCtx(taskCtx);
|
||||
mergeUtils.merge(plugin, body.input);
|
||||
|
||||
@@ -18,8 +18,8 @@ import { ApiTags } from "@midwayjs/swagger";
|
||||
* 证书
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/pi/history')
|
||||
@ApiTags(['pipeline-history'])
|
||||
@Controller("/api/pi/history")
|
||||
@ApiTags(["pipeline-history"])
|
||||
export class HistoryController extends CrudController<HistoryService> {
|
||||
@Inject()
|
||||
service: HistoryService;
|
||||
@@ -41,10 +41,10 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询流水线执行历史分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询流水线执行历史分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.projectId = projectId;
|
||||
|
||||
const isAdmin = await this.authService.isAdmin(this.ctx);
|
||||
const publicSettings = await this.sysSettingsService.getPublicSettings();
|
||||
@@ -64,7 +64,7 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
const pipelines = await this.pipelineService.list({
|
||||
query: pipelineQuery,
|
||||
buildQuery: qb => {
|
||||
qb.andWhere('title like :title', { title: `%${pipelineTitle}%` });
|
||||
qb.andWhere("title like :title", { title: `%${pipelineTitle}%` });
|
||||
},
|
||||
});
|
||||
pipelineIds = pipelines.map(p => p.id);
|
||||
@@ -88,14 +88,14 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询流水线执行历史列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询流水线执行历史列表" })
|
||||
async list(@Body(ALL) body) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
if (!body){
|
||||
body = {}
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
if (!body) {
|
||||
body = {};
|
||||
}
|
||||
if (projectId){
|
||||
body.projectId = projectId
|
||||
if (projectId) {
|
||||
body.projectId = projectId;
|
||||
}
|
||||
|
||||
const isAdmin = this.authService.isAdmin(this.ctx);
|
||||
@@ -111,7 +111,7 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
};
|
||||
const withDetail = body.withDetail;
|
||||
delete body.withDetail;
|
||||
let select: any = null
|
||||
let select: any = null;
|
||||
if (!withDetail) {
|
||||
select = {
|
||||
pipeline: true, // 后面这里改成false
|
||||
@@ -129,9 +129,9 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
}
|
||||
const listRet = await this.getService().list({
|
||||
query: body,
|
||||
sort: { prop: 'id', asc: false },
|
||||
sort: { prop: "id", asc: false },
|
||||
buildQuery,
|
||||
select
|
||||
select,
|
||||
});
|
||||
|
||||
for (const item of listRet) {
|
||||
@@ -144,92 +144,92 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
|
||||
//@ts-ignore
|
||||
item.version = json.version;
|
||||
item.status = json.status.result
|
||||
item.status = json.status.result;
|
||||
delete item.pipeline;
|
||||
}
|
||||
|
||||
return this.ok(listRet);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加流水线执行历史" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加流水线执行历史" })
|
||||
async add(@Body(ALL) bean: PipelineEntity) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
bean.projectId = projectId
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
bean.projectId = projectId;
|
||||
bean.userId = userId;
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新流水线执行历史" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新流水线执行历史" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.getService(), bean.id,"write",true);
|
||||
await this.checkOwner(this.getService(), bean.id, "write", true);
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
return super.update(bean);
|
||||
}
|
||||
|
||||
@Post('/save', { description: Constants.per.authOnly, summary: "保存流水线执行历史" })
|
||||
@Post("/save", { description: Constants.per.authOnly, summary: "保存流水线执行历史" })
|
||||
async save(@Body(ALL) bean: HistoryEntity) {
|
||||
const { projectId,userId } = await this.getProjectUserIdWrite()
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId;
|
||||
if (bean.id > 0) {
|
||||
//修改
|
||||
delete bean.projectId;
|
||||
delete bean.userId;
|
||||
await this.checkOwner(this.getService(), bean.id,"write",true);
|
||||
await this.checkOwner(this.getService(), bean.id, "write", true);
|
||||
}
|
||||
|
||||
|
||||
await this.service.save(bean);
|
||||
return this.ok(bean.id);
|
||||
}
|
||||
|
||||
@Post('/saveLog', { description: Constants.per.authOnly, summary: "保存流水线执行日志" })
|
||||
@Post("/saveLog", { description: Constants.per.authOnly, summary: "保存流水线执行日志" })
|
||||
async saveLog(@Body(ALL) bean: HistoryLogEntity) {
|
||||
const { projectId,userId } = await this.getProjectUserIdWrite()
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
bean.projectId = projectId;
|
||||
bean.userId = userId;
|
||||
if (bean.id > 0) {
|
||||
//修改
|
||||
delete bean.projectId;
|
||||
delete bean.userId;
|
||||
await this.checkOwner(this.logService, bean.id,"write",true);
|
||||
await this.checkOwner(this.logService, bean.id, "write", true);
|
||||
}
|
||||
await this.logService.save(bean);
|
||||
return this.ok(bean.id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除流水线执行历史" })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.checkOwner(this.getService(), id,"write",true);
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除流水线执行历史" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write", true);
|
||||
await super.delete(id);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/deleteByIds', { description: Constants.per.authOnly, summary: "批量删除流水线执行历史" })
|
||||
@Post("/deleteByIds", { description: Constants.per.authOnly, summary: "批量删除流水线执行历史" })
|
||||
async deleteByIds(@Body(ALL) body: any) {
|
||||
let {userId} = await this.checkOwner(this.getService(), body.ids,"write",true);
|
||||
let { userId } = await this.checkOwner(this.getService(), body.ids, "write", true);
|
||||
const isAdmin = await this.authService.isAdmin(this.ctx);
|
||||
userId = isAdmin ? null : userId;
|
||||
await this.getService().deleteByIds(body.ids, userId);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post('/detail', { description: Constants.per.authOnly, summary: "查询流水线执行历史详情" })
|
||||
async detail(@Query('id') id: number) {
|
||||
await this.checkOwner(this.getService(), id,"read",true);
|
||||
@Post("/detail", { description: Constants.per.authOnly, summary: "查询流水线执行历史详情" })
|
||||
async detail(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read", true);
|
||||
const detail = await this.service.detail(id);
|
||||
return this.ok(detail);
|
||||
}
|
||||
|
||||
@Post('/logs', { description: Constants.per.authOnly, summary: "查询流水线执行日志" })
|
||||
async logs(@Query('id') id: number) {
|
||||
await this.checkOwner(this.logService, id,"read",true);
|
||||
@Post("/logs", { description: Constants.per.authOnly, summary: "查询流水线执行日志" })
|
||||
async logs(@Query("id") id: number) {
|
||||
await this.checkOwner(this.logService, id, "read", true);
|
||||
const logInfo = await this.logService.info(id);
|
||||
return this.ok(logInfo);
|
||||
}
|
||||
|
||||
@Post('/files', { description: Constants.per.authOnly, summary: "查询流水线执行文件" })
|
||||
async files(@Query('pipelineId') pipelineId: number, @Query('historyId') historyId: number) {
|
||||
@Post("/files", { description: Constants.per.authOnly, summary: "查询流水线执行文件" })
|
||||
async files(@Query("pipelineId") pipelineId: number, @Query("historyId") historyId: number) {
|
||||
const files = await this.getFiles(historyId, pipelineId);
|
||||
return this.ok(files);
|
||||
}
|
||||
@@ -243,24 +243,24 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
history = await this.service.getLastHistory(pipelineId);
|
||||
}
|
||||
if (history == null) {
|
||||
throw new CommonException('流水线还未运行过');
|
||||
throw new CommonException("流水线还未运行过");
|
||||
}
|
||||
const {projectId} = await this.getProjectUserIdRead()
|
||||
const { projectId } = await this.getProjectUserIdRead();
|
||||
if (projectId) {
|
||||
//enterprise模式
|
||||
if(history.projectId !== projectId){
|
||||
throw new PermissionException("您没有权限下载该流水线证书,请先加入该项目:"+history.projectId);
|
||||
if (history.projectId !== projectId) {
|
||||
throw new PermissionException("您没有权限下载该流水线证书,请先加入该项目:" + history.projectId);
|
||||
}
|
||||
//有权限下载
|
||||
}else if (history.userId !== this.getUserId()) {
|
||||
} else if (history.userId !== this.getUserId()) {
|
||||
// 如果是管理员,检查用户是否有授权管理员查看
|
||||
const isAdmin = await this.isAdmin()
|
||||
const isAdmin = await this.isAdmin();
|
||||
if (!isAdmin) {
|
||||
throw new PermissionException();
|
||||
}
|
||||
// 是否允许管理员查看
|
||||
const setting = await this.userSettingsService.getSetting<UserGrantSetting>(history.userId, null, UserGrantSetting, false);
|
||||
if (setting?.allowAdminViewCerts!==true) {
|
||||
if (setting?.allowAdminViewCerts !== true) {
|
||||
//不允许管理员查看
|
||||
throw new PermissionException("该流水线的用户还未授权管理员下载证书,请先让用户在”设置->授权委托“中打开开关");
|
||||
}
|
||||
@@ -269,12 +269,12 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
return await this.service.getFiles(history);
|
||||
}
|
||||
|
||||
@Get('/download', { description: Constants.per.authOnly, summary: "下载流水线执行文件" })
|
||||
async download(@Query('pipelineId') pipelineId: number, @Query('historyId') historyId: number, @Query('fileId') fileId: string) {
|
||||
@Get("/download", { description: Constants.per.authOnly, summary: "下载流水线执行文件" })
|
||||
async download(@Query("pipelineId") pipelineId: number, @Query("historyId") historyId: number, @Query("fileId") fileId: string) {
|
||||
const files = await this.getFiles(historyId, pipelineId);
|
||||
const file = files.find(f => f.id === fileId);
|
||||
if (file == null) {
|
||||
throw new CommonException('file not found');
|
||||
throw new CommonException("file not found");
|
||||
}
|
||||
// koa send file
|
||||
// 下载文件的名称
|
||||
@@ -284,7 +284,7 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
logger.info(`download:${path}`);
|
||||
// 以流的形式下载文件
|
||||
this.ctx.attachment(path);
|
||||
this.ctx.set('Content-Type', 'application/octet-stream');
|
||||
this.ctx.set("Content-Type", "application/octet-stream");
|
||||
|
||||
return fs.createReadStream(path);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { Constants, CrudController, ValidateException } from '@certd/lib-server';
|
||||
import { NotificationService } from '../../../modules/pipeline/service/notification-service.js';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { NotificationDefine } from '@certd/pipeline';
|
||||
import { checkPlus } from '@certd/plus-core';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Constants, CrudController, ValidateException } from "@certd/lib-server";
|
||||
import { NotificationService } from "../../../modules/pipeline/service/notification-service.js";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { NotificationDefine } from "@certd/pipeline";
|
||||
import { checkPlus } from "@certd/plus-core";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 通知
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/pi/notification')
|
||||
@ApiTags(['pipeline-notification'])
|
||||
@Controller("/api/pi/notification")
|
||||
@ApiTags(["pipeline-notification"])
|
||||
export class NotificationController extends CrudController<NotificationService> {
|
||||
@Inject()
|
||||
service: NotificationService;
|
||||
@@ -22,14 +22,14 @@ export class NotificationController extends CrudController<NotificationService>
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询通知配置分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询通知配置分页列表" })
|
||||
async page(@Body(ALL) body) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
delete body.query.userId;
|
||||
body.query.projectId = projectId;
|
||||
const buildQuery = qb => {
|
||||
qb.andWhere('user_id = :userId', { userId: userId});
|
||||
qb.andWhere("user_id = :userId", { userId: userId });
|
||||
};
|
||||
const res = await this.service.page({
|
||||
query: body.query,
|
||||
@@ -40,24 +40,24 @@ export class NotificationController extends CrudController<NotificationService>
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询通知配置列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询通知配置列表" })
|
||||
async list(@Body(ALL) body) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId;
|
||||
return super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加通知配置" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加通知配置" })
|
||||
async add(@Body(ALL) bean) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId;
|
||||
const type = bean.type;
|
||||
const define: NotificationDefine = this.service.getDefineByType(type);
|
||||
if (!define) {
|
||||
throw new ValidateException('通知类型不存在');
|
||||
throw new ValidateException("通知类型不存在");
|
||||
}
|
||||
if (define.needPlus) {
|
||||
checkPlus();
|
||||
@@ -65,18 +65,18 @@ export class NotificationController extends CrudController<NotificationService>
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新通知配置" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新通知配置" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.getService(), bean.id,"write");
|
||||
await this.checkOwner(this.getService(), bean.id, "write");
|
||||
const old = await this.service.info(bean.id);
|
||||
if (!old) {
|
||||
throw new ValidateException('通知配置不存在');
|
||||
throw new ValidateException("通知配置不存在");
|
||||
}
|
||||
if (old.type !== bean.type) {
|
||||
const type = bean.type;
|
||||
const define: NotificationDefine = this.service.getDefineByType(type);
|
||||
if (!define) {
|
||||
throw new ValidateException('通知类型不存在');
|
||||
throw new ValidateException("通知类型不存在");
|
||||
}
|
||||
if (define.needPlus) {
|
||||
checkPlus();
|
||||
@@ -86,25 +86,25 @@ export class NotificationController extends CrudController<NotificationService>
|
||||
delete bean.projectId;
|
||||
return super.update(bean);
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询通知配置详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.checkOwner(this.getService(), id,"read");
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询通知配置详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read");
|
||||
return super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除通知配置" })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.checkOwner(this.getService(), id,"write");
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除通知配置" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/define', { description: Constants.per.authOnly, summary: "查询通知插件定义" })
|
||||
async define(@Query('type') type: string) {
|
||||
@Post("/define", { description: Constants.per.authOnly, summary: "查询通知插件定义" })
|
||||
async define(@Query("type") type: string) {
|
||||
const notification = this.service.getDefineByType(type);
|
||||
return this.ok(notification);
|
||||
}
|
||||
|
||||
@Post('/getTypeDict', { description: Constants.per.authOnly, summary: "查询通知类型字典" })
|
||||
@Post("/getTypeDict", { description: Constants.per.authOnly, summary: "查询通知类型字典" })
|
||||
async getTypeDict() {
|
||||
const list: any = this.service.getDefineList();
|
||||
let dict = [];
|
||||
@@ -125,48 +125,48 @@ export class NotificationController extends CrudController<NotificationService>
|
||||
return this.ok(dict);
|
||||
}
|
||||
|
||||
@Post('/simpleInfo', { description: Constants.per.authOnly, summary: "查询通知配置简单信息" })
|
||||
async simpleInfo(@Query('id') id: number) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
@Post("/simpleInfo", { description: Constants.per.authOnly, summary: "查询通知配置简单信息" })
|
||||
async simpleInfo(@Query("id") id: number) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
if (id === 0) {
|
||||
//获取默认
|
||||
const res = await this.service.getDefault(userId,projectId);
|
||||
const res = await this.service.getDefault(userId, projectId);
|
||||
if (!res) {
|
||||
throw new ValidateException('默认通知配置不存在');
|
||||
throw new ValidateException("默认通知配置不存在");
|
||||
}
|
||||
const simple = await this.service.getSimpleInfo(res.id);
|
||||
return this.ok(simple);
|
||||
}
|
||||
await this.checkOwner(this.getService(), id,"read",true);
|
||||
await this.checkOwner(this.getService(), id, "read", true);
|
||||
const res = await this.service.getSimpleInfo(id);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/getDefaultId', { description: Constants.per.authOnly, summary: "查询默认通知配置ID" })
|
||||
@Post("/getDefaultId", { description: Constants.per.authOnly, summary: "查询默认通知配置ID" })
|
||||
async getDefaultId() {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getDefault(userId,projectId);
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getDefault(userId, projectId);
|
||||
return this.ok(res?.id);
|
||||
}
|
||||
|
||||
@Post('/setDefault', { description: Constants.per.authOnly, summary: "设置默认通知配置" })
|
||||
async setDefault(@Query('id') id: number) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
await this.checkOwner(this.getService(), id,"write");
|
||||
const res = await this.service.setDefault(id, userId,projectId);
|
||||
@Post("/setDefault", { description: Constants.per.authOnly, summary: "设置默认通知配置" })
|
||||
async setDefault(@Query("id") id: number) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
const res = await this.service.setDefault(id, userId, projectId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/getOrCreateDefault', { description: Constants.per.authOnly, summary: "获取或创建默认通知配置" })
|
||||
async getOrCreateDefault(@Body('email') email: string) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getOrCreateDefault(email, userId,projectId);
|
||||
@Post("/getOrCreateDefault", { description: Constants.per.authOnly, summary: "获取或创建默认通知配置" })
|
||||
async getOrCreateDefault(@Body("email") email: string) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const res = await this.service.getOrCreateDefault(email, userId, projectId);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/options', { description: Constants.per.authOnly, summary: "查询通知配置选项" })
|
||||
@Post("/options", { description: Constants.per.authOnly, summary: "查询通知配置选项" })
|
||||
async options() {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const res = await this.service.list({
|
||||
query: {
|
||||
userId: userId,
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { Constants, CrudController, SysSettingsService } from '@certd/lib-server';
|
||||
import { isPlus } from '@certd/plus-core';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { ApiProperty, ApiTags } from '@midwayjs/swagger';
|
||||
import { SiteInfoService } from '../../../modules/monitor/index.js';
|
||||
import { HistoryService } from '../../../modules/pipeline/service/history-service.js';
|
||||
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { PipelineEntity } from '../../../modules/pipeline/entity/pipeline.js';
|
||||
|
||||
import { Constants, CrudController, SysSettingsService } from "@certd/lib-server";
|
||||
import { isPlus } from "@certd/plus-core";
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { ApiProperty, ApiTags } from "@midwayjs/swagger";
|
||||
import { SiteInfoService } from "../../../modules/monitor/index.js";
|
||||
import { HistoryService } from "../../../modules/pipeline/service/history-service.js";
|
||||
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { PipelineEntity } from "../../../modules/pipeline/entity/pipeline.js";
|
||||
|
||||
const pipelineExample = `
|
||||
// 流水线配置示例,实际传送时要去掉注释
|
||||
@@ -67,50 +66,50 @@ const pipelineExample = `
|
||||
"notificationId": 0, // 通知ID, 0为使用默认通知
|
||||
}
|
||||
],
|
||||
}`
|
||||
}`;
|
||||
|
||||
export class PipelineSaveDTO {
|
||||
@ApiProperty({ description: 'Id,修改时必传' })
|
||||
id: number;
|
||||
userId: number;
|
||||
@ApiProperty({ description: '标题' })
|
||||
title: string;
|
||||
@ApiProperty({ description: '流水线详细配置,json格式的字符串', example: pipelineExample })
|
||||
content: string;
|
||||
@ApiProperty({ description: "Id,修改时必传" })
|
||||
id: number;
|
||||
userId: number;
|
||||
@ApiProperty({ description: "标题" })
|
||||
title: string;
|
||||
@ApiProperty({ description: "流水线详细配置,json格式的字符串", example: pipelineExample })
|
||||
content: string;
|
||||
|
||||
@ApiProperty({ description: '保留历史版本数量' })
|
||||
keepHistoryCount: number;
|
||||
@ApiProperty({ description: '分组ID' })
|
||||
groupId: number;
|
||||
@ApiProperty({ description: '备注' })
|
||||
remark: string;
|
||||
@ApiProperty({ description: '状态' })
|
||||
status: string;
|
||||
@ApiProperty({ description: '是否禁用' })
|
||||
disabled: boolean;
|
||||
@ApiProperty({ description: '类型' })
|
||||
type: string;
|
||||
webhookKey: string;
|
||||
@ApiProperty({ description: '来源' })
|
||||
from: string;
|
||||
@ApiProperty({ description: '排序' })
|
||||
order: number;
|
||||
@ApiProperty({ description: '项目ID' })
|
||||
projectId: number;
|
||||
@ApiProperty({ description: '流水线有效期,单位秒' })
|
||||
validTime: number;
|
||||
@ApiProperty({ description: '是否增加证书监控' })
|
||||
addToMonitorEnabled: boolean
|
||||
@ApiProperty({ description: '增加证书监控的域名,逗号分隔' })
|
||||
addToMonitorDomains: string
|
||||
@ApiProperty({ description: "保留历史版本数量" })
|
||||
keepHistoryCount: number;
|
||||
@ApiProperty({ description: "分组ID" })
|
||||
groupId: number;
|
||||
@ApiProperty({ description: "备注" })
|
||||
remark: string;
|
||||
@ApiProperty({ description: "状态" })
|
||||
status: string;
|
||||
@ApiProperty({ description: "是否禁用" })
|
||||
disabled: boolean;
|
||||
@ApiProperty({ description: "类型" })
|
||||
type: string;
|
||||
webhookKey: string;
|
||||
@ApiProperty({ description: "来源" })
|
||||
from: string;
|
||||
@ApiProperty({ description: "排序" })
|
||||
order: number;
|
||||
@ApiProperty({ description: "项目ID" })
|
||||
projectId: number;
|
||||
@ApiProperty({ description: "流水线有效期,单位秒" })
|
||||
validTime: number;
|
||||
@ApiProperty({ description: "是否增加证书监控" })
|
||||
addToMonitorEnabled: boolean;
|
||||
@ApiProperty({ description: "增加证书监控的域名,逗号分隔" })
|
||||
addToMonitorDomains: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 证书
|
||||
*/
|
||||
@Provide()
|
||||
@ApiTags(['pipeline'])
|
||||
@Controller('/api/pi/pipeline')
|
||||
@ApiTags(["pipeline"])
|
||||
@Controller("/api/pi/pipeline")
|
||||
export class PipelineController extends CrudController<PipelineService> {
|
||||
@Inject()
|
||||
service: PipelineService;
|
||||
@@ -124,19 +123,18 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
@Inject()
|
||||
siteInfoService: SiteInfoService;
|
||||
|
||||
|
||||
getService() {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询流水线分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询流水线分页列表" })
|
||||
async page(@Body(ALL) body) {
|
||||
const isAdmin = await this.authService.isAdmin(this.ctx);
|
||||
const publicSettings = await this.sysSettingsService.getPublicSettings();
|
||||
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
let onlyOther = false
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.projectId = projectId;
|
||||
let onlyOther = false;
|
||||
if (isAdmin) {
|
||||
if (publicSettings.managerOtherUserPipeline) {
|
||||
//管理员管理 其他用户
|
||||
@@ -157,14 +155,14 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
|
||||
const buildQuery = qb => {
|
||||
if (title) {
|
||||
qb.andWhere('(title like :title or content like :content)', { title: `%${title}%`, content: `%${title}%` });
|
||||
qb.andWhere("(title like :title or content like :content)", { title: `%${title}%`, content: `%${title}%` });
|
||||
}
|
||||
if (onlyOther) {
|
||||
qb.andWhere('user_id != :userId', { userId: this.getUserId() });
|
||||
qb.andWhere("user_id != :userId", { userId: this.getUserId() });
|
||||
}
|
||||
};
|
||||
if (!body.sort || !body.sort?.prop) {
|
||||
body.sort = { prop: 'order', asc: false };
|
||||
body.sort = { prop: "order", asc: false };
|
||||
}
|
||||
|
||||
const pageRet = await this.getService().page({
|
||||
@@ -176,31 +174,30 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
return this.ok(pageRet);
|
||||
}
|
||||
|
||||
@Post('/getSimpleByIds', { description: Constants.per.authOnly, summary: "根据ID列表获取流水线简单信息" })
|
||||
@Post("/getSimpleByIds", { description: Constants.per.authOnly, summary: "根据ID列表获取流水线简单信息" })
|
||||
async getSimpleById(@Body(ALL) body) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const ret = await this.getService().getSimplePipelines(body.ids, userId, projectId);
|
||||
return this.ok(ret);
|
||||
}
|
||||
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly })
|
||||
@Post("/add", { description: Constants.per.authOnly })
|
||||
async add(@Body(ALL) bean: PipelineEntity) {
|
||||
return await this.save(bean as any);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly })
|
||||
async update(@Body(ALL) bean:PipelineEntity) {
|
||||
await this.checkOwner(this.getService(), bean.id,"write",true);
|
||||
await this.service.update(bean as any);
|
||||
return this.ok({});
|
||||
@Post("/update", { description: Constants.per.authOnly })
|
||||
async update(@Body(ALL) bean: PipelineEntity) {
|
||||
await this.checkOwner(this.getService(), bean.id, "write", true);
|
||||
await this.service.update(bean as any);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/save', { description: Constants.per.authOnly, summary: '新增/更新流水线' })
|
||||
@Post("/save", { description: Constants.per.authOnly, summary: "新增/更新流水线" })
|
||||
async save(@Body() bean: PipelineSaveDTO) {
|
||||
const { userId ,projectId} = await this.getProjectUserIdWrite()
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
if (bean.id > 0) {
|
||||
const {userId,projectId} = await this.checkOwner(this.getService(), bean.id,"write",true);
|
||||
const { userId, projectId } = await this.checkOwner(this.getService(), bean.id, "write", true);
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId;
|
||||
} else {
|
||||
@@ -210,7 +207,7 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
|
||||
if (!this.isAdmin()) {
|
||||
// 非管理员用户 不允许设置流水线有效期
|
||||
delete bean.validTime
|
||||
delete bean.validTime;
|
||||
}
|
||||
|
||||
const { version } = await this.service.save(bean as any);
|
||||
@@ -229,63 +226,62 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
return this.ok({ id: bean.id, version: version });
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除流水线" })
|
||||
async delete(@Query('id') id: number) {
|
||||
await this.checkOwner(this.getService(), id,"write",true);
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除流水线" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write", true);
|
||||
await this.service.delete(id);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/disabled', { description: Constants.per.authOnly, summary: "禁用流水线" })
|
||||
@Post("/disabled", { description: Constants.per.authOnly, summary: "禁用流水线" })
|
||||
async disabled(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.getService(), bean.id,"write",true);
|
||||
await this.checkOwner(this.getService(), bean.id, "write", true);
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
await this.service.disabled(bean.id, bean.disabled);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/detail', { description: Constants.per.authOnly, summary: "查询流水线详情" })
|
||||
async detail(@Query('id') id: number) {
|
||||
await this.checkOwner(this.getService(), id,"read",true);
|
||||
@Post("/detail", { description: Constants.per.authOnly, summary: "查询流水线详情" })
|
||||
async detail(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read", true);
|
||||
const detail = await this.service.detail(id);
|
||||
return this.ok(detail);
|
||||
}
|
||||
|
||||
@Post('/trigger', { description: Constants.per.authOnly, summary: "触发流水线执行" })
|
||||
async trigger(@Query('id') id: number, @Query('stepId') stepId?: string) {
|
||||
await this.checkOwner(this.getService(), id,"write",true);
|
||||
@Post("/trigger", { description: Constants.per.authOnly, summary: "触发流水线执行" })
|
||||
async trigger(@Query("id") id: number, @Query("stepId") stepId?: string) {
|
||||
await this.checkOwner(this.getService(), id, "write", true);
|
||||
await this.service.trigger(id, stepId, true);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/cancel', { description: Constants.per.authOnly, summary: "取消流水线执行" })
|
||||
async cancel(@Query('historyId') historyId: number) {
|
||||
await this.checkOwner(this.historyService, historyId,"write",true);
|
||||
@Post("/cancel", { description: Constants.per.authOnly, summary: "取消流水线执行" })
|
||||
async cancel(@Query("historyId") historyId: number) {
|
||||
await this.checkOwner(this.historyService, historyId, "write", true);
|
||||
await this.service.cancel(historyId);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/count', { description: Constants.per.authOnly, summary: "查询流水线数量" })
|
||||
@Post("/count", { description: Constants.per.authOnly, summary: "查询流水线数量" })
|
||||
async count() {
|
||||
const { userId } = await this.getProjectUserIdRead()
|
||||
const { userId } = await this.getProjectUserIdRead();
|
||||
const count = await this.service.count({ userId: userId });
|
||||
return this.ok({ count });
|
||||
}
|
||||
|
||||
|
||||
private async checkPermissionCall(callback:any){
|
||||
let { projectId ,userId} = await this.getProjectUserIdWrite()
|
||||
if(projectId){
|
||||
return await callback({userId,projectId});
|
||||
private async checkPermissionCall(callback: any) {
|
||||
let { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
if (projectId) {
|
||||
return await callback({ userId, projectId });
|
||||
}
|
||||
const isAdmin = await this.authService.isAdmin(this.ctx);
|
||||
userId = isAdmin ? undefined : userId;
|
||||
return await callback({userId});
|
||||
return await callback({ userId });
|
||||
}
|
||||
|
||||
@Post('/batchDelete', { description: Constants.per.authOnly, summary: "批量删除流水线" })
|
||||
async batchDelete(@Body('ids') ids: number[]) {
|
||||
@Post("/batchDelete", { description: Constants.per.authOnly, summary: "批量删除流水线" })
|
||||
async batchDelete(@Body("ids") ids: number[]) {
|
||||
// let { projectId ,userId} = await this.getProjectUserIdWrite()
|
||||
// if(projectId){
|
||||
// await this.service.batchDelete(ids, null,projectId);
|
||||
@@ -295,16 +291,14 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
// userId = isAdmin ? undefined : userId;
|
||||
// await this.service.batchDelete(ids, userId);
|
||||
// return this.ok({});
|
||||
await this.checkPermissionCall(async ({userId,projectId})=>{
|
||||
await this.service.batchDelete(ids, userId,projectId);
|
||||
})
|
||||
return this.ok({})
|
||||
await this.checkPermissionCall(async ({ userId, projectId }) => {
|
||||
await this.service.batchDelete(ids, userId, projectId);
|
||||
});
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Post('/batchUpdateGroup', { description: Constants.per.authOnly, summary: "批量更新流水线分组" })
|
||||
async batchUpdateGroup(@Body('ids') ids: number[], @Body('groupId') groupId: number) {
|
||||
@Post("/batchUpdateGroup", { description: Constants.per.authOnly, summary: "批量更新流水线分组" })
|
||||
async batchUpdateGroup(@Body("ids") ids: number[], @Body("groupId") groupId: number) {
|
||||
// let { projectId ,userId} = await this.getProjectUserIdWrite()
|
||||
// if(projectId){
|
||||
// await this.service.batchUpdateGroup(ids, groupId, null,projectId);
|
||||
@@ -314,15 +308,14 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
// const isAdmin = await this.authService.isAdmin(this.ctx);
|
||||
// userId = isAdmin ? undefined : this.getUserId();
|
||||
// await this.service.batchUpdateGroup(ids, groupId, userId);
|
||||
await this.checkPermissionCall(async ({userId,projectId})=>{
|
||||
await this.service.batchUpdateGroup(ids, groupId, userId,projectId);
|
||||
})
|
||||
await this.checkPermissionCall(async ({ userId, projectId }) => {
|
||||
await this.service.batchUpdateGroup(ids, groupId, userId, projectId);
|
||||
});
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
|
||||
@Post('/batchUpdateTrigger', { description: Constants.per.authOnly, summary: "批量更新流水线触发器" })
|
||||
async batchUpdateTrigger(@Body('ids') ids: number[], @Body('trigger') trigger: any) {
|
||||
@Post("/batchUpdateTrigger", { description: Constants.per.authOnly, summary: "批量更新流水线触发器" })
|
||||
async batchUpdateTrigger(@Body("ids") ids: number[], @Body("trigger") trigger: any) {
|
||||
// let { projectId ,userId} = await this.getProjectUserIdWrite()
|
||||
// if(projectId){
|
||||
// await this.service.batchUpdateTrigger(ids, trigger, null,projectId);
|
||||
@@ -332,54 +325,53 @@ export class PipelineController extends CrudController<PipelineService> {
|
||||
// const isAdmin = await this.authService.isAdmin(this.ctx);
|
||||
// userId = isAdmin ? undefined : this.getUserId();
|
||||
// await this.service.batchUpdateTrigger(ids, trigger, userId);
|
||||
await this.checkPermissionCall(async ({userId,projectId})=>{
|
||||
await this.service.batchUpdateTrigger(ids, trigger, userId,projectId);
|
||||
})
|
||||
await this.checkPermissionCall(async ({ userId, projectId }) => {
|
||||
await this.service.batchUpdateTrigger(ids, trigger, userId, projectId);
|
||||
});
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/batchUpdateNotification', { description: Constants.per.authOnly, summary: "批量更新流水线通知" })
|
||||
async batchUpdateNotification(@Body('ids') ids: number[], @Body('notification') notification: any) {
|
||||
@Post("/batchUpdateNotification", { description: Constants.per.authOnly, summary: "批量更新流水线通知" })
|
||||
async batchUpdateNotification(@Body("ids") ids: number[], @Body("notification") notification: any) {
|
||||
// const isAdmin = await this.authService.isAdmin(this.ctx);
|
||||
// const userId = isAdmin ? undefined : this.getUserId();
|
||||
// await this.service.batchUpdateNotifications(ids, notification, userId);
|
||||
await this.checkPermissionCall(async ({userId,projectId})=>{
|
||||
await this.service.batchUpdateNotifications(ids, notification, userId,projectId);
|
||||
})
|
||||
await this.checkPermissionCall(async ({ userId, projectId }) => {
|
||||
await this.service.batchUpdateNotifications(ids, notification, userId, projectId);
|
||||
});
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/batchUpdateCertApplyOptions', { description: Constants.per.authOnly, summary: "批量更新证书申请任务配置" })
|
||||
async batchUpdateCertApplyOptions(@Body('ids') ids: number[], @Body('options') options: any) {
|
||||
await this.checkPermissionCall(async ({userId,projectId})=>{
|
||||
await this.service.batchUpdateCertApplyOptions(ids, options, userId,projectId);
|
||||
})
|
||||
@Post("/batchUpdateCertApplyOptions", { description: Constants.per.authOnly, summary: "批量更新证书申请任务配置" })
|
||||
async batchUpdateCertApplyOptions(@Body("ids") ids: number[], @Body("options") options: any) {
|
||||
await this.checkPermissionCall(async ({ userId, projectId }) => {
|
||||
await this.service.batchUpdateCertApplyOptions(ids, options, userId, projectId);
|
||||
});
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/batchRerun', { description: Constants.per.authOnly, summary: "批量重新运行流水线" })
|
||||
async batchRerun(@Body('ids') ids: number[], @Body('force') force: boolean) {
|
||||
await this.checkPermissionCall(async ({userId,projectId})=>{
|
||||
await this.service.batchRerun(ids, force,userId,projectId);
|
||||
})
|
||||
@Post("/batchRerun", { description: Constants.per.authOnly, summary: "批量重新运行流水线" })
|
||||
async batchRerun(@Body("ids") ids: number[], @Body("force") force: boolean) {
|
||||
await this.checkPermissionCall(async ({ userId, projectId }) => {
|
||||
await this.service.batchRerun(ids, force, userId, projectId);
|
||||
});
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/batchTransfer', { description: Constants.per.authOnly, summary: "批量迁移流水线" })
|
||||
async batchTransfer(@Body('ids') ids: number[], @Body('toProjectId') toProjectId: number) {
|
||||
await this.checkPermissionCall(async ({})=>{
|
||||
@Post("/batchTransfer", { description: Constants.per.authOnly, summary: "批量迁移流水线" })
|
||||
async batchTransfer(@Body("ids") ids: number[], @Body("toProjectId") toProjectId: number) {
|
||||
await this.checkPermissionCall(async ({}) => {
|
||||
await this.service.batchTransfer(ids, toProjectId);
|
||||
})
|
||||
});
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/refreshWebhookKey', { description: Constants.per.authOnly, summary: "刷新Webhook密钥" })
|
||||
async refreshWebhookKey(@Body('id') id: number) {
|
||||
await this.checkOwner(this.getService(), id,"write",true);
|
||||
@Post("/refreshWebhookKey", { description: Constants.per.authOnly, summary: "刷新Webhook密钥" })
|
||||
async refreshWebhookKey(@Body("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write", true);
|
||||
const res = await this.service.refreshWebhookKey(id);
|
||||
return this.ok({
|
||||
webhookKey: res,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+21
-21
@@ -1,15 +1,15 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { Constants, CrudController } from '@certd/lib-server';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { PipelineGroupService } from '../../../modules/pipeline/service/pipeline-group-service.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Constants, CrudController } from "@certd/lib-server";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { PipelineGroupService } from "../../../modules/pipeline/service/pipeline-group-service.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 通知
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/pi/pipeline/group')
|
||||
@ApiTags(['pipeline-group'])
|
||||
@Controller("/api/pi/pipeline/group")
|
||||
@ApiTags(["pipeline-group"])
|
||||
export class PipelineGroupController extends CrudController<PipelineGroupService> {
|
||||
@Inject()
|
||||
service: PipelineGroupService;
|
||||
@@ -20,14 +20,14 @@ export class PipelineGroupController extends CrudController<PipelineGroupService
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询流水线分组分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询流水线分组分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
delete body.query.userId;
|
||||
body.query.projectId = projectId;
|
||||
const buildQuery = qb => {
|
||||
qb.andWhere('user_id = :userId', { userId: userId });
|
||||
qb.andWhere("user_id = :userId", { userId: userId });
|
||||
};
|
||||
const res = await this.service.page({
|
||||
query: body.query,
|
||||
@@ -38,45 +38,45 @@ export class PipelineGroupController extends CrudController<PipelineGroupService
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询流水线分组列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询流水线分组列表" })
|
||||
async list(@Body(ALL) body: any) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId;
|
||||
return await super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加流水线分组" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加流水线分组" })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId;
|
||||
return await super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新流水线分组" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新流水线分组" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.getService(), bean.id, "write");
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
return await super.update(bean);
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询流水线分组详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询流水线分组详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read");
|
||||
return await super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除流水线分组" })
|
||||
async delete(@Query('id') id: number) {
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除流水线分组" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
return await super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/all', { description: Constants.per.authOnly, summary: "查询所有流水线分组" })
|
||||
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有流水线分组" })
|
||||
async all() {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const list: any = await this.service.find({
|
||||
where: {
|
||||
userId: userId,
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { BaseController, Constants } from '@certd/lib-server';
|
||||
import { PluginService } from '../../../modules/plugin/service/plugin-service.js';
|
||||
import { PluginConfigService } from '../../../modules/plugin/service/plugin-config-service.js';
|
||||
import {pluginGroups} from "@certd/pipeline";
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { BaseController, Constants } from "@certd/lib-server";
|
||||
import { PluginService } from "../../../modules/plugin/service/plugin-service.js";
|
||||
import { PluginConfigService } from "../../../modules/plugin/service/plugin-config-service.js";
|
||||
import { pluginGroups } from "@certd/pipeline";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 插件
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/pi/plugin')
|
||||
@ApiTags(['pipeline-plugin'])
|
||||
@Controller("/api/pi/plugin")
|
||||
@ApiTags(["pipeline-plugin"])
|
||||
export class PluginController extends BaseController {
|
||||
@Inject()
|
||||
service: PluginService;
|
||||
@@ -18,39 +18,39 @@ export class PluginController extends BaseController {
|
||||
@Inject()
|
||||
pluginConfigService: PluginConfigService;
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询插件列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询插件列表" })
|
||||
async list(@Query(ALL) query: any) {
|
||||
const list = await this.service.getEnabledBuiltInList();
|
||||
return this.ok(list);
|
||||
}
|
||||
|
||||
@Post('/groups', { description: Constants.per.authOnly, summary: "查询插件分组" })
|
||||
@Post("/groups", { description: Constants.per.authOnly, summary: "查询插件分组" })
|
||||
async groups(@Query(ALL) query: any) {
|
||||
const group = await this.service.getEnabledBuildInGroup();
|
||||
return this.ok(group);
|
||||
}
|
||||
|
||||
@Post('/groupsList', { description: Constants.per.authOnly, summary: "查询插件分组列表" })
|
||||
@Post("/groupsList", { description: Constants.per.authOnly, summary: "查询插件分组列表" })
|
||||
async groupsList(@Query(ALL) query: any) {
|
||||
const groups = pluginGroups
|
||||
const groupsList:any = []
|
||||
const groups = pluginGroups;
|
||||
const groupsList: any = [];
|
||||
for (const key in groups) {
|
||||
const group = {
|
||||
...groups[key]
|
||||
}
|
||||
delete group.plugins
|
||||
groupsList.push(group)
|
||||
...groups[key],
|
||||
};
|
||||
delete group.plugins;
|
||||
groupsList.push(group);
|
||||
}
|
||||
return this.ok(groupsList);
|
||||
}
|
||||
|
||||
@Post('/getDefineByType', { description: Constants.per.authOnly, summary: "根据类型获取插件定义" })
|
||||
async getDefineByType(@Body('type') type: string) {
|
||||
@Post("/getDefineByType", { description: Constants.per.authOnly, summary: "根据类型获取插件定义" })
|
||||
async getDefineByType(@Body("type") type: string) {
|
||||
const define = await this.service.getDefineByType(type);
|
||||
return this.ok(define);
|
||||
}
|
||||
|
||||
@Post('/config', { description: Constants.per.authOnly, summary: "获取插件配置" })
|
||||
@Post("/config", { description: Constants.per.authOnly, summary: "获取插件配置" })
|
||||
async config(@Body(ALL) body: { id?: number; name?: string; type: string }) {
|
||||
const config = await this.pluginConfigService.getPluginConfig(body);
|
||||
return this.ok(config);
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { Constants, CrudController } from '@certd/lib-server';
|
||||
import { DomainParser } from '@certd/plugin-cert';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { Constants, CrudController } from "@certd/lib-server";
|
||||
import { DomainParser } from "@certd/plugin-cert";
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { SubDomainService } from "../../../modules/pipeline/service/sub-domain-service.js";
|
||||
import { TaskServiceBuilder } from '../../../modules/pipeline/service/getter/task-service-getter.js';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { TaskServiceBuilder } from "../../../modules/pipeline/service/getter/task-service-getter.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 子域名托管
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/pi/subDomain')
|
||||
@ApiTags(['pipeline-subdomain'])
|
||||
@Controller("/api/pi/subDomain")
|
||||
@ApiTags(["pipeline-subdomain"])
|
||||
export class SubDomainController extends CrudController<SubDomainService> {
|
||||
@Inject()
|
||||
service: SubDomainService;
|
||||
@@ -22,25 +22,24 @@ export class SubDomainController extends CrudController<SubDomainService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
@Post('/parseDomain', { description: Constants.per.authOnly, summary: "解析域名" })
|
||||
async parseDomain(@Body("fullDomain") fullDomain:string) {
|
||||
const {projectId,userId} = await this.getProjectUserIdRead();
|
||||
@Post("/parseDomain", { description: Constants.per.authOnly, summary: "解析域名" })
|
||||
async parseDomain(@Body("fullDomain") fullDomain: string) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
const taskService = this.taskServiceBuilder.create({ userId: userId, projectId: projectId });
|
||||
const subDomainGetter = await taskService.getSubDomainsGetter();
|
||||
const domainParser = new DomainParser(subDomainGetter)
|
||||
const domain = await domainParser.parse(fullDomain)
|
||||
const domainParser = new DomainParser(subDomainGetter);
|
||||
const domain = await domainParser.parse(fullDomain);
|
||||
return this.ok(domain);
|
||||
}
|
||||
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询子域名分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询子域名分页列表" })
|
||||
async page(@Body(ALL) body) {
|
||||
const {userId,projectId} = await this.getProjectUserIdRead();
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
delete body.query.userId;
|
||||
body.query.projectId = projectId;
|
||||
const buildQuery = qb => {
|
||||
qb.andWhere('user_id = :userId', { userId: userId });
|
||||
qb.andWhere("user_id = :userId", { userId: userId });
|
||||
};
|
||||
const res = await this.service.page({
|
||||
query: body.query,
|
||||
@@ -51,45 +50,45 @@ export class SubDomainController extends CrudController<SubDomainService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询子域名列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询子域名列表" })
|
||||
async list(@Body(ALL) body) {
|
||||
const {userId,projectId} = await this.getProjectUserIdRead();
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
body.query = body.query ?? {};
|
||||
body.query.userId = userId;
|
||||
body.query.projectId = projectId;
|
||||
return super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加子域名" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加子域名" })
|
||||
async add(@Body(ALL) bean) {
|
||||
const {userId,projectId} = await this.getProjectUserIdRead();
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId;
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新子域名" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新子域名" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.getService(), bean.id, "write");
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
return super.update(bean);
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询子域名详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询子域名详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "read");
|
||||
return super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除子域名" })
|
||||
async delete(@Query('id') id: number) {
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除子域名" })
|
||||
async delete(@Query("id") id: number) {
|
||||
await this.checkOwner(this.getService(), id, "write");
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Post('/batchDelete', { description: Constants.per.authOnly, summary: "批量删除子域名" })
|
||||
async batchDelete(@Body('ids') ids: number[]) {
|
||||
const {userId,projectId} = await this.getProjectUserIdWrite();
|
||||
@Post("/batchDelete", { description: Constants.per.authOnly, summary: "批量删除子域名" })
|
||||
async batchDelete(@Body("ids") ids: number[]) {
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
await this.service.batchDelete(ids, userId, projectId);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import {ALL, Body, Controller, Inject, Post, Provide, Query} from '@midwayjs/core';
|
||||
import {Constants, CrudController} from '@certd/lib-server';
|
||||
import { TemplateService } from '../../../modules/pipeline/service/template-service.js';
|
||||
import { checkPlus } from '@certd/plus-core';
|
||||
import { ApiTags } from '@midwayjs/swagger';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { Constants, CrudController } from "@certd/lib-server";
|
||||
import { TemplateService } from "../../../modules/pipeline/service/template-service.js";
|
||||
import { checkPlus } from "@certd/plus-core";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
|
||||
/**
|
||||
* 流水线模版
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/pi/template')
|
||||
@ApiTags(['pipeline-template'])
|
||||
@Controller("/api/pi/template")
|
||||
@ApiTags(["pipeline-template"])
|
||||
export class TemplateController extends CrudController<TemplateService> {
|
||||
@Inject()
|
||||
service: TemplateService;
|
||||
@@ -18,17 +18,15 @@ export class TemplateController extends CrudController<TemplateService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
|
||||
@Post('/page', { description: Constants.per.authOnly, summary: "查询流水线模版分页列表" })
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询流水线模版分页列表" })
|
||||
async page(@Body(ALL) body) {
|
||||
|
||||
body.query = body.query ?? {};
|
||||
delete body.query.userId;
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.projectId = projectId;
|
||||
|
||||
const buildQuery = qb => {
|
||||
qb.andWhere('user_id = :userId', { userId: userId });
|
||||
qb.andWhere("user_id = :userId", { userId: userId });
|
||||
};
|
||||
const res = await this.service.page({
|
||||
query: body.query,
|
||||
@@ -39,63 +37,63 @@ export class TemplateController extends CrudController<TemplateService> {
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post('/list', { description: Constants.per.authOnly, summary: "查询流水线模版列表" })
|
||||
@Post("/list", { description: Constants.per.authOnly, summary: "查询流水线模版列表" })
|
||||
async list(@Body(ALL) body) {
|
||||
body.query = body.query ?? {};
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
body.query.projectId = projectId
|
||||
body.query.userId = userId
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
body.query.projectId = projectId;
|
||||
body.query.userId = userId;
|
||||
return super.list(body);
|
||||
}
|
||||
|
||||
@Post('/add', { description: Constants.per.authOnly, summary: "添加流水线模版" })
|
||||
@Post("/add", { description: Constants.per.authOnly, summary: "添加流水线模版" })
|
||||
async add(@Body(ALL) bean) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead()
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
bean.userId = userId;
|
||||
bean.projectId = projectId
|
||||
checkPlus()
|
||||
bean.projectId = projectId;
|
||||
checkPlus();
|
||||
return super.add(bean);
|
||||
}
|
||||
|
||||
@Post('/update', { description: Constants.per.authOnly, summary: "更新流水线模版" })
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新流水线模版" })
|
||||
async update(@Body(ALL) bean) {
|
||||
await this.checkOwner(this.service, bean.id, "write");
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
return super.update(bean);
|
||||
}
|
||||
@Post('/info', { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
|
||||
async info(@Query('id') id: number) {
|
||||
await this.checkOwner(this.service, id, "read");
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
await this.checkOwner(this.service, id, "read");
|
||||
return super.info(id);
|
||||
}
|
||||
|
||||
@Post('/delete', { description: Constants.per.authOnly, summary: "删除流水线模版" })
|
||||
async delete(@Query('id') id: number) {
|
||||
const { userId ,projectId } = await this.getProjectUserIdWrite()
|
||||
await this.service.batchDelete([id], userId,projectId);
|
||||
@Post("/delete", { description: Constants.per.authOnly, summary: "删除流水线模版" })
|
||||
async delete(@Query("id") id: number) {
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
await this.service.batchDelete([id], userId, projectId);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/batchDelete', { description: Constants.per.authOnly, summary: "批量删除流水线模版" })
|
||||
async batchDelete(@Body('ids') ids: number[]) {
|
||||
const { userId ,projectId } = await this.getProjectUserIdWrite()
|
||||
await this.service.batchDelete(ids, userId,projectId);
|
||||
@Post("/batchDelete", { description: Constants.per.authOnly, summary: "批量删除流水线模版" })
|
||||
async batchDelete(@Body("ids") ids: number[]) {
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
await this.service.batchDelete(ids, userId, projectId);
|
||||
return this.ok({});
|
||||
}
|
||||
|
||||
@Post('/detail', { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
|
||||
async detail(@Query('id') id: number) {
|
||||
const { userId ,projectId } = await this.getProjectUserIdRead()
|
||||
const detail = await this.service.detail(id, userId,projectId);
|
||||
@Post("/detail", { description: Constants.per.authOnly, summary: "查询流水线模版详情" })
|
||||
async detail(@Query("id") id: number) {
|
||||
const { userId, projectId } = await this.getProjectUserIdRead();
|
||||
const detail = await this.service.detail(id, userId, projectId);
|
||||
return this.ok(detail);
|
||||
}
|
||||
@Post('/createPipelineByTemplate', { description: Constants.per.authOnly, summary: "根据模版创建流水线" })
|
||||
@Post("/createPipelineByTemplate", { description: Constants.per.authOnly, summary: "根据模版创建流水线" })
|
||||
async createPipelineByTemplate(@Body(ALL) body: any) {
|
||||
const { userId ,projectId } = await this.getProjectUserIdWrite()
|
||||
const { userId, projectId } = await this.getProjectUserIdWrite();
|
||||
body.userId = userId;
|
||||
body.projectId = projectId
|
||||
checkPlus()
|
||||
body.projectId = projectId;
|
||||
checkPlus();
|
||||
const res = await this.service.createPipelineByTemplate(body);
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user