Browse Source

[Improvement][User] Query all users filter un enabled. (#11504)

* user query all filter un enabled
* restore permissions
3.1.0-release
JiPeng Wang 2 years ago committed by GitHub
parent
commit
961e67f524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
  2. 3
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java
  3. 9
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserMapper.java
  4. 6
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml

9
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java

@ -80,7 +80,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -977,13 +976,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
putMsg(result, Status.USER_NO_OPERATION_PERM); putMsg(result, Status.USER_NO_OPERATION_PERM);
return result; return result;
} }
List<User> userList = userMapper.queryEnabledUsers();
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.ge("id", 0);
if (loginUser.getUserType().equals(UserType.GENERAL_USER)) {
queryWrapper.eq("id", loginUser.getId());
}
List<User> userList = userMapper.selectList(null);
result.put(Constants.DATA_LIST, userList); result.put(Constants.DATA_LIST, userList);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);

3
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java

@ -252,7 +252,6 @@ public class UsersServiceTest {
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
user.setId(1); user.setId(1);
//no operate
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN,null, 1, USER_MANAGER, serviceLogger)).thenReturn(true); Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN,null, 1, USER_MANAGER, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0, serviceLogger)).thenReturn(false); Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0, serviceLogger)).thenReturn(false);
Map<String, Object> result = usersService.queryUserList(user); Map<String, Object> result = usersService.queryUserList(user);
@ -263,7 +262,7 @@ public class UsersServiceTest {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN,null, 1, USER_MANAGER, serviceLogger)).thenReturn(true); Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ACCESS_TOKEN,null, 1, USER_MANAGER, serviceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0, serviceLogger)).thenReturn(true); Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ACCESS_TOKEN, null, 0, serviceLogger)).thenReturn(true);
user.setUserType(UserType.ADMIN_USER); user.setUserType(UserType.ADMIN_USER);
when(userMapper.selectList(null)).thenReturn(getUserList()); when(userMapper.queryEnabledUsers()).thenReturn(getUserList());
result = usersService.queryUserList(user); result = usersService.queryUserList(user);
List<User> userList = (List<User>) result.get(Constants.DATA_LIST); List<User> userList = (List<User>) result.get(Constants.DATA_LIST);
Assert.assertTrue(userList.size() > 0); Assert.assertTrue(userList.size() > 0);

9
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserMapper.java

@ -174,13 +174,8 @@ public interface UserMapper extends BaseMapper<User> {
List<User> queryAuthedUserListByProjectId(@Param("projectId") int projectId); List<User> queryAuthedUserListByProjectId(@Param("projectId") int projectId);
/** /**
* list authorized User * query enabled users
* @param userId
* @param resourcesIds
* @param <T>
* @return * @return
*/ */
<T> List<User> listAuthorizedUsersList (@Param("userId") int userId, @Param("resourcesIds")T[] resourcesIds); List<User> queryEnabledUsers();
} }

6
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml

@ -131,4 +131,10 @@
from t_ds_user u, t_ds_relation_project_user rel from t_ds_user u, t_ds_relation_project_user rel
where u.id = rel.user_id and rel.project_id = #{projectId} where u.id = rel.user_id and rel.project_id = #{projectId}
</select> </select>
<select id="queryEnabledUsers" resultType="org.apache.dolphinscheduler.dao.entity.User">
select
<include refid="baseSql"/>
from t_ds_user
where state = 1
</select>
</mapper> </mapper>

Loading…
Cancel
Save