Browse Source

[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 <wangjipeng@whaleops.com>
3.0.0/version-upgrade
WangJPLeo 3 years ago committed by GitHub
parent
commit
ae84900329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java
  2. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java
  3. 14
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
  4. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java
  5. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java
  6. 3
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java
  7. 4
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml

2
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<String, Object> result = projectService.queryAllProjectList();
Map<String, Object> result = projectService.queryAllProjectList(loginUser);
return returnDataList(result);
}
}

4
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<String, Object> queryAllProjectList();
Map<String, Object> queryAllProjectList(User loginUser);
/**
* query authorized and user create project list by user id

14
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<String, Object> queryAllProjectList() {
public Map<String, Object> queryAllProjectList(User user) {
Map<String, Object> result = new HashMap<>();
List<Project> projects = projectMapper.queryAllProject();
List<Project> projects = projectMapper.queryAllProject(user.getUserType() == UserType.ADMIN_USER ? 0 : user.getId());
result.put(Constants.DATA_LIST, projects);
putMsg(result, Status.SUCCESS);

4
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<String, Object> 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());
}

6
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<String, Object> result = projectService.queryAllProjectList();
User user = new User();
user.setId(0);
Map<String, Object> result = projectService.queryAllProjectList(user);
logger.info(result.toString());
List<Project> projects = (List<Project>) result.get(Constants.DATA_LIST);
Assert.assertTrue(CollectionUtils.isNotEmpty(projects));

3
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java

@ -123,7 +123,8 @@ public interface ProjectMapper extends BaseMapper<Project> {
/**
* query all project
* @param userId
* @return projectList
*/
List<Project> queryAllProject();
List<Project> queryAllProject(@Param("userId") int userId);
}

4
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml

@ -164,5 +164,9 @@
select
<include refid="baseSql"/>
from t_ds_project
where 1=1
<if test="userId != 0">
and user_id = #{userId}
</if>
</select>
</mapper>

Loading…
Cancel
Save