mirror of
https://github.com/certd/certd.git
synced 2026-07-17 19:47:34 +08:00
feat: 支持审计日志,操作日志
This commit is contained in:
@@ -8,6 +8,7 @@ import { logger } from "@certd/basic";
|
||||
import dayjs from "dayjs";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { CertReader } from "@certd/plugin-lib";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -29,6 +30,10 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.monitor;
|
||||
}
|
||||
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询证书分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
@@ -117,7 +122,9 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
const { projectId, userId } = await this.getProjectUserIdWrite();
|
||||
bean.projectId = projectId;
|
||||
bean.userId = userId;
|
||||
return await super.add(bean);
|
||||
const res = await super.add(bean);
|
||||
this.auditLog({ content: `新增了证书(ID:${res.data})` });
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/update", { description: Constants.per.authOnly, summary: "更新证书" })
|
||||
@@ -125,7 +132,9 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
await this.checkOwner(this.service, bean.id, "write");
|
||||
delete bean.userId;
|
||||
delete bean.projectId;
|
||||
return await super.update(bean);
|
||||
const res = await super.update(bean);
|
||||
this.auditLog({ content: `修改了证书(ID:${bean.id})` });
|
||||
return res;
|
||||
}
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询证书详情" })
|
||||
async info(@Query("id") id: number) {
|
||||
@@ -136,7 +145,9 @@ export class CertInfoController extends CrudController<CertInfoService> {
|
||||
@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);
|
||||
const res = await super.delete(id);
|
||||
this.auditLog({ content: `删除了证书(ID:${id})` });
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/all", { description: Constants.per.authOnly, summary: "查询所有证书" })
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ApiTags } from "@midwayjs/swagger";
|
||||
import { SiteInfoService } from "../../../modules/monitor/index.js";
|
||||
import { JobHistoryService } from "../../../modules/monitor/service/job-history-service.js";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -22,6 +23,10 @@ export class JobHistoryController extends CrudController<JobHistoryService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.jobHistory;
|
||||
}
|
||||
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询监控运行历史分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
@@ -54,12 +59,15 @@ export class JobHistoryController extends CrudController<JobHistoryService> {
|
||||
@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);
|
||||
const res = await super.delete(id);
|
||||
this.auditLog({ content: `删除了监控运行历史(ID:${id})` });
|
||||
return res;
|
||||
}
|
||||
@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);
|
||||
this.auditLog({ content: `批量删除了${ids.length}条监控运行历史` });
|
||||
return this.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { merge } from "lodash-es";
|
||||
import { SiteIpService } from "../../../modules/monitor/service/site-ip-service.js";
|
||||
import { utils } from "@certd/basic";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { AuditType, AuditAction } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -25,6 +25,10 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.monitor;
|
||||
}
|
||||
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询站点监控分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
@@ -76,8 +80,6 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
this.service.check(entity.id, true, 0);
|
||||
}
|
||||
this.auditLog({
|
||||
type: AuditType.monitor,
|
||||
action: AuditAction.add,
|
||||
content: `新增了站点监控「${bean.name}」(ID:${res.id}, 域名:${bean.domain})`,
|
||||
});
|
||||
return this.ok(res);
|
||||
@@ -94,8 +96,6 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
this.service.check(entity.id, true, 0);
|
||||
}
|
||||
this.auditLog({
|
||||
type: AuditType.monitor,
|
||||
action: AuditAction.update,
|
||||
content: `修改了站点监控「${bean.name}」(ID:${bean.id})`,
|
||||
});
|
||||
return this.ok();
|
||||
@@ -111,8 +111,6 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
await this.checkOwner(this.service, id, "write");
|
||||
const res = await super.delete(id);
|
||||
this.auditLog({
|
||||
type: AuditType.monitor,
|
||||
action: AuditAction.delete,
|
||||
content: `删除了站点监控(ID:${id})`,
|
||||
});
|
||||
return res;
|
||||
@@ -121,11 +119,9 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
@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 count = await this.service.batchDelete(body.ids, userId, projectId);
|
||||
this.auditLog({
|
||||
type: AuditType.monitor,
|
||||
action: AuditAction.batchDelete,
|
||||
content: `批量删除了${body.ids.length}条站点监控`,
|
||||
content: `批量删除了${count}条站点监控`,
|
||||
});
|
||||
return this.ok();
|
||||
}
|
||||
@@ -154,6 +150,7 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
userId,
|
||||
projectId,
|
||||
});
|
||||
this.auditLog({ content: "导入了站点监控" });
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@@ -191,6 +188,7 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
projectId: projectId,
|
||||
key,
|
||||
});
|
||||
this.auditLog({ content: "删除了站点监控导入任务" });
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@@ -203,6 +201,7 @@ export class SiteInfoController extends CrudController<SiteInfoService> {
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
});
|
||||
this.auditLog({ content: "开始了站点监控导入任务" });
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { AuthService } from "../../../modules/sys/authority/service/auth-service
|
||||
import { SiteIpService } from "../../../modules/monitor/service/site-ip-service.js";
|
||||
import { SiteInfoService } from "../../../modules/monitor/index.js";
|
||||
import { ApiTags } from "@midwayjs/swagger";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -22,6 +23,10 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.siteIp;
|
||||
}
|
||||
|
||||
@Post("/page", { description: Constants.per.authOnly, summary: "查询站点IP分页列表" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
const { projectId, userId } = await this.getProjectUserIdRead();
|
||||
@@ -57,6 +62,7 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
const { domain, httpsPort } = siteEntity;
|
||||
this.service.check(res.id, domain, httpsPort);
|
||||
}
|
||||
this.auditLog({ content: `新增了站点IP(ID:${res.id})` });
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@@ -71,6 +77,7 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
const { domain, httpsPort } = siteEntity;
|
||||
this.service.check(siteEntity.id, domain, httpsPort);
|
||||
}
|
||||
this.auditLog({ content: `修改了站点IP(ID:${bean.id})` });
|
||||
return this.ok();
|
||||
}
|
||||
@Post("/info", { description: Constants.per.authOnly, summary: "查询站点IP详情" })
|
||||
@@ -85,6 +92,7 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
const entity = await this.service.info(id);
|
||||
const res = await super.delete(id);
|
||||
await this.service.updateIpCount(entity.siteId);
|
||||
this.auditLog({ content: `删除了站点IP(ID:${id})` });
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -124,6 +132,7 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
||||
siteId: body.siteId,
|
||||
projectId,
|
||||
});
|
||||
this.auditLog({ content: "导入了站点IP" });
|
||||
return this.ok();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user