feat(接口测试): 引入公共脚本的表格增加创建人筛选

--bug=1037457 --user=宋天阳 【接口测试】定义-调试-后置-脚本操作-插入公共脚本-创建人没有筛选功能 https://www.tapd.cn/55049933/s/1481281
This commit is contained in:
song-tianyang 2024-03-26 19:45:35 +08:00 committed by Craftsman
parent f385215320
commit 7df04bc7bb
10 changed files with 118 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package io.metersphere.project.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import io.metersphere.project.domain.CustomFunction;
import io.metersphere.project.dto.customfunction.CustomFuncColumnsOptionDTO;
import io.metersphere.project.dto.customfunction.CustomFunctionDTO;
import io.metersphere.project.dto.customfunction.request.CustomFunctionPageRequest;
import io.metersphere.project.dto.customfunction.request.CustomFunctionRequest;
@ -48,6 +49,14 @@ public class CustomFunctionController {
return PageUtils.setPageInfo(page, customFunctionService.getPage(request));
}
@GetMapping("/columns-option/{projectId}")
@Operation(summary = "项目管理-公共脚本-请求头筛选相关选项")
@RequiresPermissions(PermissionConstants.PROJECT_CUSTOM_FUNCTION_READ)
@CheckOwner(resourceId = "#projectId", resourceType = "project")
public CustomFuncColumnsOptionDTO getColumnsOption(@PathVariable String projectId) {
return customFunctionService.getColumnsOption(projectId);
}
@GetMapping("/detail/{id}")
@Operation(summary = "项目管理-公共脚本-脚本详情")
@RequiresPermissions(PermissionConstants.PROJECT_CUSTOM_FUNCTION_READ)

View File

@ -0,0 +1,17 @@
package io.metersphere.project.dto.customfunction;
import io.metersphere.plugin.platform.dto.SelectOption;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CustomFuncColumnsOptionDTO {
@Schema(description = "用户相关的下拉选项")
List<SelectOption> userOption;
}

View File

@ -54,6 +54,10 @@
and c.status in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<when test="key=='createUser'">
and c.create_user in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
</choose>
</if>
</foreach>

View File

@ -1,9 +1,12 @@
package io.metersphere.project.service;
import io.metersphere.plugin.platform.dto.SelectOption;
import io.metersphere.project.domain.CustomFunction;
import io.metersphere.project.domain.CustomFunctionBlob;
import io.metersphere.project.domain.CustomFunctionBlobExample;
import io.metersphere.project.domain.CustomFunctionExample;
import io.metersphere.project.dto.ProjectUserDTO;
import io.metersphere.project.dto.customfunction.CustomFuncColumnsOptionDTO;
import io.metersphere.project.dto.customfunction.CustomFunctionDTO;
import io.metersphere.project.dto.customfunction.request.CustomFunctionPageRequest;
import io.metersphere.project.dto.customfunction.request.CustomFunctionRequest;
@ -13,6 +16,7 @@ import io.metersphere.project.enums.result.ProjectResultCode;
import io.metersphere.project.mapper.CustomFunctionBlobMapper;
import io.metersphere.project.mapper.CustomFunctionMapper;
import io.metersphere.project.mapper.ExtCustomFunctionMapper;
import io.metersphere.project.request.ProjectMemberRequest;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.uid.IDGenerator;
@ -35,6 +39,9 @@ import java.util.Optional;
@Transactional(rollbackFor = Exception.class)
public class CustomFunctionService {
@Resource
ProjectMemberService projectMemberService;
@Resource
CustomFunctionMapper customFunctionMapper;
@ -184,4 +191,18 @@ public class CustomFunctionService {
.andIdIn(commonScriptIds);
return customFunctionMapper.selectByExample(example);
}
public CustomFuncColumnsOptionDTO getColumnsOption(String projectId) {
ProjectMemberRequest request = new ProjectMemberRequest();
request.setProjectId(projectId);
List<ProjectUserDTO> projectMembers = projectMemberService.listMember(request);
List<SelectOption> selectOptions = projectMembers.stream().map(user -> {
SelectOption option = new SelectOption();
option.setText(user.getName());
option.setValue(user.getId());
return option;
}).toList();
return new CustomFuncColumnsOptionDTO(selectOptions);
}
}

View File

