mirror of
https://github.com/certd/certd.git
synced 2026-07-26 05:37:36 +08:00
chore: 继续完善审计日志
This commit is contained in:
@@ -14,7 +14,6 @@ describe("AuditLogContext type", () => {
|
||||
append: ["ID:5"],
|
||||
content: "删除了流水线(ID:5)",
|
||||
projectId: 3,
|
||||
projectName: "默认项目",
|
||||
enabled: true,
|
||||
};
|
||||
|
||||
|
||||
@@ -12,11 +12,33 @@ export type AuditLogContext = {
|
||||
append?: string | string[];
|
||||
content?: string;
|
||||
projectId?: number;
|
||||
projectName?: string;
|
||||
enabled?: boolean;
|
||||
allowAnonymous?: boolean;
|
||||
scope?: string;
|
||||
userId?: number;
|
||||
username?: string;
|
||||
success?: boolean;
|
||||
};
|
||||
|
||||
/** 审计日志方法的参数类型 */
|
||||
export type AuditLogParam = {
|
||||
type?: string;
|
||||
action?: string;
|
||||
content?: string;
|
||||
append?: string | string[];
|
||||
projectId?: number;
|
||||
userId?: number;
|
||||
username?: string;
|
||||
};
|
||||
|
||||
/** AuditService.log() 参数类型 */
|
||||
export type AuditLogWriteParam = {
|
||||
userId: number;
|
||||
type: string;
|
||||
action: string;
|
||||
content: string;
|
||||
username?: string;
|
||||
projectId?: number;
|
||||
ipAddress?: string;
|
||||
scope?: string;
|
||||
success?: boolean;
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { IMidwayContainer } from "@midwayjs/core";
|
||||
import * as koa from "@midwayjs/koa";
|
||||
import { Constants } from "./constants.js";
|
||||
import { isEnterprise } from "./mode.js";
|
||||
import type { AuditLogContext } from "./audit.js";
|
||||
import type { AuditLogContext, AuditLogParam } from "./audit.js";
|
||||
|
||||
export abstract class BaseController {
|
||||
@Inject()
|
||||
@@ -133,7 +133,7 @@ export abstract class BaseController {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
auditLog(bean: { type?: string; action?: string; content?: string; append?: string | string[]; projectId?: number; userId?: number; username?: string } = {}) {
|
||||
auditLog(bean: AuditLogParam = {}) {
|
||||
const auditLog = this.ensureAuditLogContext();
|
||||
auditLog.enabled = true;
|
||||
if (bean.userId != null) {
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import { createRequestParamDecorator } from "@midwayjs/core";
|
||||
|
||||
export const AuditLog = (opts: { enabled?: boolean }) => {
|
||||
export const AuditLog = (opts: { type?: string; action?: string; content?: string; enabled?: boolean } = {}) => {
|
||||
return createRequestParamDecorator(ctx => {
|
||||
if (!ctx.auditLog) {
|
||||
ctx.auditLog = {};
|
||||
}
|
||||
if (opts.enabled !== undefined) {
|
||||
ctx.auditLog.enabled = opts.enabled || true;
|
||||
ctx.auditLog.enabled = opts.enabled !== false;
|
||||
if (opts.type != null) {
|
||||
ctx.auditLog.type = opts.type;
|
||||
}
|
||||
if (opts.action != null) {
|
||||
ctx.auditLog.action = opts.action;
|
||||
}
|
||||
if (opts.content != null) {
|
||||
ctx.auditLog.content = opts.content;
|
||||
}
|
||||
return ctx.auditLog;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user