Browse Source

[Bug] [Audit log] Fix Audit log UI query error (#15427)

3.2.1-prepare
旺阳 12 months ago committed by GitHub
parent
commit
e5a512803e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AuditLogMapper.xml
  2. 32
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AuditLogMapperTest.java

3
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AuditLogMapper.xml

@ -60,5 +60,8 @@
<if test="resourceType != null and resourceType == 'USER'">
select user_name from t_ds_user where id = #{resourceId}
</if>
<if test="resourceType != null and resourceType == 'PROJECT'">
select name from t_ds_project where id = #{resourceId}
</if>
</select>
</mapper>

32
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AuditLogMapperTest.java

@ -17,8 +17,10 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.AuditResourceType;
import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.Project;
import java.util.Date;
@ -34,26 +36,41 @@ public class AuditLogMapperTest extends BaseDaoTest {
@Autowired
AuditLogMapper logMapper;
@Autowired
private ProjectMapper projectMapper;
/**
* insert
* @return
*/
private void insertOne() {
private void insertOne(AuditResourceType resourceType) {
AuditLog auditLog = new AuditLog();
auditLog.setUserId(1);
auditLog.setTime(new Date());
auditLog.setResourceType(0);
auditLog.setResourceType(resourceType.getCode());
auditLog.setOperation(0);
auditLog.setResourceId(0);
logMapper.insert(auditLog);
}
private Project insertProject() {
Project project = new Project();
project.setName("ut project");
project.setUserId(111);
project.setCode(1L);
project.setCreateTime(new Date());
project.setUpdateTime(new Date());
projectMapper.insert(project);
return project;
}
/**
* test page query
*/
@Test
public void testQueryAuditLog() {
insertOne();
insertOne(AuditResourceType.USER_MODULE);
insertOne(AuditResourceType.PROJECT_MODULE);
Page<AuditLog> page = new Page<>(1, 3);
int[] resourceType = new int[0];
int[] operationType = new int[0];
@ -64,7 +81,12 @@ public class AuditLogMapperTest extends BaseDaoTest {
@Test
public void testQueryResourceNameByType() {
String resourceName = logMapper.queryResourceNameByType("USER", 1);
Assertions.assertEquals("admin", resourceName);
String resourceNameByUser = logMapper.queryResourceNameByType(AuditResourceType.USER_MODULE.getMsg(), 1);
Assertions.assertEquals("admin", resourceNameByUser);
Project project = insertProject();
String resourceNameByProject = logMapper.queryResourceNameByType(AuditResourceType.PROJECT_MODULE.getMsg(), 1);
Assertions.assertEquals(project.getName(), resourceNameByProject);
int delete = projectMapper.deleteById(project.getId());
Assertions.assertEquals(delete, 1);
}
}

Loading…
Cancel
Save