From ae849003293417e72bb57bf5019d10f02ea61b0f Mon Sep 17 00:00:00 2001 From: WangJPLeo <103574007+WangJPLeo@users.noreply.github.com> Date: Wed, 20 Apr 2022 18:24:45 +0800 Subject: [PATCH] [Fix-9617]New task group project name drop-down data is displayed according to user type. (#9625) * New task group project name drop-down data by user type * remove unused import * avoid import * Co-authored-by: WangJPLeo --- .../api/controller/ProjectController.java | 2 +- .../api/service/ProjectService.java | 4 ++-- .../api/service/impl/ProjectServiceImpl.java | 14 ++++++++++---- .../api/controller/ProjectControllerTest.java | 4 +++- .../api/service/ProjectServiceTest.java | 6 ++++-- .../dolphinscheduler/dao/mapper/ProjectMapper.java | 3 ++- .../dolphinscheduler/dao/mapper/ProjectMapper.xml | 4 ++++ 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java index 0eff931c7f..1dd4a2a07d 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java @@ -287,7 +287,7 @@ public class ProjectController extends BaseController { @ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryAllProjectList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - Map result = projectService.queryAllProjectList(); + Map result = projectService.queryAllProjectList(loginUser); return returnDataList(result); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java index 38c0c53386..aae441e4bc 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java @@ -138,10 +138,10 @@ public interface ProjectService { /** * query all project list that have one or more process definitions. - * + * @param loginUser * @return project list */ - Map queryAllProjectList(); + Map queryAllProjectList(User loginUser); /** * query authorized and user create project list by user id diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java index ddebaa782c..e10a83f8e1 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java @@ -38,7 +38,13 @@ import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import static org.apache.dolphinscheduler.api.utils.CheckUtils.checkDesc; @@ -500,13 +506,13 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic /** * query all project list - * + * @param user * @return project list */ @Override - public Map queryAllProjectList() { + public Map queryAllProjectList(User user) { Map result = new HashMap<>(); - List projects = projectMapper.queryAllProject(); + List projects = projectMapper.queryAllProject(user.getUserType() == UserType.ADMIN_USER ? 0 : user.getId()); result.put(Constants.DATA_LIST, projects); putMsg(result, Status.SUCCESS); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java index 118484c4c9..8aca9a23a7 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java @@ -137,9 +137,11 @@ public class ProjectControllerTest { @Test public void testQueryAllProjectList() { + User user = new User(); + user.setId(0); Map result = new HashMap<>(); putMsg(result, Status.SUCCESS); - Mockito.when(projectService.queryAllProjectList()).thenReturn(result); + Mockito.when(projectService.queryAllProjectList(user)).thenReturn(result); Result response = projectController.queryAllProjectList(user); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java index 0c5579b685..2f83fcc78e 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java @@ -345,9 +345,11 @@ public class ProjectServiceTest { @Test public void testQueryAllProjectList() { - Mockito.when(projectMapper.queryAllProject()).thenReturn(getList()); + Mockito.when(projectMapper.queryAllProject(0)).thenReturn(getList()); - Map result = projectService.queryAllProjectList(); + User user = new User(); + user.setId(0); + Map result = projectService.queryAllProjectList(user); logger.info(result.toString()); List projects = (List) result.get(Constants.DATA_LIST); Assert.assertTrue(CollectionUtils.isNotEmpty(projects)); diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java index ce1f845687..f31fc11088 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java @@ -123,7 +123,8 @@ public interface ProjectMapper extends BaseMapper { /** * query all project + * @param userId * @return projectList */ - List queryAllProject(); + List queryAllProject(@Param("userId") int userId); } diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml index 26602a8bcb..549afdfcb6 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml @@ -164,5 +164,9 @@ select from t_ds_project + where 1=1 + + and user_id = #{userId} +