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);
|
const auditLog: AuditLog = this.formatAuditData(ctx);
|
||||||
auditLog.uuid = reqId;
|
auditLog.uuid = reqId;
|
||||||
auditLog.status = ctx.status;
|
auditLog.status = ctx.status;
|
||||||
|
const defaultMetaData = await this.getDefaultMetaData(ctx);
|
||||||
|
auditLog.metadata = { ...metadata, ...defaultMetaData };
|
||||||
if (typeof action !== 'string') {
|
if (typeof action !== 'string') {
|
||||||
if (action.getUserInfo) {
|
if (action.getUserInfo) {
|
||||||
const userInfo = await action.getUserInfo(ctx);
|
const userInfo = await action.getUserInfo(ctx);
|
||||||
@ -298,10 +300,15 @@ export class AuditManager {
|
|||||||
}
|
}
|
||||||
if (action.getMetaData) {
|
if (action.getMetaData) {
|
||||||
const extra = await action.getMetaData(ctx);
|
const extra = await action.getMetaData(ctx);
|
||||||
auditLog.metadata = { ...metadata, ...extra };
|
if (extra) {
|
||||||
} else {
|
if (extra.request) {
|
||||||
const defaultMetaData = await this.getDefaultMetaData(ctx);
|
auditLog.metadata.request = { ...auditLog.metadata.request, ...extra.request };
|
||||||
auditLog.metadata = { ...metadata, ...defaultMetaData };
|
}
|
||||||
|
if (extra.response) {
|
||||||
|
auditLog.metadata.response = { ...auditLog.metadata.response, ...extra.response };
|
||||||
|
}
|
||||||
|
auditLog.metadata = { ...extra, ...auditLog.metadata };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (action.getSourceAndTarget) {
|
if (action.getSourceAndTarget) {
|
||||||
const sourceAndTarget = await action.getSourceAndTarget(ctx);
|
const sourceAndTarget = await action.getSourceAndTarget(ctx);
|
||||||
@ -312,9 +319,6 @@ export class AuditManager {
|
|||||||
auditLog.targetRecordUK = sourceAndTarget.targetRecordUK;
|
auditLog.targetRecordUK = sourceAndTarget.targetRecordUK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const defaultMetaData = await this.getDefaultMetaData(ctx);
|
|
||||||
auditLog.metadata = { ...metadata, ...defaultMetaData };
|
|
||||||
}
|
}
|
||||||
this.logger.log(auditLog);
|
this.logger.log(auditLog);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -129,20 +129,10 @@ export class PluginAuthServer extends Plugin {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
request: {
|
request: {
|
||||||
params: ctx.request?.params,
|
|
||||||
body: {
|
body: {
|
||||||
...ctx.request?.body,
|
...ctx.request?.body,
|
||||||
password: undefined,
|
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) => {
|
getMetaData: async (ctx: any) => {
|
||||||
return {
|
return {
|
||||||
request: {
|
request: {
|
||||||
params: ctx.request?.params,
|
|
||||||
body: {
|
body: {
|
||||||
...ctx.request?.body,
|
...ctx.request?.body,
|
||||||
password: undefined,
|
password: undefined,
|
||||||
confirm_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) => {
|
getMetaData: async (ctx: any) => {
|
||||||
return {
|
return {
|
||||||
request: {
|
request: {
|
||||||
params: ctx.request.params,
|
|
||||||
query: ctx.request.query,
|
|
||||||
body: {},
|
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: {
|
response: {
|
||||||
body: {},
|
body: {},
|
||||||
|
@ -154,16 +154,10 @@ export default class PluginUsersServer extends Plugin {
|
|||||||
const getMetaDataForUpdateProfileAction = async (ctx: any) => {
|
const getMetaDataForUpdateProfileAction = async (ctx: any) => {
|
||||||
return {
|
return {
|
||||||
request: {
|
request: {
|
||||||
params: ctx.request.params,
|
|
||||||
query: ctx.request.query,
|
|
||||||
body: {
|
body: {
|
||||||
...ctx.request.body,
|
...ctx.request.body,
|
||||||
password: '******',
|
password: '******',
|
||||||
},
|
},
|
||||||
path: ctx.request.path,
|
|
||||||
},
|
|
||||||
response: {
|
|
||||||
body: ctx.body,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user