提交 0728ad91 编写于 作者: C Captain.B

project workspace name check

上级 e5f57dc6
......@@ -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);
}
......
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);
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册