Browse Source

[Improvement-14311][Permission]Remove duplicate checkProjectAndAuth (#14313)

3.2.1-prepare
Rick Cheng 1 year ago committed by GitHub
parent
commit
5250b253eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  2. 9
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
  3. 3
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java
  4. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java

16
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java

@ -19,7 +19,6 @@ package org.apache.dolphinscheduler.api.service.impl;
import static java.util.stream.Collectors.toSet; import static java.util.stream.Collectors.toSet;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_MOVE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_MOVE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.VERSION_DELETE;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.VERSION_LIST; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.VERSION_LIST;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_BATCH_COPY; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_BATCH_COPY;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_CREATE; import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_CREATE;
@ -282,8 +281,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check if user have write perm for project // check if user have write perm for project
Map<String, Object> result = Map<String, Object> result = new HashMap<>();
projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_CREATE);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) { if (!hasProjectAndWritePerm) {
return result; return result;
@ -765,8 +763,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessExecutionTypeEnum executionType) { ProcessExecutionTypeEnum executionType) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check if user have write perm for project // check if user have write perm for project
Map<String, Object> result = Map<String, Object> result = new HashMap<>();
projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_UPDATE);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) { if (!hasProjectAndWritePerm) {
return result; return result;
@ -2397,8 +2394,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
int version) { int version) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check if user have write perm for project // check if user have write perm for project
Map<String, Object> result = Map<String, Object> result = new HashMap<>();
projectService.checkProjectAndAuth(loginUser, project, projectCode, VERSION_DELETE);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) { if (!hasProjectAndWritePerm) {
return result; return result;
@ -2459,8 +2455,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessExecutionTypeEnum executionType) { ProcessExecutionTypeEnum executionType) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check if user have write perm for project // check if user have write perm for project
Map<String, Object> result = Map<String, Object> result = new HashMap<>();
projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_CREATE);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) { if (!hasProjectAndWritePerm) {
return result; return result;
@ -2595,8 +2590,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
ProcessExecutionTypeEnum executionType) { ProcessExecutionTypeEnum executionType) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check if user have write perm for project // check if user have write perm for project
Map<String, Object> result = Map<String, Object> result = new HashMap<>();
projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_UPDATE);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) { if (!hasProjectAndWritePerm) {
return result; return result;

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

@ -155,8 +155,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
String taskDefinitionJson) { String taskDefinitionJson) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check if user have write perm for project // check if user have write perm for project
Map<String, Object> result = Map<String, Object> result = new HashMap<>();
projectService.checkProjectAndAuth(loginUser, project, projectCode, TASK_DEFINITION_CREATE);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) { if (!hasProjectAndWritePerm) {
return result; return result;
@ -300,8 +299,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
String upstreamCodes) { String upstreamCodes) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check if user have write perm for project // check if user have write perm for project
Map<String, Object> result = Map<String, Object> result = new HashMap<>();
projectService.checkProjectAndAuth(loginUser, project, projectCode, TASK_DEFINITION_CREATE);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) { if (!hasProjectAndWritePerm) {
return result; return result;
@ -1071,8 +1069,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
public Map<String, Object> deleteByCodeAndVersion(User loginUser, long projectCode, long taskCode, int version) { public Map<String, Object> deleteByCodeAndVersion(User loginUser, long projectCode, long taskCode, int version) {
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
// check if user have write perm for project // check if user have write perm for project
Map<String, Object> result = Map<String, Object> result = new HashMap<>();
projectService.checkProjectAndAuth(loginUser, project, projectCode, TASK_DEFINITION_DELETE);
boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result); boolean hasProjectAndWritePerm = projectService.hasProjectAndWritePerm(loginUser, project, result);
if (!hasProjectAndWritePerm) { if (!hasProjectAndWritePerm) {
return result; return result;

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

@ -810,12 +810,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool {
@Test @Test
public void testUpdateProcessDefinition() { public void testUpdateProcessDefinition() {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS);
Project project = getProject(projectCode); Project project = getProject(projectCode);
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
Mockito.when(projectService.checkProjectAndAuth(user, project, projectCode, WORKFLOW_UPDATE))
.thenReturn(result);
Mockito.when(projectService.hasProjectAndWritePerm(user, project, result)).thenReturn(true); Mockito.when(projectService.hasProjectAndWritePerm(user, project, result)).thenReturn(true);
try { try {

6
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java

@ -156,9 +156,9 @@ public class TaskDefinitionServiceImplTest {
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS, PROJECT_CODE); Mockito.when(projectService.hasProjectAndWritePerm(user, project, result))
Mockito.when(projectService.checkProjectAndAuth(user, project, PROJECT_CODE, TASK_DEFINITION_CREATE)) .thenReturn(true);
.thenReturn(result); Mockito.when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true);
String createTaskDefinitionJson = String createTaskDefinitionJson =
"[{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" "[{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":"

Loading…
Cancel
Save