refactor(权限管理): 接口测试权限 处理冲突

This commit is contained in:
Captain.B 2021-05-21 15:58:30 +08:00 committed by 刘瑞斌
parent 60e8036c2a
commit 0e1ffbf873
12 changed files with 1519 additions and 1409 deletions

View File

@ -21,7 +21,7 @@ import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
import io.metersphere.track.request.testplan.FileOperationRequest;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@ -33,14 +33,13 @@ import java.util.List;
@RestController
@RequestMapping(value = "/api/automation")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public class ApiAutomationController {
@Resource
ApiAutomationService apiAutomationService;
@PostMapping("/list/{goPage}/{pageSize}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ")
public Pager<List<ApiScenarioDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
@ -48,26 +47,26 @@ public class ApiAutomationController {
}
@PostMapping("/list/all")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ")
public List<ApiScenarioWithBLOBs> listAll(@RequestBody ApiScenarioBatchRequest request) {
return apiAutomationService.listAll(request);
}
@PostMapping("/listWithIds/all")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ")
public List<ApiScenarioWithBLOBs> listWithIds(@RequestBody ApiScenarioBatchRequest request) {
return apiAutomationService.listWithIds(request);
}
@PostMapping("/id/all")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ")
public List<String> idAll(@RequestBody ApiScenarioBatchRequest request) {
return apiAutomationService.idAll(request);
}
@GetMapping("/list/{projectId}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ")
public List<ApiScenarioDTO> list(@PathVariable String projectId) {
ApiScenarioRequest request = new ApiScenarioRequest();
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
@ -77,6 +76,7 @@ public class ApiAutomationController {
@PostMapping(value = "/create")
@MsAuditLog(module = "api_automation", type = OperLogConstants.CREATE, title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = ApiAutomationService.class)
@RequiresPermissions("PROJECT_API_SCENARIO:READ+CREATE")
public ApiScenario create(@RequestPart("request") SaveApiScenarioRequest request, @RequestPart(value = "bodyFiles") List<MultipartFile> bodyFiles,
@RequestPart(value = "scenarioFiles") List<MultipartFile> scenarioFiles) {
return apiAutomationService.create(request, bodyFiles, scenarioFiles);
@ -84,6 +84,7 @@ public class ApiAutomationController {
@PostMapping(value = "/update")
@MsAuditLog(module = "api_automation", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = ApiAutomationService.class)
@RequiresPermissions("PROJECT_API_SCENARIO:READ+EDIT")
public void update(@RequestPart("request") SaveApiScenarioRequest request, @RequestPart(value = "bodyFiles") List<MultipartFile> bodyFiles,
@RequestPart(value = "scenarioFiles") List<MultipartFile> scenarioFiles) {
apiAutomationService.update(request, bodyFiles, scenarioFiles);
@ -91,6 +92,7 @@ public class ApiAutomationController {
@GetMapping("/delete/{id}")
@MsAuditLog(module = "api_automation", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = ApiAutomationService.class)
@RequiresPermissions("PROJECT_API_SCENARIO:READ+delete")
public void delete(@PathVariable String id) {
apiAutomationService.delete(id);
}
@ -186,14 +188,14 @@ public class ApiAutomationController {
}
@PostMapping("/batch/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ+EDIT")
@MsAuditLog(module = "api_automation", type = OperLogConstants.BATCH_UPDATE, beforeEvent = "#msClass.getLogDetails(#request.ids)", content = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class)
public void bathEdit(@RequestBody ApiScenarioBatchRequest request) {
apiAutomationService.bathEdit(request);
}
@PostMapping("/batch/update/env")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ+EDIT")
@MsAuditLog(module = "api_automation", type = OperLogConstants.BATCH_UPDATE, beforeEvent = "#msClass.getLogDetails(#request.ids)", content = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class)
public void batchUpdateEnv(@RequestBody ApiScenarioBatchRequest request) {
apiAutomationService.batchUpdateEnv(request);
@ -246,21 +248,21 @@ public class ApiAutomationController {
}
@PostMapping(value = "/import", consumes = {"multipart/form-data"})
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ+IMPORT_SCENARIO")
@MsAuditLog(module = "api_automation", type = OperLogConstants.IMPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId")
public ScenarioImport scenarioImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) {
return apiAutomationService.scenarioImport(file, request);
}
@PostMapping(value = "/export")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ+EXPORT_SCENARIO")
@MsAuditLog(module = "api_automation", type = OperLogConstants.EXPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId")
public ApiScenrioExportResult export(@RequestBody ApiScenarioBatchRequest request) {
return apiAutomationService.export(request);
}
@PostMapping(value = "/export/jmx")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_SCENARIO:READ+EXPORT_SCENARIO")
@MsAuditLog(module = "api_automation", type = OperLogConstants.EXPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId")
public List<ApiScenrioExportJmx> exportJmx(@RequestBody ApiScenarioBatchRequest request) {
return apiAutomationService.exportJmx(request);

View File

@ -20,7 +20,6 @@ import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.base.domain.Schedule;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.json.JSONSchemaGenerator;
import io.metersphere.commons.utils.CronUtils;
import io.metersphere.commons.utils.PageUtils;
@ -32,9 +31,7 @@ import io.metersphere.service.CheckPermissionService;
import io.metersphere.service.ScheduleService;
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -97,7 +94,7 @@ public class ApiDefinitionController {
@PostMapping(value = "/create", consumes = {"multipart/form-data"})
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+CREATE_API")
@MsAuditLog(module = "api_definition", type = OperLogConstants.CREATE, title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = ApiDefinitionService.class)
public void create(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
checkPermissionService.checkProjectOwner(request.getProjectId());
@ -105,7 +102,7 @@ public class ApiDefinitionController {
}
@PostMapping(value = "/update", consumes = {"multipart/form-data"})
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+EDIT_API")
@MsAuditLog(module = "api_definition", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = ApiDefinitionService.class)
public ApiDefinitionWithBLOBs update(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
checkPermissionService.checkProjectOwner(request.getProjectId());
@ -113,14 +110,14 @@ public class ApiDefinitionController {
}
@GetMapping("/delete/{id}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+DELETE")
@MsAuditLog(module = "api_definition", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = ApiDefinitionService.class)
public void delete(@PathVariable String id) {
apiDefinitionService.delete(id);
}
@PostMapping("/deleteBatch")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+DELETE")
@MsAuditLog(module = "api_definition", type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#request.ids)", msClass = ApiDefinitionService.class)
public void deleteBatch(@RequestBody List<String> ids) {
apiDefinitionService.deleteBatch(ids);
@ -142,14 +139,14 @@ public class ApiDefinitionController {
}
@PostMapping("/removeToGc")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+DELETE")
@MsAuditLog(module = "api_definition", type = OperLogConstants.GC, beforeEvent = "#msClass.getLogDetails(#ids)", msClass = ApiDefinitionService.class)
public void removeToGc(@RequestBody List<String> ids) {
apiDefinitionService.removeToGc(ids);
}
@PostMapping("/removeToGcByParams")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+DELETE")
@MsAuditLog(module = "api_definition", type = OperLogConstants.BATCH_GC, beforeEvent = "#msClass.getLogDetails(#request.ids)", msClass = ApiDefinitionService.class)
public void removeToGcByParams(@RequestBody ApiBatchRequest request) {
apiDefinitionService.removeToGcByParams(request);
@ -195,14 +192,14 @@ public class ApiDefinitionController {
}
@PostMapping(value = "/import", consumes = {"multipart/form-data"})
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+IMPORT_API")
@MsAuditLog(module = "api_definition", type = OperLogConstants.IMPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId")
public ApiDefinitionImport testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) {
return apiDefinitionService.apiTestImport(file, request);
}
@PostMapping(value = "/export/{type}")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+EXPORT_API")
@MsAuditLog(module = "api_definition", type = OperLogConstants.EXPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId")
public ApiExportResult export(@RequestBody ApiBatchRequest request, @PathVariable String type) {
return apiDefinitionService.export(request, type);
@ -262,13 +259,13 @@ public class ApiDefinitionController {
}
@PostMapping("/batch/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+EDIT_API")
public void editApiBath(@RequestBody ApiBatchRequest request) {
apiDefinitionService.editApiBath(request);
}
@PostMapping("/batch/editByParams")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+EDIT_API")
@MsAuditLog(module = "api_definition", type = OperLogConstants.BATCH_UPDATE, beforeEvent = "#msClass.getLogDetails(#request)", content = "#msClass.getLogDetails(#request)", msClass = ApiDefinitionService.class)
public void editByParams(@RequestBody ApiBatchRequest request) {
apiDefinitionService.editApiByParam(request);
@ -291,7 +288,7 @@ public class ApiDefinitionController {
}
@GetMapping("/export/esbExcelTemplate")
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_API_DEFINITION:READ+EXPORT_API")
public void testCaseTemplateExport(HttpServletResponse response) {
esbImportService.templateExport(response);
}

View File

@ -41,7 +41,8 @@
:name="item.name"
closable>
<div class="ms-api-scenario-div">
<ms-edit-api-scenario @refresh="refresh" @openScenario="editScenario" @closePage="closePage" :currentScenario="item.currentScenario"
<ms-edit-api-scenario @refresh="refresh" @openScenario="editScenario" @closePage="closePage"
:currentScenario="item.currentScenario"
:custom-num="customNum" :moduleOptions="moduleOptions" ref="autoScenarioConfig"/>
</div>
</el-tab-pane>
@ -51,7 +52,10 @@
<el-dropdown @command="handleCommand" v-tester>
<el-button type="primary" plain icon="el-icon-plus" size="mini" v-tester/>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="ADD">{{ $t('api_test.automation.add_scenario') }}</el-dropdown-item>
<el-dropdown-item command="ADD"
v-permission="['PROJECT_API_SCENARIO:READ+CREATE']">
{{ $t('api_test.automation.add_scenario') }}
</el-dropdown-item>
<el-dropdown-item command="CLOSE_ALL">{{ $t('api_test.definition.request.close_all_label') }}
</el-dropdown-item>
</el-dropdown-menu>
@ -65,13 +69,13 @@
<script>
import MsContainer from "@/business/components/common/components/MsContainer";
import MsAsideContainer from "@/business/components/common/components/MsAsideContainer";
import MsMainContainer from "@/business/components/common/components/MsMainContainer";
import MsApiScenarioList from "@/business/components/api/automation/scenario/ApiScenarioList";
import {getUUID, downloadFile, checkoutTestManagerOrTestUser, getCurrentUser} from "@/common/js/utils";
import MsApiScenarioModule from "@/business/components/api/automation/scenario/ApiScenarioModule";
import MsEditApiScenario from "./scenario/EditApiScenario";
import MsContainer from "@/business/components/common/components/MsContainer";
import MsAsideContainer from "@/business/components/common/components/MsAsideContainer";
import MsMainContainer from "@/business/components/common/components/MsMainContainer";
import MsApiScenarioList from "@/business/components/api/automation/scenario/ApiScenarioList";
import {checkoutTestManagerOrTestUser, getCurrentUser, getUUID} from "@/common/js/utils";
import MsApiScenarioModule from "@/business/components/api/automation/scenario/ApiScenarioModule";
import MsEditApiScenario from "./scenario/EditApiScenario";
export default {
name: "ApiAutomation",
@ -228,137 +232,137 @@
currentScenario.modulePath = this.currentModulePath;
}
if (this.selectNodeIds && this.selectNodeIds.length > 0) {
currentScenario.apiScenarioModuleId = this.selectNodeIds[0];
this.getPath(this.selectNodeIds[0], this.moduleOptions);
currentScenario.modulePath = this.currentModulePath;
}
this.tabs.push({label: label, name: name, currentScenario: currentScenario});
if (this.selectNodeIds && this.selectNodeIds.length > 0) {
currentScenario.apiScenarioModuleId = this.selectNodeIds[0];
this.getPath(this.selectNodeIds[0], this.moduleOptions);
currentScenario.modulePath = this.currentModulePath;
}
if (tab.name === 'edit') {
let label = this.$t('api_test.automation.add_scenario');
let name = getUUID().substring(0, 8);
this.activeName = name;
label = tab.currentScenario.name;
this.tabs.push({label: label, name: name, currentScenario: tab.currentScenario});
}
if (this.$refs && this.$refs.autoScenarioConfig) {
this.$refs.autoScenarioConfig.forEach(item => {
item.removeListener();
}); // tab ctrl + s
this.addListener();
}
},
addListener() {
let index = this.tabs.findIndex(item => item.name === this.activeName); // tabindex
if (index != -1) { // tab
this.$nextTick(() => {
this.$refs.autoScenarioConfig[index].addListener();
});
}
},
handleTabClose() {
this.tabs = [];
this.activeName = "default";
this.refresh();
},
handleCommand(e) {
switch (e) {
case "ADD":
this.addTab({name: 'add'});
break;
case "CLOSE_ALL":
this.handleTabClose();
break;
default:
this.addTab({name: 'add'});
break;
}
},
closePage(targetName) {
this.tabs = this.tabs.filter(tab => tab.label !== targetName);
if (this.tabs.length > 0) {
this.activeName = this.tabs[this.tabs.length - 1].name;
this.addListener(); //
} else {
this.activeName = "default"
}
},
removeTab(targetName) {
this.tabs = this.tabs.filter(tab => tab.name !== targetName);
if (this.tabs.length > 0) {
this.activeName = this.tabs[this.tabs.length - 1].name;
this.addListener(); //
} else {
this.activeName = "default"
}
},
setTabLabel(data) {
for (const tab of this.tabs) {
if (tab.name === this.activeName) {
tab.label = data.name;
break;
}
}
},
selectModule(data) {
this.currentModule = data;
},
saveScenario(data) {
this.setTabLabel(data);
this.$refs.apiScenarioList.search(data);
},
refresh(data) {
this.setTabTitle(data);
this.$refs.apiScenarioList.search(data);
},
refreshAll() {
this.$refs.nodeTree.list();
this.$refs.apiScenarioList.search();
},
setTabTitle(data) {
for (let index in this.tabs) {
let tab = this.tabs[index];
if (tab.name === this.activeName) {
tab.label = data.name;
break;
}
}
},
editScenario(row) {
this.addTab({name: 'edit', currentScenario: row});
},
nodeChange(node, nodeIds, pNodes) {
this.selectNodeIds = nodeIds;
},
setModuleOptions(data) {
this.moduleOptions = data;
},
setNodeTree(data) {
this.nodeTree = data;
},
changeSelectDataRangeAll(tableType) {
this.$route.params.dataSelectRange = 'all';
},
enableTrash(data) {
this.activeName = "default";
this.trashEnable = data;
},
getProject() {
this.$get("/project/get/" + this.projectId, result => {
let data = result.data;
if (data) {
this.customNum = data.scenarioCustomNum;
}
})
this.tabs.push({label: label, name: name, currentScenario: currentScenario});
}
if (tab.name === 'edit') {
let label = this.$t('api_test.automation.add_scenario');
let name = getUUID().substring(0, 8);
this.activeName = name;
label = tab.currentScenario.name;
this.tabs.push({label: label, name: name, currentScenario: tab.currentScenario});
}
if (this.$refs && this.$refs.autoScenarioConfig) {
this.$refs.autoScenarioConfig.forEach(item => {
item.removeListener();
}); // tab ctrl + s
this.addListener();
}
},
addListener() {
let index = this.tabs.findIndex(item => item.name === this.activeName); // tabindex
if (index != -1) { // tab
this.$nextTick(() => {
this.$refs.autoScenarioConfig[index].addListener();
});
}
},
handleTabClose() {
this.tabs = [];
this.activeName = "default";
this.refresh();
},
handleCommand(e) {
switch (e) {
case "ADD":
this.addTab({name: 'add'});
break;
case "CLOSE_ALL":
this.handleTabClose();
break;
default:
this.addTab({name: 'add'});
break;
}
},
closePage(targetName) {
this.tabs = this.tabs.filter(tab => tab.label !== targetName);
if (this.tabs.length > 0) {
this.activeName = this.tabs[this.tabs.length - 1].name;
this.addListener(); //
} else {
this.activeName = "default";
}
},
removeTab(targetName) {
this.tabs = this.tabs.filter(tab => tab.name !== targetName);
if (this.tabs.length > 0) {
this.activeName = this.tabs[this.tabs.length - 1].name;
this.addListener(); //
} else {
this.activeName = "default";
}
},
setTabLabel(data) {
for (const tab of this.tabs) {
if (tab.name === this.activeName) {
tab.label = data.name;
break;
}
}
},
selectModule(data) {
this.currentModule = data;
},
saveScenario(data) {
this.setTabLabel(data);
this.$refs.apiScenarioList.search(data);
},
refresh(data) {
this.setTabTitle(data);
this.$refs.apiScenarioList.search(data);
},
refreshAll() {
this.$refs.nodeTree.list();
this.$refs.apiScenarioList.search();
},
setTabTitle(data) {
for (let index in this.tabs) {
let tab = this.tabs[index];
if (tab.name === this.activeName) {
tab.label = data.name;
break;
}
}
},
editScenario(row) {
this.addTab({name: 'edit', currentScenario: row});
},
nodeChange(node, nodeIds, pNodes) {
this.selectNodeIds = nodeIds;
},
setModuleOptions(data) {
this.moduleOptions = data;
},
setNodeTree(data) {
this.nodeTree = data;
},
changeSelectDataRangeAll(tableType) {
this.$route.params.dataSelectRange = 'all';
},
enableTrash(data) {
this.activeName = "default";
this.trashEnable = data;
},
getProject() {
this.$get("/project/get/" + this.projectId, result => {
let data = result.data;
if (data) {
this.customNum = data.scenarioCustomNum;
}
});
}
}
};
</script>
<style scoped>
/deep/ .el-tabs__header {
margin: 0 0 0px;
}
/deep/ .el-tabs__header {
margin: 0 0 0px;
}
</style>

View File

@ -61,6 +61,7 @@
<ms-table-operator-button :tip="$t('api_report.detail')" icon="el-icon-s-data"
@exec="handleView(scope.row)" type="primary"/>
<ms-table-operator-button :is-tester-permission="true" :tip="$t('api_report.delete')"
v-permission="['PROJECT_API_REPORT:READ+DELETE']"
icon="el-icon-delete" @exec="handleDelete(scope.row)" type="danger"/>
</template>
</el-table-column>

View File

@ -89,14 +89,17 @@
operators: [
{
label: this.$t('api_test.automation.add_scenario'),
callback: this.addScenario
callback: this.addScenario,
permissions: ['PROJECT_API_SCENARIO:READ+CREATE']
},
{
label: this.$t('api_test.api_import.label'),
callback: this.handleImport
callback: this.handleImport,
permissions: ['PROJECT_API_SCENARIO:READ+IMPORT_SCENARIO']
},
{
label: this.$t('report.export'),
permissions: ['PROJECT_API_SCENARIO:READ+EXPORT_SCENARIO'],
children: [
{
label: this.$t('report.export_to_ms_format'),

View File

@ -6,8 +6,11 @@
</el-link>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="ref">{{ $t('api_test.automation.view_ref') }}</el-dropdown-item>
<el-dropdown-item command="schedule" v-tester>{{ $t('api_test.automation.schedule') }}</el-dropdown-item>
<el-dropdown-item command="create_performance" v-tester v-modules="['performance']">
<el-dropdown-item command="schedule" v-permission="['PROJECT_API_SCENARIO:READ+SCHEDULE']">
{{ $t('api_test.automation.schedule') }}
</el-dropdown-item>
<el-dropdown-item command="create_performance" v-permission="['PROJECT_API_SCENARIO:READ+CREATE_PERFORMANCE']"
v-modules="['performance']">
{{ $t('api_test.create_performance_test') }}
</el-dropdown-item>
</el-dropdown-menu>
@ -19,68 +22,68 @@
</template>
<script>
import MsReferenceView from "@/business/components/api/automation/scenario/ReferenceView";
import MsScheduleMaintain from "@/business/components/api/automation/schedule/ScheduleMaintain"
import {getCurrentProjectID, getUUID} from "@/common/js/utils";
export default {
name: "MsScenarioExtendButtons",
components: {MsReferenceView, MsScheduleMaintain},
props: {
row: Object
},
methods: {
handleCommand(cmd) {
switch (cmd) {
case "ref":
this.$refs.viewRef.open(this.row);
break;
case "schedule":
this.$refs.scheduleMaintain.open(this.row);
break;
case "create_performance":
this.createPerformance(this.row);
break;
}
},
createPerformance(row) {
this.infoDb = false;
let url = "/api/automation/genPerformanceTestJmx";
let run = {};
let scenarioIds = [];
scenarioIds.push(row.id);
run.projectId = getCurrentProjectID();
run.ids = scenarioIds;
run.id = getUUID();
run.name = row.name;
this.$post(url, run, response => {
let jmxObj = {};
jmxObj.name = response.data.name;
jmxObj.xml = response.data.xml;
jmxObj.attachFiles = response.data.attachFiles;
jmxObj.attachByteFiles = response.data.attachByteFiles;
jmxObj.scenarioId = row.id;
this.$store.commit('setTest', {
name: row.name,
jmx: jmxObj
})
this.$router.push({
path: "/performance/test/create"
})
});
},
openScenario (item) {
this.$emit('openScenario', item)
},
refreshTable() {
import MsReferenceView from "@/business/components/api/automation/scenario/ReferenceView";
import MsScheduleMaintain from "@/business/components/api/automation/schedule/ScheduleMaintain";
import {getCurrentProjectID, getUUID} from "@/common/js/utils";
export default {
name: "MsScenarioExtendButtons",
components: {MsReferenceView, MsScheduleMaintain},
props: {
row: Object
},
methods: {
handleCommand(cmd) {
switch (cmd) {
case "ref":
this.$refs.viewRef.open(this.row);
break;
case "schedule":
this.$refs.scheduleMaintain.open(this.row);
break;
case "create_performance":
this.createPerformance(this.row);
break;
}
},
createPerformance(row) {
this.infoDb = false;
let url = "/api/automation/genPerformanceTestJmx";
let run = {};
let scenarioIds = [];
scenarioIds.push(row.id);
run.projectId = getCurrentProjectID();
run.ids = scenarioIds;
run.id = getUUID();
run.name = row.name;
this.$post(url, run, response => {
let jmxObj = {};
jmxObj.name = response.data.name;
jmxObj.xml = response.data.xml;
jmxObj.attachFiles = response.data.attachFiles;
jmxObj.attachByteFiles = response.data.attachByteFiles;
jmxObj.scenarioId = row.id;
this.$store.commit('setTest', {
name: row.name,
jmx: jmxObj
});
this.$router.push({
path: "/performance/test/create"
});
});
},
openScenario(item) {
this.$emit('openScenario', item);
},
refreshTable() {
}
}
};
</script>
<style scoped>
.scenario-ext-btn {
margin-left: 10px;
}
.scenario-ext-btn {
margin-left: 10px;
}
</style>

View File

@ -84,13 +84,17 @@
</div>
<!-- 快捷调试 -->
<div v-else-if="item.type=== 'debug'" class="ms-api-div">
<ms-debug-http-page :currentProtocol="currentProtocol" :testCase="item.api" @saveAs="editApi" @refreshModule="refreshModule"
<ms-debug-http-page :currentProtocol="currentProtocol" :testCase="item.api" @saveAs="editApi"
@refreshModule="refreshModule"
v-if="currentProtocol==='HTTP'"/>
<ms-debug-jdbc-page :currentProtocol="currentProtocol" :testCase="item.api" @saveAs="editApi" @refreshModule="refreshModule"
<ms-debug-jdbc-page :currentProtocol="currentProtocol" :testCase="item.api" @saveAs="editApi"
@refreshModule="refreshModule"
v-if="currentProtocol==='SQL'"/>
<ms-debug-tcp-page :currentProtocol="currentProtocol" :testCase="item.api" @saveAs="editApi" @refreshModule="refreshModule"
<ms-debug-tcp-page :currentProtocol="currentProtocol" :testCase="item.api" @saveAs="editApi"
@refreshModule="refreshModule"
v-if="currentProtocol==='TCP'"/>
<ms-debug-dubbo-page :currentProtocol="currentProtocol" :testCase="item.api" @saveAs="editApi" @refreshModule="refreshModule"
<ms-debug-dubbo-page :currentProtocol="currentProtocol" :testCase="item.api" @saveAs="editApi"
@refreshModule="refreshModule"
v-if="currentProtocol==='DUBBO'"/>
</div>
@ -119,8 +123,12 @@
<el-dropdown @command="handleCommand" v-tester>
<el-button type="primary" plain icon="el-icon-plus" size="mini" v-tester/>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="debug">{{ $t('api_test.definition.request.fast_debug') }}</el-dropdown-item>
<el-dropdown-item command="ADD">{{ $t('api_test.definition.request.title') }}</el-dropdown-item>
<el-dropdown-item command="debug" v-permission="['PROJECT_API_DEFINITION:READ+DEBUG']">
{{ $t('api_test.definition.request.fast_debug') }}
</el-dropdown-item>
<el-dropdown-item command="ADD" v-permission="['PROJECT_API_DEFINITION:READ+CREATE_API']">
{{ $t('api_test.definition.request.title') }}
</el-dropdown-item>
<el-dropdown-item command="CLOSE_ALL">{{ $t('api_test.definition.request.close_all_label') }}
</el-dropdown-item>
</el-dropdown-menu>
@ -136,382 +144,388 @@
</div>
</template>
<script>
import MsApiList from './components/list/ApiList';
import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer";
import MsAsideContainer from "../../common/components/MsAsideContainer";
import MsApiConfig from "./components/ApiConfig";
import MsDebugHttpPage from "./components/debug/DebugHttpPage";
import MsDebugJdbcPage from "./components/debug/DebugJdbcPage";
import MsDebugTcpPage from "./components/debug/DebugTcpPage";
import MsDebugDubboPage from "./components/debug/DebugDubboPage";
import MsApiList from './components/list/ApiList';
import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer";
import MsAsideContainer from "../../common/components/MsAsideContainer";
import MsApiConfig from "./components/ApiConfig";
import MsDebugHttpPage from "./components/debug/DebugHttpPage";
import MsDebugJdbcPage from "./components/debug/DebugJdbcPage";
import MsDebugTcpPage from "./components/debug/DebugTcpPage";
import MsDebugDubboPage from "./components/debug/DebugDubboPage";
import MsRunTestHttpPage from "./components/runtest/RunTestHTTPPage";
import MsRunTestTcpPage from "./components/runtest/RunTestTCPPage";
import MsRunTestSqlPage from "./components/runtest/RunTestSQLPage";
import MsRunTestDubboPage from "./components/runtest/RunTestDubboPage";
import {checkoutTestManagerOrTestUser, getCurrentUser, getUUID} from "@/common/js/utils";
import MsApiModule from "./components/module/ApiModule";
import ApiCaseSimpleList from "./components/list/ApiCaseSimpleList";
import MsRunTestHttpPage from "./components/runtest/RunTestHTTPPage";
import MsRunTestTcpPage from "./components/runtest/RunTestTCPPage";
import MsRunTestSqlPage from "./components/runtest/RunTestSQLPage";
import MsRunTestDubboPage from "./components/runtest/RunTestDubboPage";
import {checkoutTestManagerOrTestUser, getCurrentUser, getUUID} from "@/common/js/utils";
import MsApiModule from "./components/module/ApiModule";
import ApiCaseSimpleList from "./components/list/ApiCaseSimpleList";
import ApiDocumentsPage from "@/business/components/api/definition/components/list/ApiDocumentsPage";
import MsTableButton from "@/business/components/common/components/MsTableButton";
import MsTabButton from "@/business/components/common/components/MsTabButton";
import {getLabel} from "@/common/js/tableUtils";
import {API_CASE_LIST, API_LIST} from "@/common/js/constants";
import ApiDocumentsPage from "@/business/components/api/definition/components/list/ApiDocumentsPage";
import MsTableButton from "@/business/components/common/components/MsTableButton";
import MsTabButton from "@/business/components/common/components/MsTabButton";
import {getLabel} from "@/common/js/tableUtils";
import {API_CASE_LIST, API_LIST} from "@/common/js/constants";
import MockConfig from "@/business/components/api/definition/components/mock/MockConfig";
import MockConfig from "@/business/components/api/definition/components/mock/MockConfig";
export default {
name: "ApiDefinition",
computed: {
queryDataType: function () {
let routeParam = this.$route.params.dataType;
let redirectIDParam = this.$route.params.redirectID;
this.changeRedirectParam(redirectIDParam);
return routeParam;
},
isReadOnly() {
return !checkoutTestManagerOrTestUser();
},
projectId() {
return this.$store.state.projectId
},
export default {
name: "ApiDefinition",
computed: {
queryDataType: function () {
let routeParam = this.$route.params.dataType;
let redirectIDParam = this.$route.params.redirectID;
this.changeRedirectParam(redirectIDParam);
return routeParam;
},
components: {
MsTabButton,
MsTableButton,
ApiCaseSimpleList,
MsApiModule,
MsApiList,
MsMainContainer,
MsContainer,
MsAsideContainer,
MsApiConfig,
MsDebugHttpPage,
MsRunTestHttpPage,
MsDebugJdbcPage,
MsDebugTcpPage,
MsDebugDubboPage,
MsRunTestTcpPage,
MsRunTestSqlPage,
MsRunTestDubboPage,
ApiDocumentsPage,
MockConfig
isReadOnly() {
return !checkoutTestManagerOrTestUser();
},
props: {
visible: {
type: Boolean,
default: false,
},
currentRow: {
type: Object,
}
projectId() {
return this.$store.state.projectId;
},
data() {
return {
redirectID: '',
renderComponent: true,
selectDataRange: 'all',
showCasePage: true,
apiDefaultTab: 'default',
currentProtocol: 'HTTP',
currentModule: null,
selectNodeIds: [],
currentApi: {},
moduleOptions: [],
trashEnable: false,
apiTabs: [{
title: this.$t('api_test.definition.api_title'),
name: 'default',
type: "list",
closable: false
}],
activeDom: "left",
syncTabs: [],
nodeTree: [],
currentModulePath: "",
}
},
components: {
MsTabButton,
MsTableButton,
ApiCaseSimpleList,
MsApiModule,
MsApiList,
MsMainContainer,
MsContainer,
MsAsideContainer,
MsApiConfig,
MsDebugHttpPage,
MsRunTestHttpPage,
MsDebugJdbcPage,
MsDebugTcpPage,
MsDebugDubboPage,
MsRunTestTcpPage,
MsRunTestSqlPage,
MsRunTestDubboPage,
ApiDocumentsPage,
MockConfig
},
props: {
visible: {
type: Boolean,
default: false,
},
created() {
let dataRange = this.$route.params.dataSelectRange;
if (dataRange && dataRange.length > 0) {
this.activeDom = 'middle';
}
if (this.activeDom === 'left') {
getLabel(this, API_LIST);
} else if (this.activeDom === 'right') {
getLabel(this, API_CASE_LIST);
currentRow: {
type: Object,
}
},
data() {
return {
redirectID: '',
renderComponent: true,
selectDataRange: 'all',
showCasePage: true,
apiDefaultTab: 'default',
currentProtocol: 'HTTP',
currentModule: null,
selectNodeIds: [],
currentApi: {},
moduleOptions: [],
trashEnable: false,
apiTabs: [{
title: this.$t('api_test.definition.api_title'),
name: 'default',
type: "list",
closable: false
}],
activeDom: "left",
syncTabs: [],
nodeTree: [],
currentModulePath: "",
};
},
created() {
let dataRange = this.$route.params.dataSelectRange;
if (dataRange && dataRange.length > 0) {
this.activeDom = 'middle';
}
if (this.activeDom === 'left') {
getLabel(this, API_LIST);
} else if (this.activeDom === 'right') {
getLabel(this, API_CASE_LIST);
}
}
},
watch: {
currentProtocol() {
this.handleCommand("CLOSE_ALL");
},
watch: {
currentProtocol() {
this.handleCommand("CLOSE_ALL");
},
selectNodeIds() {
this.apiDefaultTab = "default";
},
redirectID() {
this.renderComponent = false;
this.$nextTick(() => {
// DOM my-component
this.renderComponent = true;
});
},
'$route'(to, from) { // ctrl s
if (to.path.indexOf('/api/definition') === -1) {
if (this.$refs && this.$refs.apiConfig) {
this.$refs.apiConfig.forEach(item => {
item.removeListener();
});
}
}
}
selectNodeIds() {
this.apiDefaultTab = "default";
},
methods: {
getPath(id, arr) {
if (id === null) {
return null;
}
if(arr) {
arr.forEach(item => {
if (item.id === id) {
this.currentModulePath = item.path;
}
if (item.children && item.children.length > 0) {
this.getPath(id, item.children);
}
});
}
},
changeRedirectParam(redirectIDParam) {
this.redirectID = redirectIDParam;
},
addTab(tab) {
if (tab.name === 'add') {
this.handleTabsEdit(this.$t('api_test.definition.request.fast_debug'), "debug");
}
if (this.$refs.apiConfig) {
redirectID() {
this.renderComponent = false;
this.$nextTick(() => {
// DOM my-component
this.renderComponent = true;
});
},
'$route'(to, from) { // ctrl s
if (to.path.indexOf('/api/definition') === -1) {
if (this.$refs && this.$refs.apiConfig) {
this.$refs.apiConfig.forEach(item => {
item.removeListener();
}); // tab ctrl + s
let tabs = this.apiTabs;
let index = tabs.findIndex(item => item.name === tab.name); // tabindex
if (index !== -1 && this.$refs.apiConfig[index - 1]) {
this.$refs.apiConfig[index - 1].addListener(); // tab ctrl + s index-1tab
}
}
},
handleCommand(e) {
switch (e) {
case "ADD":
this.handleTabAdd(e);
break;
case "TEST":
this.handleTabsEdit(this.$t("commons.api"), e);
break;
case "CLOSE_ALL":
this.handleTabClose();
break;
default:
this.handleTabsEdit(this.$t('api_test.definition.request.fast_debug'), "debug");
break;
}
},
handleTabAdd(e) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
let api = {
status: "Underway", method: "GET", userId: getCurrentUser().id,
url: "", protocol: this.currentProtocol, environmentId: "", moduleId: 'default-module', modulePath: "/" + this.$t("commons.module_title")
};
this.currentModulePath = "";
if (this.nodeTree && this.nodeTree.length > 0) {
api.moduleId = this.nodeTree[0].id;
this.getPath(this.nodeTree[0].id, this.moduleOptions);
api.modulePath = this.currentModulePath;
}
if (this.selectNodeIds && this.selectNodeIds.length > 0) {
api.moduleId = this.selectNodeIds[0];
this.getPath(this.selectNodeIds[0], this.moduleOptions);
api.modulePath = this.currentModulePath;
}
this.handleTabsEdit(this.$t('api_test.definition.request.title'), e, api);
},
handleTabClose() {
let tabs = this.apiTabs[0];
this.apiTabs = [];
this.apiDefaultTab = tabs.name;
this.apiTabs.push(tabs);
},
handleTabRemove(targetName) {
let tabs = this.apiTabs;
let activeName = this.apiDefaultTab;
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
let nextTab = tabs[index + 1] || tabs[index - 1];
if (nextTab) {
activeName = nextTab.name;
}
}
});
}
this.apiDefaultTab = activeName;
this.apiTabs = tabs.filter(tab => tab.name !== targetName);
this.refresh();
},
//
createRootModel() {
this.$refs.nodeTree.createRootModel();
},
handleMockTabsConfig(targetName, action, param) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
if (targetName === undefined || targetName === null) {
targetName = this.$t('api_test.definition.request.title');
}
let newTabName = getUUID();
this.apiTabs.push({
title: targetName,
name: newTabName,
closable: true,
type: action,
mock: param,
});
this.apiDefaultTab = newTabName;
},
handleTabsEdit(targetName, action, api) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
if (targetName === undefined || targetName === null) {
targetName = this.$t('api_test.definition.request.title');
}
let newTabName = getUUID();
this.apiTabs.push({
title: targetName,
name: newTabName,
closable: true,
type: action,
api: api,
});
this.apiDefaultTab = newTabName;
},
debug(id) {
this.handleTabsEdit(this.$t('api_test.definition.request.fast_debug'), "debug", id);
},
editApi(row) {
let name = "";
if (row.isCopy) {
name = "copy" + "-" + row.name;
row.name = "copy" + "-" + row.name;
} else {
name = this.$t('api_test.definition.request.edit_api') + "-" + row.name;
}
this.handleTabsEdit(name, "ADD", row);
},
handleCase(api) {
this.currentApi = api;
this.showCasePage = false;
},
apiCaseClose() {
this.showCasePage = true;
},
exportAPI(type) {
if (this.activeDom !== 'left') {
this.$warning('用例列表暂不支持导出,请切换成接口列表');
return;
}
this.$refs.apiList[0].exportApi(type);
},
refreshModule() {
this.$refs.nodeTree.list();
},
refresh(data) {
this.$refs.apiList[0].initTable(data);
},
setTabTitle(data) {
for (let index in this.apiTabs) {
let tab = this.apiTabs[index];
if (tab.name === this.apiDefaultTab) {
tab.title = this.$t('api_test.definition.request.edit_api') + "-" + data.name;
break;
}
}
},
runTest(data) {
this.handleTabsEdit(this.$t("commons.api"), "TEST", data);
this.setTabTitle(data);
},
mockConfig(data) {
let targetName = this.$t("commons.mock") + "-" + data.apiName;
this.handleMockTabsConfig(targetName, "MOCK", data);
},
saveApi(data) {
this.setTabTitle(data);
this.refresh(data);
},
showExecResult(row) {
this.debug(row);
},
nodeChange(node, nodeIds, pNodes) {
this.selectNodeIds = nodeIds;
},
handleProtocolChange(protocol) {
this.currentProtocol = protocol;
},
setModuleOptions(data) {
this.moduleOptions = data;
},
setNodeTree(data) {
this.nodeTree = data;
},
changeSelectDataRangeAll(tableType) {
this.$route.params.dataSelectRange = 'all';
},
enableTrash(data) {
this.trashEnable = data;
}
}
},
methods: {
getPath(id, arr) {
if (id === null) {
return null;
}
if (arr) {
arr.forEach(item => {
if (item.id === id) {
this.currentModulePath = item.path;
}
if (item.children && item.children.length > 0) {
this.getPath(id, item.children);
}
});
}
},
changeRedirectParam(redirectIDParam) {
this.redirectID = redirectIDParam;
},
addTab(tab) {
if (tab.name === 'add') {
this.handleTabsEdit(this.$t('api_test.definition.request.fast_debug'), "debug");
}
if (this.$refs.apiConfig) {
this.$refs.apiConfig.forEach(item => {
item.removeListener();
}); // tab ctrl + s
let tabs = this.apiTabs;
let index = tabs.findIndex(item => item.name === tab.name); // tabindex
if (index !== -1 && this.$refs.apiConfig[index - 1]) {
this.$refs.apiConfig[index - 1].addListener(); // tab ctrl + s index-1tab
}
}
},
handleCommand(e) {
switch (e) {
case "ADD":
this.handleTabAdd(e);
break;
case "TEST":
this.handleTabsEdit(this.$t("commons.api"), e);
break;
case "CLOSE_ALL":
this.handleTabClose();
break;
default:
this.handleTabsEdit(this.$t('api_test.definition.request.fast_debug'), "debug");
break;
}
},
handleTabAdd(e) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
let api = {
status: "Underway",
method: "GET",
userId: getCurrentUser().id,
url: "",
protocol: this.currentProtocol,
environmentId: "",
moduleId: 'default-module',
modulePath: "/" + this.$t("commons.module_title")
};
this.currentModulePath = "";
if (this.nodeTree && this.nodeTree.length > 0) {
api.moduleId = this.nodeTree[0].id;
this.getPath(this.nodeTree[0].id, this.moduleOptions);
api.modulePath = this.currentModulePath;
}
if (this.selectNodeIds && this.selectNodeIds.length > 0) {
api.moduleId = this.selectNodeIds[0];
this.getPath(this.selectNodeIds[0], this.moduleOptions);
api.modulePath = this.currentModulePath;
}
this.handleTabsEdit(this.$t('api_test.definition.request.title'), e, api);
},
handleTabClose() {
let tabs = this.apiTabs[0];
this.apiTabs = [];
this.apiDefaultTab = tabs.name;
this.apiTabs.push(tabs);
},
handleTabRemove(targetName) {
let tabs = this.apiTabs;
let activeName = this.apiDefaultTab;
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
let nextTab = tabs[index + 1] || tabs[index - 1];
if (nextTab) {
activeName = nextTab.name;
}
}
});
}
this.apiDefaultTab = activeName;
this.apiTabs = tabs.filter(tab => tab.name !== targetName);
this.refresh();
},
//
createRootModel() {
this.$refs.nodeTree.createRootModel();
},
handleMockTabsConfig(targetName, action, param) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
if (targetName === undefined || targetName === null) {
targetName = this.$t('api_test.definition.request.title');
}
let newTabName = getUUID();
this.apiTabs.push({
title: targetName,
name: newTabName,
closable: true,
type: action,
mock: param,
});
this.apiDefaultTab = newTabName;
},
handleTabsEdit(targetName, action, api) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
if (targetName === undefined || targetName === null) {
targetName = this.$t('api_test.definition.request.title');
}
let newTabName = getUUID();
this.apiTabs.push({
title: targetName,
name: newTabName,
closable: true,
type: action,
api: api,
});
this.apiDefaultTab = newTabName;
},
debug(id) {
this.handleTabsEdit(this.$t('api_test.definition.request.fast_debug'), "debug", id);
},
editApi(row) {
let name = "";
if (row.isCopy) {
name = "copy" + "-" + row.name;
row.name = "copy" + "-" + row.name;
} else {
name = this.$t('api_test.definition.request.edit_api') + "-" + row.name;
}
this.handleTabsEdit(name, "ADD", row);
},
handleCase(api) {
this.currentApi = api;
this.showCasePage = false;
},
apiCaseClose() {
this.showCasePage = true;
},
exportAPI(type) {
if (this.activeDom !== 'left') {
this.$warning('用例列表暂不支持导出,请切换成接口列表');
return;
}
this.$refs.apiList[0].exportApi(type);
},
refreshModule() {
this.$refs.nodeTree.list();
},
refresh(data) {
this.$refs.apiList[0].initTable(data);
},
setTabTitle(data) {
for (let index in this.apiTabs) {
let tab = this.apiTabs[index];
if (tab.name === this.apiDefaultTab) {
tab.title = this.$t('api_test.definition.request.edit_api') + "-" + data.name;
break;
}
}
},
runTest(data) {
this.handleTabsEdit(this.$t("commons.api"), "TEST", data);
this.setTabTitle(data);
},
mockConfig(data) {
let targetName = this.$t("commons.mock") + "-" + data.apiName;
this.handleMockTabsConfig(targetName, "MOCK", data);
},
saveApi(data) {
this.setTabTitle(data);
this.refresh(data);
},
showExecResult(row) {
this.debug(row);
},
nodeChange(node, nodeIds, pNodes) {
this.selectNodeIds = nodeIds;
},
handleProtocolChange(protocol) {
this.currentProtocol = protocol;
},
setModuleOptions(data) {
this.moduleOptions = data;
},
setNodeTree(data) {
this.nodeTree = data;
},
changeSelectDataRangeAll(tableType) {
this.$route.params.dataSelectRange = 'all';
},
enableTrash(data) {
this.trashEnable = data;
}
}
};
</script>
<style scoped>
.ms-api-div {
overflow-y: auto;
height: calc(100vh - 155px)
}
.ms-api-div {
overflow-y: auto;
height: calc(100vh - 155px)
}
/deep/ .el-main {
overflow: hidden;
}
/deep/ .el-main {
overflow: hidden;
}
/deep/ .el-tabs__header {
margin: 0 0 0px;
/*width: calc(100% - 90px);*/
}
/deep/ .el-tabs__header {
margin: 0 0 0px;
/*width: calc(100% - 90px);*/
}
/deep/ .el-card {
/*border: 1px solid #EBEEF5;*/
/*border-style: none;*/
border-top: none;
}
/deep/ .el-card {
/*border: 1px solid #EBEEF5;*/
/*border-style: none;*/
border-top: none;
}
/deep/ .api-component {
margin-top: 10px;
}
/deep/ .api-component {
margin-top: 10px;
}
</style>

View File

@ -194,18 +194,7 @@ import MsTableAdvSearchBar from "@/business/components/common/components/search/
import {API_DEFINITION_CONFIGS} from "@/business/components/common/components/search/search-components";
import MsTipButton from "@/business/components/common/components/MsTipButton";
import CaseBatchMove from "@/business/components/api/definition/components/basis/BatchMove";
import {
_filter,
_handleSelect,
_handleSelectAll,
_sort,
buildBatchParam, deepClone,
getLabel,
getSelectDataCounts,
initCondition,
setUnSelectIds,
toggleAllSelection
} from "@/common/js/tableUtils";
import {_filter, _sort, buildBatchParam, getLabel, initCondition} from "@/common/js/tableUtils";
import {Api_List} from "@/business/components/common/model/JsonData";
import HeaderCustom from "@/business/components/common/head/HeaderCustom";
import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate";
@ -251,31 +240,90 @@ export default {
selectDataRange: "all",
deletePath: "/test/case/delete",
buttons: [
{name: this.$t('api_test.definition.request.batch_delete'), handleClick: this.handleDeleteBatch},
{name: this.$t('api_test.definition.request.batch_edit'), handleClick: this.handleEditBatch},
{
name: this.$t('api_test.definition.request.batch_move'), handleClick: this.handleBatchMove
name: this.$t('api_test.definition.request.batch_delete'),
handleClick: this.handleDeleteBatch,
permissions: ['PROJECT_API_DEFINITION:READ+DELETE_API']
},
{
name: this.$t('api_test.definition.request.batch_edit'),
handleClick: this.handleEditBatch,
permissions: ['PROJECT_API_DEFINITION:READ+EDIT_API']
},
{
name: this.$t('api_test.definition.request.batch_move'),
handleClick: this.handleBatchMove,
permissions: ['PROJECT_API_DEFINITION:READ+BATCH_MOVE']
}
],
trashButtons: [
{name: this.$t('api_test.definition.request.batch_delete'), handleClick: this.handleDeleteBatch},
{
name: this.$t('api_test.definition.request.batch_delete'),
handleClick: this.handleDeleteBatch,
permissions: ['PROJECT_API_DEFINITION:READ+DELETE_API']
},
{
name: "批量恢复", handleClick: this.handleBatchRestore
},
],
tableOperatorButtons: [],
tableUsualOperatorButtons: [
{tip: this.$t('api_test.automation.execute'), icon: "el-icon-video-play", exec: this.runApi},
{tip: this.$t('commons.edit'), icon: "el-icon-edit", exec: this.editApi},
{tip: "CASE", exec: this.handleTestCase, isDivButton: true, type: "primary"},
{tip: this.$t('commons.delete'), exec: this.handleDelete, icon: "el-icon-delete", type: "danger"},
{tip: this.$t('commons.copy'), exec: this.handleCopy, icon: "el-icon-document-copy", type: "primary"},
{
tip: this.$t('api_test.automation.execute'),
icon: "el-icon-video-play",
exec: this.runApi,
permissions: ['PROJECT_API_DEFINITION:READ+RUN']
},
{
tip: this.$t('commons.edit'),
icon: "el-icon-edit",
exec: this.editApi,
permissions: ['PROJECT_API_DEFINITION:READ+EDIT_API']
},
{
tip: "CASE",
exec: this.handleTestCase,
isDivButton: true,
type: "primary",
permissions: ['PROJECT_API_DEFINITION:READ+CREATE_CASE']
},
{
tip: this.$t('commons.delete'),
exec: this.handleDelete,
icon: "el-icon-delete",
type: "danger",
permissions: ['PROJECT_API_DEFINITION:READ+DELETE_API']
},
{
tip: this.$t('commons.copy'),
exec: this.handleCopy,
icon: "el-icon-document-copy",
type: "primary",
permissions: ['PROJECT_API_DEFINITION:READ+COPY']
},
],
tableTrashOperatorButtons: [
{tip: this.$t('api_test.automation.execute'), icon: "el-icon-video-play", exec: this.runApi},
{
tip: this.$t('api_test.automation.execute'),
icon: "el-icon-video-play",
exec: this.runApi,
permissions: ['PROJECT_API_DEFINITION:READ+RUN']
},
{tip: this.$t('commons.reduction'), icon: "el-icon-refresh-left", exec: this.reductionApi},
{tip: "CASE", exec: this.handleTestCase, isDivButton: true, type: "primary"},
{tip: this.$t('commons.delete'), exec: this.handleDelete, icon: "el-icon-delete", type: "danger"},
{
tip: "CASE",
exec: this.handleTestCase,
isDivButton: true,
type: "primary",
permissions: ['PROJECT_API_DEFINITION:READ+CREATE_CASE']
},
{
tip: this.$t('commons.delete'),
exec: this.handleDelete,
icon: "el-icon-delete",
type: "danger",
permissions: ['PROJECT_API_DEFINITION:READ+DELETE_API']
},
],
typeArr: [
{id: 'status', name: this.$t('api_test.definition.api_status')},
@ -321,7 +369,7 @@ export default {
screenHeight: document.documentElement.clientHeight - 310,//,
environmentId: undefined,
selectDataCounts: 0,
}
};
},
props: {
currentProtocol: String,
@ -347,13 +395,13 @@ export default {
moduleTree: {
type: Array,
default() {
return []
return [];
},
},
moduleOptions: {
type: Array,
default() {
return []
return [];
},
}
},
@ -453,7 +501,7 @@ export default {
if (item.tags && item.tags.length > 0) {
item.tags = JSON.parse(item.tags);
}
})
});
// nexttick:
this.$nextTick(function () {
@ -461,7 +509,7 @@ export default {
this.$refs.apiDefinitionTable.checkTableRowIsSelect();
this.$refs.apiDefinitionTable.doLayout();
}
})
});
});
}
getLabel(this, API_LIST);
@ -513,7 +561,7 @@ export default {
this.$post('/user/ws/member/tester/list', {workspaceId: workspaceId}, response => {
this.valueArr.userId = response.data;
this.userFilters = response.data.map(u => {
return {text: u.name, value: u.id}
return {text: u.name, value: u.id};
});
});
},
@ -562,8 +610,8 @@ export default {
}
response.body = body;
}
row.request = request
row.response = response
row.request = request;
row.response = response;
this.$emit('runTest', row);
},
reductionApi(row) {
@ -706,7 +754,7 @@ export default {
this.$emit("changeSelectDataRangeAll", "api");
},
getIds(rowSets) {
let rowArray = Array.from(rowSets)
let rowArray = Array.from(rowSets);
let ids = rowArray.map(s => s.id);
return ids;
},
@ -739,7 +787,7 @@ export default {
if (api.moduleId === item.id) {
api.modulePath = item.path;
}
})
});
});
} catch (e) {
console.log(e);
@ -773,7 +821,7 @@ export default {
return row[property] === value;
}
},
}
};
</script>
<style scoped>

View File

@ -27,134 +27,144 @@
@saveAsEdit="saveAsEdit"
@refresh="refresh"
ref="basisApi"/>
<api-import :propotal="condition.protocol" ref="apiImport" :moduleOptions="moduleOptions" @refresh="$emit('refresh')"/>
<api-import :propotal="condition.protocol" ref="apiImport" :moduleOptions="moduleOptions"
@refresh="$emit('refresh')"/>
</div>
</template>
<script>
import {OPTIONS} from "../../model/JsonData";
import MsAddBasisApi from "../basis/AddBasisApi";
import ApiImport from "../import/ApiImport";
import ModuleTrashButton from "./ModuleTrashButton";
import {buildNodePath} from "@/business/components/api/definition/model/NodeTree";
import TemplateComponent from "../../../../track/plan/view/comonents/report/TemplateComponent/TemplateComponent";
import MsSearchBar from "@/business/components/common/components/search/MsSearchBar";
export default {
name: "ApiModuleHeader",
components: {MsSearchBar, TemplateComponent, ModuleTrashButton, ApiImport, MsAddBasisApi},
data() {
return {
options: OPTIONS,
operators: [
{
label: this.$t('api_test.definition.request.title'),
callback: this.addApi
import {OPTIONS} from "../../model/JsonData";
import MsAddBasisApi from "../basis/AddBasisApi";
import ApiImport from "../import/ApiImport";
import ModuleTrashButton from "./ModuleTrashButton";
import TemplateComponent from "../../../../track/plan/view/comonents/report/TemplateComponent/TemplateComponent";
import MsSearchBar from "@/business/components/common/components/search/MsSearchBar";
export default {
name: "ApiModuleHeader",
components: {MsSearchBar, TemplateComponent, ModuleTrashButton, ApiImport, MsAddBasisApi},
data() {
return {
options: OPTIONS,
operators: [
{
label: this.$t('api_test.definition.request.title'),
callback: this.addApi,
permissions: ['PROJECT_API_DEFINITION:READ+CREATE_API']
},
{
label: this.$t('api_test.definition.request.fast_debug'),
callback: () => {
this.$emit('debug');
},
{
label: this.$t('api_test.definition.request.fast_debug'),
callback: () => {this.$emit('debug')}
},
{
label: this.$t('api_test.api_import.label'),
callback: this.handleImport
},
{
label: this.$t('report.export'),
children: [
{
label: this.$t('report.export_to_ms_format') ,
callback: () => {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
this.$emit('exportAPI', 'MS');
}
},
{
label: this.$t('report.export_to_swagger3_format'),
callback: () => {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
this.$emit('exportAPI', 'Swagger');
permissions: ['PROJECT_API_DEFINITION:READ+DEBUG']
},
{
label: this.$t('api_test.api_import.label'),
callback: this.handleImport,
permissions: ['PROJECT_API_DEFINITION:READ+IMPORT_API']
},
{
label: this.$t('report.export'),
permissions: ['PROJECT_API_DEFINITION:READ+EXPORT_API'],
children: [
{
label: this.$t('report.export_to_ms_format'),
callback: () => {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
this.$emit('exportAPI', 'MS');
}
]
}
]
},
{
label: this.$t('report.export_to_swagger3_format'),
callback: () => {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
this.$emit('exportAPI', 'Swagger');
}
}
]
}
]
};
},
props: {
condition: {
type: Object,
default() {
return {};
}
},
props: {
condition: {
type: Object,
default() {
return {}
}
},
showOperator: Boolean,
moduleOptions: Array,
currentModule: {
type: Object,
default() {
return {}
}
},
isReadOnly: {
type: Boolean,
default() {
return false
}
},
},
computed: {
projectId() {
return this.$store.state.projectId
},
},
methods: {
handleImport() {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
this.protocol = "HTTP";
this.$refs.apiImport.open(this.moduleOptions);
},
addApi() {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
this.$refs.basisApi.open(this.currentModule);
},
saveAsEdit(data) {
this.$emit('saveAsEdit', data);
},
refresh() {
this.$emit('refresh');
},
enableTrash() {
this.condition.trashEnable = true;
showOperator: Boolean,
moduleOptions: Array,
currentModule: {
type: Object,
default() {
return {};
}
},
isReadOnly: {
type: Boolean,
default() {
return false;
}
},
},
computed: {
projectId() {
return this.$store.state.projectId;
},
},
methods: {
handleImport() {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
this.protocol = "HTTP";
this.$refs.apiImport.open(this.moduleOptions);
},
addApi() {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
this.$refs.basisApi.open(this.currentModule);
},
saveAsEdit(data) {
this.$emit('saveAsEdit', data);
},
refresh() {
this.$emit('refresh');
},
enableTrash() {
this.condition.trashEnable = true;
}
}
};
</script>
<style scoped>
.protocol-select {
width: 92px;
height: 30px;
}
.protocol-col {
min-width: 93px;
}
.read-only {
width: 150px !important;
}
.filter-input {
width: 174px;
padding-left: 3px;
}
.protocol-select {
width: 92px;
height: 30px;
}
.protocol-col {
min-width: 93px;
}
.read-only {
width: 150px !important;
}
.filter-input {
width: 174px;
padding-left: 3px;
}
</style>

View File

@ -7,7 +7,9 @@
<i class="el-icon-arrow-down el-icon--right"/>
</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item v-for="(item, index) in commands" :key="index" @click.native.stop="click(item)">
<el-dropdown-item v-for="(item, index) in commands" :key="index" @click.native.stop="click(item)"
v-permission="item.permissions"
>
<span class="tip-font" v-if="!item.children">
{{ item.label }}
</span>

View File

@ -96,7 +96,7 @@ export function hasPermission(permission) {
}
let systemPermissions = user.userGroups.filter(gp => gp.group.type === 'SYSTEM')
.filter(ug => ug.sourceId === 'system')[0]?.userGroupPermissions
.filter(ug => ug.sourceId === 'system' || ug.sourceId === 'adminSourceId')[0]?.userGroupPermissions
.map(g => g.permissionId) || [];
for (const p of systemPermissions) {