chore: audit log first

This commit is contained in:
xiaojunnuo
2026-07-10 19:24:42 +08:00
parent edda1b57f3
commit 4250d0e266
33 changed files with 1396 additions and 77 deletions
@@ -3,6 +3,7 @@ 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 { AuditType, AuditAction } from "../../../modules/sys/enterprise/service/audit-constants.js";
/**
*/
@@ -14,7 +15,6 @@ export class OpenKeyController extends CrudController<OpenKeyService> {
service: OpenKeyService;
@Inject()
authService: AuthService;
getService(): OpenKeyService {
return this.service;
}
@@ -57,6 +57,11 @@ export class OpenKeyController extends CrudController<OpenKeyService> {
body.projectId = projectId;
body.userId = userId;
const res = await this.service.add(body);
this.auditLog({
type: AuditType.openKey,
action: AuditAction.add,
content: `新增了API密钥(ID:${res.id}, scope:${body.scope})`,
});
return this.ok(res);
}
@@ -66,6 +71,11 @@ export class OpenKeyController extends CrudController<OpenKeyService> {
delete bean.userId;
delete bean.projectId;
await this.service.update(bean);
this.auditLog({
type: AuditType.openKey,
action: AuditAction.update,
content: `修改了API密钥(ID:${bean.id})`,
});
return this.ok();
}
@Post("/info", { description: Constants.per.authOnly, summary: "查询开放API密钥详情" })
@@ -90,7 +100,13 @@ export class OpenKeyController extends CrudController<OpenKeyService> {
@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);
const res = await super.delete(id);
this.auditLog({
type: AuditType.openKey,
action: AuditAction.delete,
content: `删除了API密钥(ID:${id})`,
});
return res;
}
@Post("/getApiToken", { description: Constants.per.authOnly, summary: "获取API测试令牌" })