Browse Source

[Improvement-14255][Project] Remove userName when update project (#14256)

3.2.1-prepare
Rick Cheng 1 year ago committed by GitHub
parent
commit
767331281a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java
  2. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2Controller.java
  3. 3
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/project/ProjectUpdateRequest.java
  4. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
  5. 3
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java
  6. 9
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
  7. 5
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java
  8. 3
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2ControllerTest.java
  9. 12
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java
  10. 5
      dolphinscheduler-ui/src/service/modules/projects/index.ts
  11. 5
      dolphinscheduler-ui/src/service/modules/projects/types.ts

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java

@ -104,8 +104,7 @@ public class ProjectController extends BaseController {
@Parameters({ @Parameters({
@Parameter(name = "code", description = "PROJECT_CODE", schema = @Schema(implementation = long.class, example = "123456")), @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 = "projectName", description = "PROJECT_NAME", schema = @Schema(implementation = String.class)),
@Parameter(name = "description", description = "PROJECT_DESC", 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)),
}) })
@PutMapping(value = "/{code}") @PutMapping(value = "/{code}")
@ResponseStatus(HttpStatus.OK) @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, public Result updateProject(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("code") Long code, @PathVariable("code") Long code,
@RequestParam("projectName") String projectName, @RequestParam("projectName") String projectName,
@RequestParam(value = "description", required = false) String description, @RequestParam(value = "description", required = false) String description) {
@RequestParam(value = "userName") String userName) { return projectService.update(loginUser, code, projectName, description);
return projectService.update(loginUser, code, projectName, description, userName);
} }
/** /**

2
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, @PathVariable("code") Long code,
@RequestBody ProjectUpdateRequest projectUpdateReq) { @RequestBody ProjectUpdateRequest projectUpdateReq) {
Result result = projectService.update(loginUser, code, projectUpdateReq.getProjectName(), Result result = projectService.update(loginUser, code, projectUpdateReq.getProjectName(),
projectUpdateReq.getDescription(), projectUpdateReq.getUserName()); projectUpdateReq.getDescription());
return new ProjectUpdateResponse(result); return new ProjectUpdateResponse(result);
} }

3
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 @Data
public class ProjectUpdateRequest { public class ProjectUpdateRequest {
@Schema(example = "admin", required = true)
private String userName;
@Schema(example = "pro123", required = true) @Schema(example = "pro123", required = true)
private String projectName; private String projectName;

2
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) { public void updateProject(String userName, Long projectCode, String projectName, String desc) {
User user = usersService.queryUser(userName); 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) { public void deleteProject(String userName, Long projectCode) {

3
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java

@ -128,10 +128,9 @@ public interface ProjectService {
* @param projectCode project code * @param projectCode project code
* @param projectName project name * @param projectName project name
* @param desc description * @param desc description
* @param userName project owner
* @return update result code * @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 * query unauthorized project

9
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 projectCode project code
* @param projectName project name * @param projectName project name
* @param desc description * @param desc description
* @param userName project owner
* @return update result code * @return update result code
*/ */
@Override @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(); Result result = new Result();
checkDesc(result, desc); checkDesc(result, desc);
@ -517,10 +516,10 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
putMsg(result, Status.PROJECT_ALREADY_EXISTS, projectName); putMsg(result, Status.PROJECT_ALREADY_EXISTS, projectName);
return result; return result;
} }
User user = userMapper.queryByUserNameAccurately(userName); User user = userMapper.selectById(loginUser.getId());
if (user == null) { if (user == null) {
log.error("User does not exist."); log.error("user {} not exists", loginUser.getId());
putMsg(result, Status.USER_NOT_EXIST, userName); putMsg(result, Status.USER_NOT_EXIST, loginUser.getId());
return result; return result;
} }
project.setName(projectName); project.setName(projectName);

5
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProjectControllerTest.java

@ -75,9 +75,8 @@ public class ProjectControllerTest {
long projectCode = 1L; long projectCode = 1L;
String projectName = "test"; String projectName = "test";
String desc = ""; String desc = "";
String userName = "jack"; Mockito.when(projectService.update(user, projectCode, projectName, desc)).thenReturn(result);
Mockito.when(projectService.update(user, projectCode, projectName, desc, userName)).thenReturn(result); Result response = projectController.updateProject(user, projectCode, projectName, desc);
Result response = projectController.updateProject(user, projectCode, projectName, desc, userName);
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }

