fix(用例管理): 用例前后置取消依赖接口调整&查询条件

--bug=1036167 --user=王旭 【用例查看】依赖关系-项目管理员取消用例依赖关系失败,提示没有权限 https://www.tapd.cn/55049933/s/1464747
This commit is contained in:
WangXu10 2024-02-26 15:35:55 +08:00 committed by 刘瑞斌
parent f64b36d485
commit 1dd0eaef55
8 changed files with 102 additions and 14 deletions

View File

@ -6,6 +6,7 @@ import com.github.pagehelper.PageHelper;
import io.metersphere.functional.dto.FunctionalCasePageDTO;
import io.metersphere.functional.dto.FunctionalCaseRelationshipDTO;
import io.metersphere.functional.request.RelationshipAddRequest;
import io.metersphere.functional.request.RelationshipDeleteRequest;
import io.metersphere.functional.request.RelationshipPageRequest;
import io.metersphere.functional.request.RelationshipRequest;
import io.metersphere.functional.service.FunctionalCaseRelationshipEdgeService;
@ -80,11 +81,11 @@ public class FunctionalCaseRelationshipController {
}
@GetMapping("/delete/{id}")
@PostMapping("/delete")
@Operation(summary = "用例管理-功能用例-用例详情-前后置关系-取消关联")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE)
@CheckOwner(resourceId = "#id", resourceType = "functional_case")
public void delete(@PathVariable("id") String id) {
functionalCaseRelationshipEdgeService.delete(id);
@CheckOwner(resourceId = "#request.getCaseId", resourceType = "functional_case")
public void delete(@Validated @RequestBody RelationshipDeleteRequest request) {
functionalCaseRelationshipEdgeService.delete(request);
}
}

View File

@ -51,6 +51,13 @@
</when>
</choose>
</if>
<if test="request.keyword != null and request.keyword != ''">
and (
fc.name like concat('%', #{request.keyword},'%')
or fc.num like concat('%', #{request.keyword},'%')
or fc.tags like concat('%', #{request.keyword},'%')
)
</if>
order by
<if test="sort != null and sort != ''">
fc.${sort}

View File

@ -0,0 +1,30 @@
package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* @author wx
*/
@Data
public class RelationshipDeleteRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "关联表id", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case.id.not_blank}")
private String id;
@Schema(description = "用例id", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case_blob.functional_case_id.not_blank}")
private String caseId;
@Schema(description = "类型前置/后置", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"PRE", "POST"})
@NotBlank(message = "{functional_case_relationship_edge.type.not_blank}")
private String type;
}

View File

