project workspace name check

This commit is contained in:
Captain.B 2020-02-19 16:51:11 +08:00
parent e5f57dc68b
commit 0728ad91af
3 changed files with 21 additions and 1 deletions

View File

@ -34,7 +34,7 @@ public class WorkspaceController {
@GetMapping("delete/{workspaceId}")
@RequiresRoles(RoleConstants.ORG_ADMIN)
public void saveWorkspace(@PathVariable String workspaceId) {
public void deleteWorkspace(@PathVariable String workspaceId) {
workspaceService.checkOwner(workspaceId);
workspaceService.deleteWorkspace(workspaceId);
}

View File

@ -1,8 +1,11 @@
package io.metersphere.service;
import io.metersphere.base.domain.Project;
import io.metersphere.base.domain.ProjectExample;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.user.SessionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -17,6 +20,16 @@ public class ProjectService {
private ProjectMapper projectMapper;
public Project addProject(Project project) {
if (StringUtils.isBlank(project.getName())) {
MSException.throwException("Project name cannot be null");
}
ProjectExample example = new ProjectExample();
example.createCriteria()
.andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId())
.andNameEqualTo(project.getName());
if (projectMapper.countByExample(example) > 0) {
MSException.throwException("The project name already exists");
}
project.setId(UUID.randomUUID().toString());
long createTime = System.currentTimeMillis();
project.setCreateTime(createTime);

View File

@ -32,6 +32,13 @@ public class WorkspaceService {
long currentTime = System.currentTimeMillis();
if (StringUtils.isBlank(workspace.getId())) {
WorkspaceExample example = new WorkspaceExample();
example.createCriteria()
.andOrganizationIdEqualTo(SessionUtils.getCurrentOrganizationId())
.andNameEqualTo(workspace.getName());
if (workspaceMapper.countByExample(example) > 0) {
MSException.throwException("The workspace name already exists");
}
workspace.setId(UUID.randomUUID().toString()); // 设置ID
workspace.setCreateTime(currentTime);
workspace.setUpdateTime(currentTime); // 首次 update time