Browse Source

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

3.2.1-prepare
旺阳 11 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'"> <if test="resourceType != null and resourceType == 'USER'">
select user_name from t_ds_user where id = #{resourceId} select user_name from t_ds_user where id = #{resourceId}
</if> </if>
<if test="resourceType != null and resourceType == 'PROJECT'">
select name from t_ds_project where id = #{resourceId}
</if>
</select> </select>
</mapper> </mapper>

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

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