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

This commit is contained in:
Rick Cheng 2023-06-02 09:58:22 +08:00 committed by GitHub
parent e86630bb7b
commit 767331281a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 21 additions and 36 deletions

View File

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

View File

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

View File

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

View File

@ -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) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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