From 767331281a387d5e0e10a42e53e40943ff6e5cd4 Mon Sep 17 00:00:00 2001 From: Rick Cheng Date: Fri, 2 Jun 2023 09:58:22 +0800 Subject: [PATCH] [Improvement-14255][Project] Remove userName when update project (#14256) --- .../api/controller/ProjectController.java | 8 +++----- .../api/controller/v2/ProjectV2Controller.java | 2 +- .../api/dto/project/ProjectUpdateRequest.java | 3 --- .../dolphinscheduler/api/python/PythonGateway.java | 2 +- .../dolphinscheduler/api/service/ProjectService.java | 3 +-- .../api/service/impl/ProjectServiceImpl.java | 9 ++++----- .../api/controller/ProjectControllerTest.java | 5 ++--- .../api/controller/v2/ProjectV2ControllerTest.java | 3 +-- .../api/service/ProjectServiceTest.java | 12 ++++++------ .../src/service/modules/projects/index.ts | 5 ++--- .../src/service/modules/projects/types.ts | 5 ----- 11 files changed, 21 insertions(+), 36 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 c699bd5dfd..e46cb7c346 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 @@ -104,8 +104,7 @@ public class ProjectController extends BaseController { @Parameters({ @Parameter(name = "code", description = "PROJECT_CODE", schema = @Schema(implementation = long.class, example = "123456")), @Parameter(name = "projectName", description = "PROJECT_NAME", schema = @Schema(implementation = String.class)), - @Parameter(name = "description", description = "PROJECT_DESC", schema = @Schema(implementation = String.class)), - @Parameter(name = "userName", description = "USER_NAME", schema = @Schema(implementation = String.class)), + @Parameter(name = "description", description = "PROJECT_DESC", schema = @Schema(implementation = String.class)) }) @PutMapping(value = "/{code}") @ResponseStatus(HttpStatus.OK) @@ -114,9 +113,8 @@ public class ProjectController extends BaseController { public Result updateProject(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, @PathVariable("code") Long code, @RequestParam("projectName") String projectName, - @RequestParam(value = "description", required = false) String description, - @RequestParam(value = "userName") String userName) { - return projectService.update(loginUser, code, projectName, description, userName); + @RequestParam(value = "description", required = false) String description) { + return projectService.update(loginUser, code, projectName, description); } /** diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2Controller.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2Controller.java index 633dc59eab..38df7fd132 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2Controller.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2Controller.java @@ -113,7 +113,7 @@ public class ProjectV2Controller extends BaseController { @PathVariable("code") Long code, @RequestBody ProjectUpdateRequest projectUpdateReq) { Result result = projectService.update(loginUser, code, projectUpdateReq.getProjectName(), - projectUpdateReq.getDescription(), projectUpdateReq.getUserName()); + projectUpdateReq.getDescription()); return new ProjectUpdateResponse(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/project/ProjectUpdateRequest.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/project/ProjectUpdateRequest.java index 000900bdf1..cf6216728f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/project/ProjectUpdateRequest.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/project/ProjectUpdateRequest.java @@ -31,9 +31,6 @@ import io.swagger.v3.oas.annotations.media.Schema; @Data public class ProjectUpdateRequest { - @Schema(example = "admin", required = true) - private String userName; - @Schema(example = "pro123", required = true) private String projectName; diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java index d2eced336d..a40a89db30 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java @@ -450,7 +450,7 @@ public class PythonGateway { public void updateProject(String userName, Long projectCode, String projectName, String desc) { User user = usersService.queryUser(userName); - projectService.update(user, projectCode, projectName, desc, userName); + projectService.update(user, projectCode, projectName, desc); } public void deleteProject(String userName, Long projectCode) { 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 61e8540eb8..d1eb4b2ada 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 @@ -128,10 +128,9 @@ public interface ProjectService { * @param projectCode project code * @param projectName project name * @param desc description - * @param userName project owner * @return update result code */ - Result update(User loginUser, Long projectCode, String projectName, String desc, String userName); + Result update(User loginUser, Long projectCode, String projectName, String desc); /** * query unauthorized project 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 35aeacf798..4884646173 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 @@ -495,11 +495,10 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic * @param projectCode project code * @param projectName project name * @param desc description - * @param userName project owner * @return update result code */ @Override - public Result update(User loginUser, Long projectCode, String projectName, String desc, String userName) { + public Result update(User loginUser, Long projectCode, String projectName, String desc) { Result result = new Result(); checkDesc(result, desc); @@ -517,10 +516,10 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic putMsg(result, Status.PROJECT_ALREADY_EXISTS, projectName); return result; } - User user = userMapper.queryByUserNameAccurately(userName); + User user = userMapper.selectById(loginUser.getId()); if (user == null) { - log.error("User does not exist."); - putMsg(result, Status.USER_NOT_EXIST, userName); + log.error("user {} not exists", loginUser.getId()); + putMsg(result, Status.USER_NOT_EXIST, loginUser.getId()); return result; } project.setName(projectName); 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 647dc14533..1caf333ab1 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 @@ -75,9 +75,8 @@ public class ProjectControllerTest { long projectCode = 1L; String projectName = "test"; String desc = ""; - String userName = "jack"; - Mockito.when(projectService.update(user, projectCode, projectName, desc, userName)).thenReturn(result); - Result response = projectController.updateProject(user, projectCode, projectName, desc, userName); + Mockito.when(projectService.update(user, projectCode, projectName, desc)).thenReturn(result); + Result response = projectController.updateProject(user, projectCode, projectName, desc); Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2ControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2ControllerTest.java index 7a486d0615..f11f8fa41b 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2ControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2ControllerTest.java @@ -77,9 +77,8 @@ public class ProjectV2ControllerTest { ProjectUpdateRequest projectUpdateReq = new ProjectUpdateRequest(); projectUpdateReq.setProjectName("james"); projectUpdateReq.setDescription("james lbj"); - projectUpdateReq.setUserName("admin"); Mockito.when(projectService.update(user, projectCode, projectUpdateReq.getProjectName(), - projectUpdateReq.getDescription(), projectUpdateReq.getUserName())).thenReturn(result); + projectUpdateReq.getDescription())).thenReturn(result); Result response = projectV2Controller.updateProject(user, projectCode, projectUpdateReq); Assertions.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 0fecefecb0..16ada5532f 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 @@ -292,7 +292,7 @@ public class ProjectServiceTest { Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project); Mockito.when(projectMapper.queryByCode(2L)).thenReturn(getProject()); // PROJECT_NOT_FOUND - Result result = projectService.update(loginUser, 1L, projectName, "desc", "testUser"); + Result result = projectService.update(loginUser, 1L, projectName, "desc"); logger.info(result.toString()); Assertions.assertTrue(Status.PROJECT_NOT_FOUND.getCode() == result.getCode()); @@ -304,20 +304,20 @@ public class ProjectServiceTest { Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1}, loginUser.getId(), baseServiceLogger)).thenReturn(true); - result = projectService.update(loginUser, 2L, projectName, "desc", userName); + result = projectService.update(loginUser, 2L, projectName, "desc"); logger.info(result.toString()); Assertions.assertTrue(Status.PROJECT_ALREADY_EXISTS.getCode() == result.getCode()); // USER_NOT_EXIST - Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(null); - result = projectService.update(loginUser, 2L, "test", "desc", "testuser"); + Mockito.when(userMapper.selectById(Mockito.any())).thenReturn(null); + result = projectService.update(loginUser, 2L, "test", "desc"); Assertions.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); // success - Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(new User()); + Mockito.when(userMapper.selectById(Mockito.any())).thenReturn(new User()); project.setUserId(1); Mockito.when(projectMapper.updateById(Mockito.any(Project.class))).thenReturn(1); - result = projectService.update(loginUser, 2L, "test", "desc", "testUser"); + result = projectService.update(loginUser, 2L, "test", "desc"); logger.info(result.toString()); Assertions.assertTrue(Status.SUCCESS.getCode() == result.getCode()); diff --git a/dolphinscheduler-ui/src/service/modules/projects/index.ts b/dolphinscheduler-ui/src/service/modules/projects/index.ts index e8c5e43ae3..4690cf52f3 100644 --- a/dolphinscheduler-ui/src/service/modules/projects/index.ts +++ b/dolphinscheduler-ui/src/service/modules/projects/index.ts @@ -20,8 +20,7 @@ import { ListReq, ListIdReq, ProjectsReq, - UserIdReq, - UpdateProjectsReq + UserIdReq } from './types' export function queryProjectListPaging(params: ListReq): any { @@ -95,7 +94,7 @@ export function queryProjectByCode(code: number): any { }) } -export function updateProject(data: UpdateProjectsReq, code: number): any { +export function updateProject(data: ProjectsReq, code: number): any { return axios({ url: `/projects/${code}`, method: 'put', diff --git a/dolphinscheduler-ui/src/service/modules/projects/types.ts b/dolphinscheduler-ui/src/service/modules/projects/types.ts index 3d0d824c8f..6c66ae3e0b 100644 --- a/dolphinscheduler-ui/src/service/modules/projects/types.ts +++ b/dolphinscheduler-ui/src/service/modules/projects/types.ts @@ -37,10 +37,6 @@ interface UserIdReq { userId?: number } -interface UpdateProjectsReq extends ProjectsReq { - userName?: string -} - interface ProjectList { id: number userId: number @@ -69,7 +65,6 @@ export { ListIdReq, ProjectsReq, UserIdReq, - UpdateProjectsReq, ProjectRes, ProjectList }