3
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/v2/ProjectV2ControllerTest.java

@ -77,9 +77,8 @@ public class ProjectV2ControllerTest {
ProjectUpdateRequest projectUpdateReq = new ProjectUpdateRequest(); ProjectUpdateRequest projectUpdateReq = new ProjectUpdateRequest();
projectUpdateReq.setProjectName("james"); projectUpdateReq.setProjectName("james");
projectUpdateReq.setDescription("james lbj"); projectUpdateReq.setDescription("james lbj");
projectUpdateReq.setUserName("admin");
Mockito.when(projectService.update(user, projectCode, projectUpdateReq.getProjectName(), 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); Result response = projectV2Controller.updateProject(user, projectCode, projectUpdateReq);
Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assertions.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }

12
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.queryByName(projectName)).thenReturn(project);
Mockito.when(projectMapper.queryByCode(2L)).thenReturn(getProject()); Mockito.when(projectMapper.queryByCode(2L)).thenReturn(getProject());
// PROJECT_NOT_FOUND // PROJECT_NOT_FOUND
Result result = projectService.update(loginUser, 1L, projectName, "desc", "testUser"); Result result = projectService.update(loginUser, 1L, projectName, "desc");
logger.info(result.toString()); logger.info(result.toString());
Assertions.assertTrue(Status.PROJECT_NOT_FOUND.getCode() == result.getCode()); 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}, Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.PROJECTS, new Object[]{1},
loginUser.getId(), loginUser.getId(),
baseServiceLogger)).thenReturn(true); baseServiceLogger)).thenReturn(true);
result = projectService.update(loginUser, 2L, projectName, "desc", userName); result = projectService.update(loginUser, 2L, projectName, "desc");
logger.info(result.toString()); logger.info(result.toString());
Assertions.assertTrue(Status.PROJECT_ALREADY_EXISTS.getCode() == result.getCode()); Assertions.assertTrue(Status.PROJECT_ALREADY_EXISTS.getCode() == result.getCode());
// USER_NOT_EXIST // USER_NOT_EXIST
Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(null); Mockito.when(userMapper.selectById(Mockito.any())).thenReturn(null);
result = projectService.update(loginUser, 2L, "test", "desc", "testuser"); result = projectService.update(loginUser, 2L, "test", "desc");
Assertions.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); Assertions.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode());
// success // success
Mockito.when(userMapper.queryByUserNameAccurately(Mockito.any())).thenReturn(new User()); Mockito.when(userMapper.selectById(Mockito.any())).thenReturn(new User());
project.setUserId(1); project.setUserId(1);
Mockito.when(projectMapper.updateById(Mockito.any(Project.class))).thenReturn(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()); logger.info(result.toString());
Assertions.assertTrue(Status.SUCCESS.getCode() == result.getCode()); Assertions.assertTrue(Status.SUCCESS.getCode() == result.getCode());

5
dolphinscheduler-ui/src/service/modules/projects/index.ts

@ -20,8 +20,7 @@ import {
ListReq, ListReq,
ListIdReq, ListIdReq,
ProjectsReq, ProjectsReq,
UserIdReq, UserIdReq
UpdateProjectsReq
} from './types' } from './types'
export function queryProjectListPaging(params: ListReq): any { 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({ return axios({
url: `/projects/${code}`, url: `/projects/${code}`,
method: 'put', method: 'put',

5
dolphinscheduler-ui/src/service/modules/projects/types.ts

@ -37,10 +37,6 @@ interface UserIdReq {
userId?: number userId?: number
} }
interface UpdateProjectsReq extends ProjectsReq {
userName?: string
}
interface ProjectList { interface ProjectList {
id: number id: number
userId: number userId: number
@ -69,7 +65,6 @@ export {
ListIdReq, ListIdReq,
ProjectsReq, ProjectsReq,
UserIdReq, UserIdReq,
UpdateProjectsReq,
ProjectRes, ProjectRes,
ProjectList ProjectList
} }

Loading…
Cancel
Save