Skip to content

Commit

Permalink
fix(操作日志): 登出操作日志记录 #1005204
Browse files Browse the repository at this point in the history
--bug=1005204 --user=赵勇 【系统设置-操作日志】... https://www.tapd.cn/55049933/s/1027443
  • Loading branch information
fit2-zhao committed Jul 21, 2021
1 parent 423a399 commit 4114edd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ResultHolder currentUser() {
}

@GetMapping(value = "/signout")
@MsAuditLog(module = "auth_title", type = OperLogConstants.LOGIN, title = "登出")
@MsAuditLog(module = "auth_title", beforeEvent = "#msClass.getUserId(id)",type = OperLogConstants.LOGIN, title = "登出",msClass = SessionUtils.class)
public ResultHolder logout() throws Exception {
userService.logout();
SecurityUtils.getSubject().logout();
Expand Down
34 changes: 19 additions & 15 deletions backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,26 @@ public void before(JoinPoint joinPoint) {
for (int len = 0; len < params.length; len++) {
context.setVariable(params[len], args[len]);
}
for (Class clazz : msLog.msClass()) {
context.setVariable("msClass", applicationContext.getBean(clazz));
}
Expression expression = parser.parseExpression(msLog.beforeEvent());
String beforeContent = expression.getValue(context, String.class);
InvocationHandler invocationHandler = Proxy.getInvocationHandler(msLog);
Field value = invocationHandler.getClass().getDeclaredField("memberValues");
value.setAccessible(true);
Map<String, Object> memberValues = (Map<String, Object>) value.get(invocationHandler);
memberValues.put("beforeValue", beforeContent);
}
if (msLog != null && StringUtils.isEmpty(msLog.operUser())) {
InvocationHandler invocationHandler = Proxy.getInvocationHandler(msLog);
Field value = invocationHandler.getClass().getDeclaredField("memberValues");
value.setAccessible(true);
Map<String, Object> memberValues = (Map<String, Object>) value.get(invocationHandler);
memberValues.put("operUser", SessionUtils.getUserId());
boolean isNext = false;
for (Class clazz : msLog.msClass()) {
if (clazz.getName().equals("io.metersphere.commons.utils.SessionUtils")) {
Map<String, Object> memberValues = (Map<String, Object>) value.get(invocationHandler);
memberValues.put("operUser", SessionUtils.getUserId());
continue;
}
context.setVariable("msClass", applicationContext.getBean(clazz));
isNext = true;
}
if (isNext) {
Expression expression = parser.parseExpression(msLog.beforeEvent());
String beforeContent = expression.getValue(context, String.class);
Map<String, Object> memberValues = (Map<String, Object>) value.get(invocationHandler);
memberValues.put("beforeValue", beforeContent);
}
}

} catch (Exception e) {
LogUtil.error(e.getMessage());
}
Expand Down Expand Up @@ -147,6 +148,9 @@ public void saveLog(JoinPoint joinPoint) {
}

for (Class clazz : msLog.msClass()) {
if (clazz.getName().equals("io.metersphere.commons.utils.SessionUtils")) {
continue;
}
context.setVariable("msClass", applicationContext.getBean(clazz));
}
// 项目ID 表达式
Expand Down

0 comments on commit 4114edd

Please sign in to comment.