@ -13,12 +13,16 @@ import io.metersphere.functional.dto.FunctionalCaseRelationshipDTO;
import io.metersphere.functional.mapper.ExtFunctionalCaseRelationshipEdgeMapper;
import io.metersphere.functional.mapper.FunctionalCaseRelationshipEdgeMapper;
import io.metersphere.functional.request.RelationshipAddRequest;
import io.metersphere.functional.request.RelationshipDeleteRequest;
import io.metersphere.functional.request.RelationshipRequest;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.RelationshipEdgeDTO;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.RelationshipEdgeUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@ -180,9 +184,25 @@ public class FunctionalCaseRelationshipEdgeService {
}
public void delete(String id) {
RelationshipEdgeUtils.updateGraphId(id, extFunctionalCaseRelationshipEdgeMapper::getGraphId, extFunctionalCaseRelationshipEdgeMapper::getEdgeByGraphId, extFunctionalCaseRelationshipEdgeMapper::update);
functionalCaseRelationshipEdgeMapper.deleteByPrimaryKey(id);
public void delete(RelationshipDeleteRequest request) {
checkResource(request);
RelationshipEdgeUtils.updateGraphId(request.getId(), extFunctionalCaseRelationshipEdgeMapper::getGraphId, extFunctionalCaseRelationshipEdgeMapper::getEdgeByGraphId, extFunctionalCaseRelationshipEdgeMapper::update);
functionalCaseRelationshipEdgeMapper.deleteByPrimaryKey(request.getId());
}
private void checkResource(RelationshipDeleteRequest request) {
FunctionalCaseRelationshipEdgeExample example = new FunctionalCaseRelationshipEdgeExample();
FunctionalCaseRelationshipEdgeExample.Criteria criteria = example.createCriteria();
criteria.andIdEqualTo(request.getId());
if(StringUtils.equalsIgnoreCase(request.getType(), "PRE")){
criteria.andTargetIdEqualTo(request.getCaseId());
}else {
criteria.andSourceIdEqualTo(request.getCaseId());
}
if(functionalCaseRelationshipEdgeMapper.countByExample(example) == 0){
throw new MSException(Translator.get("resource_not_exist"));
}
}

View File

@ -1,6 +1,7 @@
package io.metersphere.functional.controller;
import io.metersphere.functional.request.RelationshipAddRequest;
import io.metersphere.functional.request.RelationshipDeleteRequest;
import io.metersphere.functional.request.RelationshipPageRequest;
import io.metersphere.functional.request.RelationshipRequest;
import io.metersphere.sdk.util.JSON;
@ -26,7 +27,7 @@ public class FunctionalCaseRelationshipControllerTests extends BaseTest {
public static final String RELATE_PAGE = "/functional/case/relationship/relate/page";
public static final String ADD = "/functional/case/relationship/add";
public static final String PAGE = "/functional/case/relationship/page";
public static final String DELETE = "/functional/case/relationship/delete/";
public static final String DELETE = "/functional/case/relationship/delete";
public static final String IDS = "/functional/case/relationship/get-ids/";
@ -141,7 +142,11 @@ public class FunctionalCaseRelationshipControllerTests extends BaseTest {
@Test
@Order(4)
public void testDelete() throws Exception {
MvcResult postResult = this.requestGetWithOkAndReturn(DELETE + "relationship_1");
RelationshipDeleteRequest request = new RelationshipDeleteRequest();
request.setId("relationship_1");
request.setCaseId("wx_relationship_1");
request.setType("POST");
MvcResult postResult = this.requestPostWithOkAndReturn(DELETE, request);
// 获取返回值
String postReturnData = postResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder postResultHolder = JSON.parseObject(postReturnData, ResultHolder.class);
@ -149,7 +154,9 @@ public class FunctionalCaseRelationshipControllerTests extends BaseTest {
Assertions.assertNotNull(postResultHolder);
//异常覆盖
assertErrorCode(this.requestGet(DELETE + "test"), MsHttpResultCode.FAILED);
request.setId("test");
request.setType("PRE");
assertErrorCode(this.requestPost(DELETE, request), MsHttpResultCode.FAILED);
}
@Test
@ -163,6 +170,10 @@ public class FunctionalCaseRelationshipControllerTests extends BaseTest {
Assertions.assertNotNull(postResultHolder);
//异常覆盖
assertErrorCode(this.requestGet(DELETE + "test"), MsHttpResultCode.FAILED);
RelationshipDeleteRequest request = new RelationshipDeleteRequest();
request.setCaseId("wx_relationship_1");
request.setId("test");
request.setType("PRE");
assertErrorCode(this.requestPost(DELETE, request), MsHttpResultCode.FAILED);
}
}

View File

@ -83,6 +83,7 @@ import type {
CreateOrUpdateDemand,
CreateOrUpdateModule,
DeleteCaseType,
DeleteDependencyParams,
DemandItem,
DragCase,
ImportExcelType,
@ -340,8 +341,8 @@ export function addPrepositionRelation(data: TableQueryParams) {
return MSR.post<ModulesTreeType[]>({ url: AddDependOnRelationUrl, data });
}
// 取消依赖关系
export function cancelPreOrPostCase(id: string) {
return MSR.get({ url: `${cancelPreAndPostCaseUrl}/${id}` });
export function cancelPreOrPostCase(data: DeleteDependencyParams) {
return MSR.post({ url: cancelPreAndPostCaseUrl, data });
}
// 获取抽屉详情已关联用例列表
export function getAssociatedCasePage(data: TableQueryParams) {

View File

@ -350,3 +350,9 @@ export interface ChangeHistoryItem {
createUserName: string;
versionName: string;
}
//取消前后置依赖关系
export interface DeleteDependencyParams {
id: string;
caseId: string;
type: string;
}

View File

@ -23,6 +23,8 @@
:placeholder="t('caseManagement.featureCase.searchByNameAndId')"
allow-clear
class="mx-[8px] w-[240px]"
@search="searchDependCase"
@press-enter="searchDependCase"
></a-input-search>
</div>
</div>
@ -171,7 +173,12 @@
async function cancelDependency(record: any) {
cancelLoading.value = true;
try {
await cancelPreOrPostCase(record.id);
const params = {
id: record.id,
caseId: record.caseId,
type: showType.value === 'preposition' ? 'PRE' : 'POST',
};
await cancelPreOrPostCase(params);
Message.success(t('caseManagement.featureCase.cancelFollowSuccess'));
initData();
} catch (error) {
@ -194,6 +201,11 @@
initData();
}
async function searchDependCase() {
getParams();
await loadList();
}
watch(
() => showType.value,
(val) => {