mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
refactor(audit-manager): optimize the logic of getting metadata (#5814)
* chore: optmize log output * chore: optmize log output
This commit is contained in:
parent
2cb4304a38
commit
21bd55422f
@ -284,6 +284,8 @@ export class AuditManager {
|
||||
const auditLog: AuditLog = this.formatAuditData(ctx);
|
||||
auditLog.uuid = reqId;
|
||||
auditLog.status = ctx.status;
|
||||
const defaultMetaData = await this.getDefaultMetaData(ctx);
|
||||
auditLog.metadata = { ...metadata, ...defaultMetaData };
|
||||
if (typeof action !== 'string') {
|
||||
if (action.getUserInfo) {
|
||||
const userInfo = await action.getUserInfo(ctx);
|
||||
@ -298,10 +300,15 @@ export class AuditManager {
|
||||
}
|
||||
if (action.getMetaData) {
|
||||
const extra = await action.getMetaData(ctx);
|
||||
auditLog.metadata = { ...metadata, ...extra };
|
||||
} else {
|
||||
const defaultMetaData = await this.getDefaultMetaData(ctx);
|
||||
auditLog.metadata = { ...metadata, ...defaultMetaData };
|
||||
if (extra) {
|
||||
if (extra.request) {
|
||||
auditLog.metadata.request = { ...auditLog.metadata.request, ...extra.request };
|
||||
}
|
||||
if (extra.response) {
|
||||
auditLog.metadata.response = { ...auditLog.metadata.response, ...extra.response };
|
||||
}
|
||||
auditLog.metadata = { ...extra, ...auditLog.metadata };
|
||||
}
|
||||
}
|
||||
if (action.getSourceAndTarget) {
|
||||
const sourceAndTarget = await action.getSourceAndTarget(ctx);
|
||||
@ -312,9 +319,6 @@ export class AuditManager {
|
||||
auditLog.targetRecordUK = sourceAndTarget.targetRecordUK;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const defaultMetaData = await this.getDefaultMetaData(ctx);
|
||||
auditLog.metadata = { ...metadata, ...defaultMetaData };
|
||||
}
|
||||
this.logger.log(auditLog);
|
||||
} catch (err) {
|
||||
|
@ -129,20 +129,10 @@ export class PluginAuthServer extends Plugin {
|
||||
}
|
||||
return {
|
||||
request: {
|
||||
params: ctx.request?.params,
|
||||
body: {
|
||||
...ctx.request?.body,
|
||||
password: undefined,
|
||||
},
|
||||
path: ctx.request?.path,
|
||||
headers: {
|
||||
'x-authenticator': ctx.request?.headers['x-authenticator'],
|
||||
'x-locale': ctx.request?.headers['x-locale'],
|
||||
'x-timezone': ctx.request?.headers['x-timezone'],
|
||||
},
|
||||
},
|
||||
response: {
|
||||
body,
|
||||
},
|
||||
};
|
||||
},
|
||||
@ -180,24 +170,11 @@ export class PluginAuthServer extends Plugin {
|
||||
getMetaData: async (ctx: any) => {
|
||||
return {
|
||||
request: {
|
||||
params: ctx.request?.params,
|
||||
body: {
|
||||
...ctx.request?.body,
|
||||
password: undefined,
|
||||
confirm_password: undefined,
|
||||
},
|
||||
path: ctx.request?.path,
|
||||
headers: {
|
||||
'x-authenticator': ctx.request?.headers['x-authenticator'],
|
||||
'x-locale': ctx.request?.headers['x-locale'],
|
||||
'x-timezone': ctx.request?.headers['x-timezone'],
|
||||
},
|
||||
},
|
||||
response: {
|
||||
body: {
|
||||
...ctx.response?.body,
|
||||
token: undefined,
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
@ -207,15 +184,7 @@ export class PluginAuthServer extends Plugin {
|
||||
getMetaData: async (ctx: any) => {
|
||||
return {
|
||||
request: {
|
||||
params: ctx.request.params,
|
||||
query: ctx.request.query,
|
||||
body: {},
|
||||
path: ctx.request.path,
|
||||
headers: {
|
||||
'x-authenticator': ctx.request?.headers['x-authenticator'],
|
||||
'x-locale': ctx.request?.headers['x-locale'],
|
||||
'x-timezone': ctx.request?.headers['x-timezone'],
|
||||
},
|
||||
},
|
||||
response: {
|
||||
body: {},
|
||||
|
@ -154,16 +154,10 @@ export default class PluginUsersServer extends Plugin {
|
||||
const getMetaDataForUpdateProfileAction = async (ctx: any) => {
|
||||
return {
|
||||
request: {
|
||||
params: ctx.request.params,
|
||||
query: ctx.request.query,
|
||||
body: {
|
||||
...ctx.request.body,
|
||||
password: '******',
|
||||
},
|
||||
path: ctx.request.path,
|
||||
},
|
||||
response: {
|
||||
body: ctx.body,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user