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({
@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);
}
/**

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,
@RequestBody ProjectUpdateRequest projectUpdateReq) {
Result result = projectService.update(loginUser, code, projectUpdateReq.getProjectName(),
projectUpdateReq.getDescription(), projectUpdateReq.getUserName());
projectUpdateReq.getDescription());
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
public class ProjectUpdateRequest {
@Schema(example = "admin", required = true)
private String userName;
@Schema(example = "pro123", required = true)
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) {
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) {

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 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

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 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);

5
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());
}

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();
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());
}

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.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());

5
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',

5
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
}

Loading…
Cancel
Save