未验证 提交 8d75e622 编写于 作者: M metersphere-bot 提交者: GitHub

fix: 禁止删除已经关联的模板 (#2175)

* fix: 编辑系统自定义字段报错

* fix: 禁止删除已经关联的模板
Co-authored-by: Nchenjianxing <jianxing.chen@fit2cloud.com>
上级 85654493
......@@ -23,7 +23,7 @@ import java.util.UUID;
@Service
@Transactional(rollbackFor = Exception.class)
public class IssueTemplateService {
public class IssueTemplateService extends TemplateBaseService {
@Resource
ExtIssueTemplateMapper extIssueTemplateMapper;
......@@ -62,6 +62,7 @@ public class IssueTemplateService {
}
public void delete(String id) {
checkTemplateUsed(id, projectService::getByIssueTemplateId);
issueTemplateMapper.deleteByPrimaryKey(id);
customFieldTemplateService.deleteByTemplateId(id);
}
......
......@@ -180,6 +180,20 @@ public class ProjectService {
return projectMapper.selectByPrimaryKey(id);
}
public List<Project> getByCaseTemplateId(String templateId) {
ProjectExample example = new ProjectExample();
example.createCriteria()
.andCaseTemplateIdEqualTo(templateId);
return projectMapper.selectByExample(example);
}
public List<Project> getByIssueTemplateId(String templateId) {
ProjectExample example = new ProjectExample();
example.createCriteria()
.andIssueTemplateIdEqualTo(templateId);
return projectMapper.selectByExample(example);
}
public List<FileMetadata> uploadFiles(String projectId, List<MultipartFile> files) {
List<FileMetadata> result = new ArrayList<>();
if (files != null) {
......
package io.metersphere.service;
import io.metersphere.base.domain.Project;
import io.metersphere.commons.exception.MSException;
import org.apache.commons.collections.CollectionUtils;
import java.util.List;
import java.util.function.Function;
public class TemplateBaseService {
protected void checkTemplateUsed(String id, Function<String, List<Project>> getProjectFuc) {
List<Project> projects = getProjectFuc.apply(id);
if (CollectionUtils.isNotEmpty(projects)) {
StringBuilder tip = new StringBuilder();
projects.forEach(item -> {
tip.append(item.getName() + ',');
});
tip.deleteCharAt(tip.length() - 1);
MSException.throwException("该模板已关联项目:" + tip);
}
}
}
......@@ -18,15 +18,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
public class TestCaseTemplateService {
public class TestCaseTemplateService extends TemplateBaseService {
@Resource
ExtTestCaseTemplateMapper extTestCaseTemplateMapper;
......@@ -65,6 +62,7 @@ public class TestCaseTemplateService {
}
public void delete(String id) {
checkTemplateUsed(id, projectService::getByCaseTemplateId);
testCaseTemplateMapper.deleteByPrimaryKey(id);
customFieldTemplateService.deleteByTemplateId(id);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册