mirror of
https://github.com/certd/certd.git
synced 2026-07-25 13:17:36 +08:00
chore: audit log first
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { CrudController } from "@certd/lib-server";
|
||||
import { PermissionService } from "../../../modules/sys/authority/service/permission-service.js";
|
||||
import { AuditType, AuditAction } from "../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
* 权限资源
|
||||
@@ -28,7 +29,13 @@ export class PermissionController extends CrudController<PermissionService> {
|
||||
@Body(ALL)
|
||||
bean
|
||||
) {
|
||||
return await super.add(bean);
|
||||
const res = await super.add(bean);
|
||||
await this.auditLog({
|
||||
type: AuditType.permission,
|
||||
action: AuditAction.add,
|
||||
content: `新增了权限「${bean.name}」(ID:${res.data})`,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/update", { description: "sys:auth:per:edit" })
|
||||
@@ -36,14 +43,26 @@ export class PermissionController extends CrudController<PermissionService> {
|
||||
@Body(ALL)
|
||||
bean
|
||||
) {
|
||||
return await super.update(bean);
|
||||
const res = await super.update(bean);
|
||||
await this.auditLog({
|
||||
type: AuditType.permission,
|
||||
action: AuditAction.update,
|
||||
content: `修改了权限「${bean.name}」(ID:${bean.id})`,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
@Post("/delete", { description: "sys:auth:per:remove" })
|
||||
async delete(
|
||||
@Query("id")
|
||||
id: number
|
||||
) {
|
||||
return await super.delete(id);
|
||||
const res = await super.delete(id);
|
||||
await this.auditLog({
|
||||
type: AuditType.permission,
|
||||
action: AuditAction.delete,
|
||||
content: `删除了权限(ID:${id})`,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/tree", { description: "sys:auth:per:view" })
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { CrudController } from "@certd/lib-server";
|
||||
import { RoleService } from "../../../modules/sys/authority/service/role-service.js";
|
||||
import { AuditType, AuditAction } from "../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
@@ -34,7 +35,13 @@ export class RoleController extends CrudController<RoleService> {
|
||||
@Body(ALL)
|
||||
bean
|
||||
) {
|
||||
return await super.add(bean);
|
||||
const res = await super.add(bean);
|
||||
await this.auditLog({
|
||||
type: AuditType.role,
|
||||
action: AuditAction.add,
|
||||
content: `新增了角色「${bean.name}」(ID:${res.data})`,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/update", { description: "sys:auth:role:edit" })
|
||||
@@ -42,7 +49,13 @@ export class RoleController extends CrudController<RoleService> {
|
||||
@Body(ALL)
|
||||
bean
|
||||
) {
|
||||
return await super.update(bean);
|
||||
const res = await super.update(bean);
|
||||
await this.auditLog({
|
||||
type: AuditType.role,
|
||||
action: AuditAction.update,
|
||||
content: `修改了角色「${bean.name}」(ID:${bean.id})`,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
@Post("/delete", { description: "sys:auth:role:remove" })
|
||||
async delete(
|
||||
@@ -52,7 +65,13 @@ export class RoleController extends CrudController<RoleService> {
|
||||
if (id === 1) {
|
||||
throw new Error("不能删除默认的管理员角色");
|
||||
}
|
||||
return await super.delete(id);
|
||||
const res = await super.delete(id);
|
||||
await this.auditLog({
|
||||
type: AuditType.role,
|
||||
action: AuditAction.delete,
|
||||
content: `删除了角色(ID:${id})`,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/getPermissionTree", { description: "sys:auth:role:view" })
|
||||
|
||||
@@ -6,6 +6,7 @@ import { PermissionService } from "../../../modules/sys/authority/service/permis
|
||||
import { Constants } from "@certd/lib-server";
|
||||
import { In } from "typeorm";
|
||||
import { LoginService } from "../../../modules/login/service/login-service.js";
|
||||
import { AuditType, AuditAction } from "../../modules/sys/enterprise/service/audit-constants.js";
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
@@ -97,7 +98,13 @@ export class UserController extends CrudController<UserService> {
|
||||
@Body(ALL)
|
||||
bean
|
||||
) {
|
||||
return await super.add(bean);
|
||||
const res = await super.add(bean);
|
||||
await this.auditLog({
|
||||
type: AuditType.user,
|
||||
action: AuditAction.add,
|
||||
content: `新增了用户「${bean.username}」(ID:${res.data})`,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/update", { description: "sys:auth:user:edit" })
|
||||
@@ -105,7 +112,13 @@ export class UserController extends CrudController<UserService> {
|
||||
@Body(ALL)
|
||||
bean
|
||||
) {
|
||||
return await super.update(bean);
|
||||
const res = await super.update(bean);
|
||||
await this.auditLog({
|
||||
type: AuditType.user,
|
||||
action: AuditAction.update,
|
||||
content: `修改了用户「${bean.username}」(ID:${bean.id})`,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
@Post("/delete", { description: "sys:auth:user:remove" })
|
||||
@@ -119,7 +132,13 @@ export class UserController extends CrudController<UserService> {
|
||||
if (id === 3) {
|
||||
throw new Error("不能删除默认的普通用户角色");
|
||||
}
|
||||
return await super.delete(id);
|
||||
const res = await super.delete(id);
|
||||
await this.auditLog({
|
||||
type: AuditType.user,
|
||||
action: AuditAction.delete,
|
||||
content: `删除了用户(ID:${id})`,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user