@ -30,8 +30,6 @@ import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author: LAN
@ -50,6 +48,8 @@ public class CustomFunctionControllerTests extends BaseTest {
private static final String DETAIL = BASE_PATH + "detail/";
private static final String STATUS = BASE_PATH + "status";
private static final String COLUMNS_OPTION = BASE_PATH + "columns-option/";
private static CustomFunction customFunction;
@Resource
@ -332,6 +332,15 @@ public class CustomFunctionControllerTests extends BaseTest {
request.setFilter(filters);
}
@Test
@Order(10)
public void columnsOption() throws Exception {
// @@请求成功
this.requestGetWithOk(COLUMNS_OPTION + DEFAULT_PROJECT_ID);
// @@校验权限
requestGetPermissionTest(PermissionConstants.PROJECT_CUSTOM_FUNCTION_READ, COLUMNS_OPTION + "/" + DEFAULT_PROJECT_ID);
}
@Test
@Order(11)
public void testUncoveredFunc() {

View File

@ -359,8 +359,11 @@ public class UserService {
*/
private void checkProcessUserAndThrowException(List<String> userIdList, String operatorId, String operatorName, String exceptionMessage) {
for (String userId : userIdList) {
if (StringUtils.equalsAny(userId, "admin", operatorId)) {
//当前用户或admin不能被操作
if (StringUtils.equals(userId, operatorId)) {
throw new MSException(exceptionMessage + ":" + operatorName);
} else if (StringUtils.equals(userId, "admin")) {
throw new MSException(exceptionMessage + ": admin");
}
}
}

View File

@ -6,6 +6,7 @@ import {
GetCommonScriptDetailUrl,
GetCommonScriptPageUrl,
GetCommonScriptStatusUrl,
GetCustomFuncColumnsOptionUrl,
GetFormApiImportModuleCountUrl,
GetFormApiImportPageListUrl,
GetFormApiImportUrl,
@ -21,6 +22,7 @@ import type {
CommonScriptItem,
TestScriptType,
} from '@/models/projectManagement/commonScript';
import { CustomFuncColumnOptionItem } from '@/models/projectManagement/commonScript';
// 获取公共脚本列表
export function getCommonScriptPage(data: TableQueryParams) {
@ -56,6 +58,13 @@ export function getInsertCommonScriptPage(data: TableQueryParams) {
return MSR.post<CommonList<CommonScriptItem[]>>({ url: GetInsertCommonScriptPageUrl, data });
}
/**
*
*/
export function getCustomFuncColumnOption(projectId: string) {
return MSR.get<CustomFuncColumnOptionItem>({ url: `${GetCustomFuncColumnsOptionUrl}${projectId}` });
}
// 获取从Api导入
export function getFormApiImportModule(data: TableQueryParams) {
return MSR.post<ModulesTreeType[]>({ url: GetFormApiImportUrl, data });

View File

@ -12,6 +12,9 @@ export const DeleteCommonScriptUrl = '/project/custom/func/delete';
export const GetCommonScriptStatusUrl = '/project/custom/func/status';
// 插入公共脚
export const GetInsertCommonScriptPageUrl = '/project/custom/func/page';
export const GetCustomFuncColumnsOptionUrl = '/project/custom/func/columns-option/';
// 获取公共脚本从Api导入
export const GetFormApiImportUrl = '/api/definition/module/tree';
// 获取从api导入列表

View File

@ -60,6 +60,20 @@
</a-popover>
</div>
</template>
<template #createUserFilter="{ columnConfig }">
<TableFilter
v-model:visible="createUserFilterVisible"
v-model:status-filters="createUserFilterValue"
:title="(columnConfig.title as string)"
:list="createUserFilterOptions"
value-key="value"
@search="initData()"
>
<template #item="{ item }">
{{ item.text }}
</template>
</TableFilter>
</template>
<template #status="{ record }">
<MsTag v-if="record.status === 'PASSED'" type="success" theme="light">{{
t('project.commonScript.testsPass')
@ -93,11 +107,17 @@
import type { MsTableColumn } from '@/components/pure/ms-table/type';
import useTable from '@/components/pure/ms-table/useTable';
import MsTag from '@/components/pure/ms-tag/ms-tag.vue';
import TableFilter from '@/views/case-management/caseManagementFeature/components/tableFilter.vue';
import { addOrUpdateCommonScriptReq, getInsertCommonScriptPage } from '@/api/modules/project-management/commonScript';
import {
addOrUpdateCommonScriptReq,
getCustomFuncColumnOption,
getInsertCommonScriptPage,
} from '@/api/modules/project-management/commonScript';
import { useI18n } from '@/hooks/useI18n';
import useAppStore from '@/store/modules/app';
import { BugOptionItem } from '@/models/bug-management';
import type { AddOrUpdateCommonScript, ParamsRequestType } from '@/models/projectManagement/commonScript';
import Message from '@arco-design/web-vue/es/message';
@ -131,7 +151,9 @@
emit('update:visible', val);
},
});
const createUserFilterOptions = ref<BugOptionItem[]>([]);
const createUserFilterVisible = ref(false);
const createUserFilterValue = ref<string[]>([]);
const keyword = ref<string>('');
const columns: MsTableColumn = [
@ -169,6 +191,7 @@
{
title: 'project.commonScript.createUser',
dataIndex: 'createUserName',
titleSlotName: 'createUserFilter',
showInTable: true,
width: 200,
showDrag: true,
@ -238,6 +261,9 @@
keyword: keyword.value,
projectId: currentProjectId.value,
type: props.scriptLanguage,
filter: {
createUser: createUserFilterValue.value,
},
});
loadList();
}
@ -301,11 +327,17 @@
}
}
async function initFilterOptions() {
const res = await getCustomFuncColumnOption(appStore.currentProjectId);
createUserFilterOptions.value = res.userOption;
}
watch(
() => props.visible,
(val) => {
if (val) {
resetSelector();
initFilterOptions();
initData();
}
}

View File

@ -6,6 +6,12 @@ export interface CommonScriptMenu {
command?: string;
}
export interface CustomFuncColumnOptionItem {
userOption: {
value: string; // 缺陷id
text: string; // 缺陷编号
}[]; // 用户相关下拉选项
}
// 脚本列表
export interface CommonScriptItem {
id: string;