未验证 提交 fcf4110e 编写于 作者: W WangJPLeo 提交者: GitHub

resource modules query fix. (#10687)

上级 1b86394d
......@@ -109,7 +109,7 @@ public class AlertGroupController extends BaseController {
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result list(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
Map<String, Object> result = alertGroupService.queryAlertgroup();
Map<String, Object> result = alertGroupService.queryAlertgroup(loginUser);
return returnDataList(result);
}
......
......@@ -212,7 +212,7 @@ public class EnvironmentController extends BaseController {
@ApiException(QUERY_ENVIRONMENT_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryAllEnvironmentList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
Map<String, Object> result = environmentService.queryAllEnvironmentList();
Map<String, Object> result = environmentService.queryAllEnvironmentList(loginUser);
return returnDataList(result);
}
......
......@@ -135,7 +135,7 @@ public class WorkerGroupController extends BaseController {
@ApiException(QUERY_WORKER_GROUP_FAIL)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryAllWorkerGroups(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
Map<String, Object> result = workerGroupService.queryAllGroup();
Map<String, Object> result = workerGroupService.queryAllGroup(loginUser);
return returnDataList(result);
}
......
......@@ -30,9 +30,10 @@ public interface AlertGroupService {
/**
* query alert group list
*
* @param loginUser
* @return alert group list
*/
Map<String, Object> queryAlertgroup();
Map<String, Object> queryAlertgroup(User loginUser);
/**
* query alert group by id
......
......@@ -86,9 +86,10 @@ public interface EnvironmentService {
/**
* query all environment
*
* @param loginUser
* @return all environment list
*/
Map<String, Object> queryAllEnvironmentList();
Map<String, Object> queryAllEnvironmentList(User loginUser);
/**
* verify environment name
......
......@@ -52,9 +52,10 @@ public interface WorkerGroupService {
/**
* query all worker group
*
* @param loginUser
* @return all worker group list
*/
Map<String, Object> queryAllGroup();
Map<String, Object> queryAllGroup(User loginUser);
/**
* delete worker group by id
......
......@@ -64,16 +64,26 @@ public class AlertGroupServiceImpl extends BaseServiceImpl implements AlertGroup
/**
* query alert group list
*
* @param loginUser
* @return alert group list
*/
@Override
public Map<String, Object> queryAlertgroup() {
public Map<String, Object> queryAlertgroup(User loginUser) {
HashMap<String, Object> result = new HashMap<>();
List<AlertGroup> alertGroups = alertGroupMapper.queryAllGroupList();
List<AlertGroup> alertGroups;
if (loginUser.getUserType().equals(UserType.ADMIN_USER)) {
alertGroups = alertGroupMapper.queryAllGroupList();
} else {
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.ALERT_GROUP, loginUser.getId(), logger);
if (ids.isEmpty()) {
result.put(Constants.DATA_LIST, Collections.emptyList());
putMsg(result, Status.SUCCESS);
return result;
}
alertGroups = alertGroupMapper.selectBatchIds(ids);
}
result.put(Constants.DATA_LIST, alertGroups);
putMsg(result, Status.SUCCESS);
return result;
}
......
......@@ -54,6 +54,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -305,14 +306,19 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
Map<String, Object> result = new HashMap<>();
List<DataSource> datasourceList = null;
if (canOperatorPermissions(loginUser,null,AuthorizationType.DATASOURCE,DATASOURCE_UPDATE)){
datasourceList = dataSourceMapper.queryDataSourceByType(UserType.ADMIN_USER.equals(loginUser.getUserType()) ? 0 : loginUser.getId(), type);
if (loginUser.getUserType().equals(UserType.ADMIN_USER)) {
datasourceList = dataSourceMapper.queryDataSourceByType(0, type);
} else {
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.DATASOURCE, loginUser.getId(), logger);
if (ids.isEmpty()) {
result.put(Constants.DATA_LIST, Collections.emptyList());
putMsg(result, Status.SUCCESS);
return result;
}
datasourceList = dataSourceMapper.selectBatchIds(ids).stream().filter(dataSource -> dataSource.getType().getCode() == type).collect(Collectors.toList());
}
result.put(Constants.DATA_LIST, datasourceList);
putMsg(result, Status.SUCCESS);
return result;
}
......
......@@ -211,13 +211,19 @@ public class EnvironmentServiceImpl extends BaseServiceImpl implements Environme
/**
* query all environment
*
* @param loginUser
* @return all environment list
*/
@Override
public Map<String, Object> queryAllEnvironmentList() {
public Map<String, Object> queryAllEnvironmentList(User loginUser) {
Map<String,Object> result = new HashMap<>();
List<Environment> environmentList = environmentMapper.queryAllEnvironmentList();
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.ENVIRONMENT, loginUser.getId(), logger);
if (ids.isEmpty()) {
result.put(Constants.DATA_LIST, Collections.emptyList());
putMsg(result,Status.SUCCESS);
return result;
}
List<Environment> environmentList = environmentMapper.selectBatchIds(ids);
if (CollectionUtils.isNotEmpty(environmentList)) {
Map<Long, List<String>> relationMap = relationMapper.selectList(null).stream()
.collect(Collectors.groupingBy(EnvironmentWorkerGroupRelation::getEnvironmentCode,Collectors.mapping(EnvironmentWorkerGroupRelation::getWorkerGroup,Collectors.toList())));
......
......@@ -17,9 +17,7 @@
package org.apache.dolphinscheduler.api.service.impl;
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.ProjectService;
import org.apache.dolphinscheduler.api.service.TaskGroupQueueService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.common.Constants;
......@@ -27,8 +25,8 @@ import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.TaskGroupQueue;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskGroupQueueMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import java.util.HashMap;
import java.util.List;
......@@ -53,10 +51,7 @@ public class TaskGroupQueueServiceImpl extends BaseServiceImpl implements TaskGr
TaskGroupQueueMapper taskGroupQueueMapper;
@Autowired
private TaskInstanceMapper taskInstanceMapper;
@Autowired
private ProjectService projectService;
private ProjectMapper projectMapper;
private static final Logger logger = LoggerFactory.getLogger(TaskGroupQueueServiceImpl.class);
......@@ -73,18 +68,18 @@ public class TaskGroupQueueServiceImpl extends BaseServiceImpl implements TaskGr
public Map<String, Object> queryTasksByGroupId(User loginUser, String taskName
, String processName, Integer status, int groupId, int pageNo, int pageSize) {
Map<String, Object> result = new HashMap<>();
boolean canOperatorPermissions = canOperatorPermissions(loginUser, null, AuthorizationType.TASK_GROUP, ApiFuncIdentificationConstant.TASK_GROUP_QUEUE);
if (!canOperatorPermissions){
result.put(Constants.STATUS, Status.NO_CURRENT_OPERATING_PERMISSION);
Page<TaskGroupQueue> page = new Page<>(pageNo, pageSize);
PageInfo<TaskGroupQueue> pageInfo = new PageInfo<>(pageNo, pageSize);
Set<Integer> projectIds = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, loginUser.getId(), logger);
if (projectIds.isEmpty()) {
result.put(Constants.DATA_LIST, pageInfo);
putMsg(result, Status.SUCCESS);
return result;
}
Page<TaskGroupQueue> page = new Page<>(pageNo, pageSize);
Map<String, Object> objectMap = this.projectService.queryAuthorizedProject(loginUser, loginUser.getId());
List<Project> projects = (List<Project>)objectMap.get(Constants.DATA_LIST);
List<Project> projects = projectMapper.selectBatchIds(projectIds);
IPage<TaskGroupQueue> taskGroupQueue = taskGroupQueueMapper.queryTaskGroupQueueByTaskGroupIdPaging(page, taskName
,processName,status,groupId,projects);
PageInfo<TaskGroupQueue> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotal((int) taskGroupQueue.getTotal());
pageInfo.setTotalList(taskGroupQueue.getRecords());
......
......@@ -236,12 +236,24 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
/**
* query all worker group
*
* @param loginUser
* @return all worker group list
*/
@Override
public Map<String, Object> queryAllGroup() {
public Map<String, Object> queryAllGroup(User loginUser) {
Map<String, Object> result = new HashMap<>();
List<WorkerGroup> workerGroups = getWorkerGroups(false);
List<WorkerGroup> workerGroups;
if (loginUser.getUserType().equals(UserType.ADMIN_USER)) {
workerGroups = getWorkerGroups(false);
} else {
Set<Integer> ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.WORKER_GROUP, loginUser.getId(), logger);
if (ids.isEmpty()) {
result.put(Constants.DATA_LIST, Collections.emptyList());
putMsg(result, Status.SUCCESS);
return result;
}
workerGroups = workerGroupMapper.selectBatchIds(ids);
}
List<String> availableWorkerGroupList = workerGroups.stream()
.map(WorkerGroup::getName)
.collect(Collectors.toList());
......
......@@ -21,6 +21,7 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import org.apache.commons.compress.utils.Sets;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.impl.AlertGroupServiceImpl;
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl;
......@@ -64,6 +65,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
public class AlertGroupServiceTest {
private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(AlertGroupServiceTest.class);
private static final Logger alertGroupServiceLogger = LoggerFactory.getLogger(AlertGroupServiceImpl.class);
@InjectMocks
private AlertGroupServiceImpl alertGroupService;
......@@ -80,7 +82,7 @@ public class AlertGroupServiceTest {
public void testQueryAlertGroup() {
Mockito.when(alertGroupMapper.queryAllGroupList()).thenReturn(getList());
Map<String, Object> result = alertGroupService.queryAlertgroup();
Map<String, Object> result = alertGroupService.queryAlertgroup(getLoginUser());
logger.info(result.toString());
List<AlertGroup> alertGroups = (List<AlertGroup>) result.get(Constants.DATA_LIST);
Assert.assertTrue(CollectionUtils.isNotEmpty(alertGroups));
......
......@@ -50,6 +50,7 @@ import org.apache.commons.collections.CollectionUtils;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
......@@ -79,6 +80,7 @@ import org.slf4j.LoggerFactory;
public class DataSourceServiceTest {
private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(DataSourceServiceTest.class);
private static final Logger dataSourceServiceLogger = LoggerFactory.getLogger(DataSourceServiceImpl.class);
@InjectMocks
private DataSourceServiceImpl dataSourceService;
......@@ -304,8 +306,15 @@ public class DataSourceServiceTest {
public void queryDataSourceListTest() {
User loginUser = new User();
loginUser.setUserType(UserType.GENERAL_USER);
Set<Integer> dataSourceIds = new HashSet<>();
dataSourceIds.add(1);
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATASOURCE, loginUser.getId(), null, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATASOURCE, null, 0, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.DATASOURCE, loginUser.getId(), dataSourceServiceLogger)).thenReturn(dataSourceIds);
DataSource dataSource = new DataSource();
dataSource.setType(DbType.MYSQL);
Mockito.when(dataSourceMapper.selectBatchIds(dataSourceIds)).thenReturn(Collections.singletonList(dataSource));
Map<String, Object> map = dataSourceService.queryDataSourceList(loginUser, DbType.MYSQL.ordinal());
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
}
......
......@@ -35,8 +35,10 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService;
import org.assertj.core.util.Lists;
......@@ -67,6 +69,7 @@ public class EnvironmentServiceTest {
public static final Logger logger = LoggerFactory.getLogger(EnvironmentServiceTest.class);
private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class);
private static final Logger environmentServiceLogger = LoggerFactory.getLogger(EnvironmentServiceImpl.class);
@InjectMocks
private EnvironmentServiceImpl environmentService;
......@@ -166,8 +169,12 @@ public class EnvironmentServiceTest {
@Test
public void testQueryAllEnvironmentList() {
Mockito.when(environmentMapper.queryAllEnvironmentList()).thenReturn(Lists.newArrayList(getEnvironment()));
Map<String, Object> result = environmentService.queryAllEnvironmentList();
Set<Integer> ids = new HashSet<>();
ids.add(1);
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.ENVIRONMENT, 1, environmentServiceLogger)).thenReturn(ids);
Mockito.when(environmentMapper.selectBatchIds(ids)).thenReturn(Lists.newArrayList(getEnvironment()));
Map<String, Object> result = environmentService.queryAllEnvironmentList(getAdminUser());
logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS));
......
......@@ -35,6 +35,7 @@ import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
......@@ -63,9 +64,17 @@ public class WorkerGroupServiceTest {
private String groupName = "groupName000001";
private User loginUSer;
@Before
public void init(){
loginUSer = new User();
loginUSer.setUserType(UserType.ADMIN_USER);
}
@Test
public void testQueryAllGroup() {
Map<String, Object> result = workerGroupService.queryAllGroup();
Map<String, Object> result = workerGroupService.queryAllGroup(loginUSer);
List<String> workerGroups = (List<String>) result.get(Constants.DATA_LIST);
Assert.assertEquals(workerGroups.size(), 1);
}
......@@ -104,7 +113,7 @@ public class WorkerGroupServiceTest {
@Test
public void testQueryAllGroupWithDefault() {
Map<String, Object> result = workerGroupService.queryAllGroup();
Map<String, Object> result = workerGroupService.queryAllGroup(loginUSer);
List<String> workerGroups = (List<String>) result.get(Constants.DATA_LIST);
Assert.assertEquals(1, workerGroups.size());
Assert.assertEquals("default", workerGroups.toArray()[0]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册