mirror of
https://github.com/certd/certd.git
synced 2026-07-29 08:37:36 +08:00
feat: 支持审计日志,操作日志
This commit is contained in:
@@ -2,6 +2,7 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/c
|
||||
import { CrudController } from "@certd/lib-server";
|
||||
import { merge } from "lodash-es";
|
||||
import { CnameProviderService } from "../../../modules/cname/service/cname-provider-service.js";
|
||||
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
* 授权
|
||||
@@ -16,6 +17,10 @@ export class CnameRecordController extends CrudController<CnameProviderService>
|
||||
return this.service;
|
||||
}
|
||||
|
||||
getAuditType(): string {
|
||||
return AuditType.cname;
|
||||
}
|
||||
|
||||
@Post("/page", { description: "sys:settings:view" })
|
||||
async page(@Body(ALL) body: any) {
|
||||
body.query = body.query ?? {};
|
||||
@@ -27,7 +32,7 @@ export class CnameRecordController extends CrudController<CnameProviderService>
|
||||
return super.list(body);
|
||||
}
|
||||
|
||||
@Post("/add", { description: "sys:settings:edit" })
|
||||
@Post("/add", { description: "sys:settings:edit", summary: "添加CNAME服务" })
|
||||
async add(@Body(ALL) bean: any) {
|
||||
const def: any = {
|
||||
isDefault: false,
|
||||
@@ -35,13 +40,17 @@ export class CnameRecordController extends CrudController<CnameProviderService>
|
||||
};
|
||||
merge(bean, def);
|
||||
bean.userId = this.getUserId();
|
||||
return super.add(bean);
|
||||
const res = await super.add(bean);
|
||||
await this.auditLog({ content: `添加了CNAME服务(ID:${res.data})` });
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/update", { description: "sys:settings:edit" })
|
||||
@Post("/update", { description: "sys:settings:edit", summary: "更新CNAME服务" })
|
||||
async update(@Body(ALL) bean: any) {
|
||||
bean.userId = this.getUserId();
|
||||
return super.update(bean);
|
||||
const res = await super.update(bean);
|
||||
await this.auditLog({ content: `更新了CNAME服务(ID:${bean.id})` });
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/info", { description: "sys:settings:view" })
|
||||
@@ -49,26 +58,31 @@ export class CnameRecordController extends CrudController<CnameProviderService>
|
||||
return super.info(id);
|
||||
}
|
||||
|
||||
@Post("/delete", { description: "sys:settings:edit" })
|
||||
@Post("/delete", { description: "sys:settings:edit", summary: "删除CNAME服务" })
|
||||
async delete(@Query("id") id: number) {
|
||||
return super.delete(id);
|
||||
const res = await super.delete(id);
|
||||
await this.auditLog({ content: `删除了CNAME服务(ID:${id})` });
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/deleteByIds", { description: "sys:settings:edit" })
|
||||
@Post("/deleteByIds", { description: "sys:settings:edit", summary: "批量删除CNAME服务" })
|
||||
async deleteByIds(@Body("ids") ids: number[]) {
|
||||
const res = await this.service.delete(ids);
|
||||
await this.auditLog({ content: `批量删除了${ids.length}条CNAME服务` });
|
||||
return this.ok(res);
|
||||
}
|
||||
|
||||
@Post("/setDefault", { description: "sys:settings:edit" })
|
||||
@Post("/setDefault", { description: "sys:settings:edit", summary: "设置默认CNAME服务" })
|
||||
async setDefault(@Body("id") id: number) {
|
||||
await this.service.setDefault(id);
|
||||
await this.auditLog({ content: `设置了默认CNAME服务(ID:${id})` });
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
@Post("/setDisabled", { description: "sys:settings:edit" })
|
||||
@Post("/setDisabled", { description: "sys:settings:edit", summary: "禁用/启用CNAME服务" })
|
||||
async setDisabled(@Body("id") id: number, @Body("disabled") disabled: boolean) {
|
||||
await this.service.setDisabled(id, disabled);
|
||||
await this.auditLog({ content: `${disabled ? "禁用" : "启用"}了CNAME服务(ID:${id})` });
|
||||
return this.ok();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user