refactor(权限管理): 性能测试权限

This commit is contained in:
Captain.B 2021-05-21 14:57:39 +08:00 committed by 刘瑞斌
parent e1eaecff17
commit c04eeff4ec
10 changed files with 113 additions and 93 deletions

View File

@ -33,6 +33,7 @@ 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;
@ -47,7 +48,6 @@ import java.util.List;
@RestController
@RequestMapping(value = "/api/definition")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public class ApiDefinitionController {
@Resource
private ScheduleService scheduleService;
@ -63,6 +63,7 @@ public class ApiDefinitionController {
private ApiTestEnvironmentService apiTestEnvironmentService;
@PostMapping("/list/{goPage}/{pageSize}")
@RequiresPermissions("PROJECT_API_DEFINITION:READ")
public Pager<List<ApiDefinitionResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
@ -84,6 +85,7 @@ public class ApiDefinitionController {
}
@PostMapping("/list/all")
@RequiresPermissions("PROJECT_API_DEFINITION:READ")
public List<ApiDefinitionResult> list(@RequestBody ApiDefinitionRequest request) {
return apiDefinitionService.list(request);
}

View File

@ -5,7 +5,6 @@ import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.LoadTestReportLog;
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.dto.LogDetailDTO;
@ -17,8 +16,7 @@ import io.metersphere.performance.controller.request.RenameReportRequest;
import io.metersphere.performance.controller.request.ReportRequest;
import io.metersphere.performance.dto.LoadTestExportJmx;
import io.metersphere.performance.service.PerformanceReportService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -33,7 +31,7 @@ public class PerformanceReportController {
private PerformanceReportService performanceReportService;
@PostMapping("/recent/{count}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_PERFORMANCE_REPORT:READ")
public List<ReportDTO> recentProjects(@PathVariable int count, @RequestBody ReportRequest request) {
// 最近 `count` 个项目
PageHelper.startPage(1, count);
@ -47,7 +45,7 @@ public class PerformanceReportController {
}
@PostMapping("/delete/{reportId}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_PERFORMANCE_REPORT:READ+DELETE")
@MsAuditLog(module = "performance_test_report", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#reportId)", msClass = PerformanceReportService.class)
public void deleteReport(@PathVariable String reportId) {
performanceReportService.deleteReport(reportId);
@ -131,7 +129,7 @@ public class PerformanceReportController {
}
@PostMapping("/batch/delete")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@RequiresPermissions("PROJECT_PERFORMANCE_REPORT:READ+DELETE")
@MsAuditLog(module = "performance_test_report", type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#reportRequest.ids)", msClass = PerformanceReportService.class)
public void deleteReportBatch(@RequestBody DeleteReportRequest reportRequest) {
performanceReportService.deleteReportBatch(reportRequest);

View File

@ -23,6 +23,7 @@ import io.metersphere.service.CheckPermissionService;
import io.metersphere.service.FileService;
import io.metersphere.track.request.testplan.FileOperationRequest;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@ -36,7 +37,6 @@ import java.util.UUID;
@RestController
@RequestMapping(value = "performance")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public class PerformanceTestController {
@Resource
private PerformanceTestService performanceTestService;
@ -52,12 +52,14 @@ public class PerformanceTestController {
}
@PostMapping("/list/{goPage}/{pageSize}")
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ")
public Pager<List<LoadTestDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, performanceTestService.list(request));
}
@GetMapping("/list/{projectId}")
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ")
public List<LoadTest> list(@PathVariable String projectId) {
checkPermissionService.checkProjectOwner(projectId);
return performanceTestService.getLoadTestByProjectId(projectId);
@ -65,6 +67,7 @@ public class PerformanceTestController {
@GetMapping("/state/get/{testId}")
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ")
public LoadTest listByTestId(@PathVariable String testId) {
checkPermissionService.checkPerformanceTestOwner(testId);
return performanceTestService.getLoadTestBytestId(testId);
@ -72,6 +75,7 @@ public class PerformanceTestController {
@PostMapping(value = "/save", consumes = {"multipart/form-data"})
@MsAuditLog(module = "performance_test", type = OperLogConstants.CREATE, title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ+CREATE")
public String save(
@RequestPart("request") SaveTestPlanRequest request,
@RequestPart(value = "file") List<MultipartFile> files
@ -83,6 +87,7 @@ public class PerformanceTestController {
@PostMapping(value = "/edit", consumes = {"multipart/form-data"})
@MsAuditLog(module = "performance_test", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ+EDIT")
public String edit(
@RequestPart("request") EditTestPlanRequest request,
@RequestPart(value = "file", required = false) List<MultipartFile> files
@ -131,6 +136,7 @@ public class PerformanceTestController {
@PostMapping("/delete")
@MsAuditLog(module = "performance_test", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ+DELETE")
public void delete(@RequestBody DeleteTestPlanRequest request) {
checkPermissionService.checkPerformanceTestOwner(request.getId());
performanceTestService.delete(request);
@ -138,6 +144,7 @@ public class PerformanceTestController {
@PostMapping("/run")
@MsAuditLog(module = "performance_test", type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ+RUN")
public String run(@RequestBody RunTestPlanRequest request) {
return performanceTestService.run(request);
}
@ -179,21 +186,25 @@ public class PerformanceTestController {
@PostMapping(value = "/copy")
@MsAuditLog(module = "performance_test", type = OperLogConstants.COPY, content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ+COPY")
public void copy(@RequestBody SaveTestPlanRequest request) {
performanceTestService.copy(request);
}
@PostMapping(value = "/schedule/create")
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ+SCHEDULE")
public void createSchedule(@RequestBody ScheduleRequest request) {
performanceTestService.createSchedule(request);
}
@PostMapping(value = "/schedule/update")
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ+SCHEDULE")
public void updateSchedule(@RequestBody Schedule request) {
performanceTestService.updateSchedule(request);
}
@PostMapping("/list/schedule/{goPage}/{pageSize}")
@RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ")
public List<ScheduleDao> listSchedule(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryScheduleRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return performanceTestService.listSchedule(request);

View File

@ -12,15 +12,16 @@
{{ $t("i18n.home") }}
</el-menu-item>
<el-menu-item v-show="isNewVersion" :index="'/api/definition'">
<el-menu-item v-show="isNewVersion" :index="'/api/definition'" v-permission="['PROJECT_API_DEFINITION:READ']">
{{ $t("i18n.definition") }}
</el-menu-item>
<el-menu-item v-show="isNewVersion" :index="'/api/automation'">
<el-menu-item v-show="isNewVersion" :index="'/api/automation'" v-permission="['PROJECT_API_SCENARIO:READ']">
{{ $t("i18n.automation") }}
</el-menu-item>
<el-menu-item v-show="isNewVersion" :index="'/api/automation/report'">
<el-menu-item v-show="isNewVersion" :index="'/api/automation/report'"
v-permission="['PROJECT_API_REPORT:READ']">
{{ $t("i18n.report") }}
</el-menu-item>
@ -78,7 +79,7 @@ export default {
return '/api/test/edit/' + item.id;
},
router: function (item) {
return {path: '/api/test/edit', query: {id: item.id}}
return {path: '/api/test/edit', query: {id: item.id}};
}
},
reportRecent: {
@ -93,7 +94,7 @@ export default {
isRouterAlive: true,
apiTestProjectPath: '',
currentProject: ''
}
};
},
computed: {
...mapGetters([
@ -121,7 +122,7 @@ export default {
beforeDestroy() {
ApiEvent.$off(LIST_CHANGE);
}
}
};
</script>

View File

@ -1,6 +1,7 @@
<template>
<span>
<ms-table-operator-button v-for="(btn, index) in buttons" :key="index" :isTesterPermission="isTesterPermission(btn)"
<ms-table-operator-button v-for="(btn, index) in buttons" :key="index"
v-permission="btn.meta.permissions"
:disabled="isDisable(btn)"
:tip="btn.tip" :icon="btn.icon" :type="btn.type" :isDivButton="btn.isDivButton"
@exec="click(btn)" @click.stop="clickStop(btn)"/>
@ -8,9 +9,9 @@
</template>
<script>
import MsTableOperatorButton from "./MsTableOperatorButton";
import MsTableOperatorButton from "./MsTableOperatorButton";
export default {
export default {
name: "MsTableOperators",
components: {MsTableOperatorButton},
props: {
@ -40,10 +41,10 @@
isTesterPermission() {
return function (btn) {
return btn.isTesterPermission !== false;
}
};
},
}
}
};
</script>
<style scoped>

View File

@ -8,17 +8,18 @@
{{ $t("i18n.home") }}
</el-menu-item>
<el-submenu v-roles="['test_manager','test_user','test_viewer']"
<el-submenu v-permission="['PROJECT_PERFORMANCE_TEST:READ']"
index="4" popper-class="submenu">
<template v-slot:title>{{ $t('commons.test') }}</template>
<ms-recent-list ref="testRecent" :options="testRecent"/>
<el-divider/>
<ms-show-all :index="'/performance/test/all'"/>
<ms-create-button v-roles="['test_manager','test_user']" :index="'/performance/test/create'"
<ms-create-button v-permission="['PROJECT_PERFORMANCE_TEST:READ+CREATE']"
:index="'/performance/test/create'"
:title="$t('load_test.create')"/>
</el-submenu>
<el-submenu v-roles="['test_manager','test_user','test_viewer']"
<el-submenu v-permission="['PROJECT_PERFORMANCE_REPORT:READ']"
index="5" popper-class="submenu">
<template v-slot:title>{{ $t('commons.report') }}</template>
<ms-recent-list ref="reportRecent" :options="reportRecent"/>
@ -28,7 +29,7 @@
</el-menu>
</el-col>
<el-col :span="4">
<el-row type="flex" justify="center">
<el-row type="flex" justify="center" v-permission="['PROJECT_PERFORMANCE_TEST:READ+CREATE']">
<ms-create-test :to="'/performance/test/create'"/>
</el-row>
</el-col>

View File

@ -14,7 +14,7 @@
<ms-test-heatmap :values="values"/>
</el-col>
<el-col :span="12">
<ms-schedule-list :group="'PERFORMANCE_TEST'"/>
<ms-schedule-list :group="'PERFORMANCE_TEST'" v-permission="['PROJECT_PERFORMANCE_TEST:READ+SCHEDULE']"/>
</el-col>
</el-row>
</ms-main-container>
@ -23,14 +23,14 @@
</template>
<script>
import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer";
import MsPerformanceTestRecentList from "./PerformanceTestRecentList"
import MsPerformanceReportRecentList from "./PerformanceReportRecentList"
import MsTestHeatmap from "../../common/components/MsTestHeatmap";
import MsScheduleList from "../../api/home/ScheduleList";
import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer";
import MsPerformanceTestRecentList from "./PerformanceTestRecentList";
import MsPerformanceReportRecentList from "./PerformanceReportRecentList";
import MsTestHeatmap from "../../common/components/MsTestHeatmap";
import MsScheduleList from "../../api/home/ScheduleList";
export default {
export default {
name: "PerformanceTestHome",
components: {
MsScheduleList,
@ -44,7 +44,7 @@
return {
values: [],
result: {},
}
};
},
mounted() {
this.getValues();
@ -59,11 +59,11 @@
});
}
}
}
};
</script>
<style scoped>
.el-row {
.el-row {
padding-bottom: 20px;
}
}
</style>

View File

@ -108,7 +108,8 @@
@exec="handleView(scope.row)" type="primary"/>
<ms-table-operator-button :tip="$t('load_test.report.diff')" icon="el-icon-s-operation"
@exec="handleDiff(scope.row)" type="warning"/>
<ms-table-operator-button :is-tester-permission="true" :tip="$t('api_report.delete')"
<ms-table-operator-button :tip="$t('api_report.delete')"
v-permission="['PROJECT_PERFORMANCE_REPORT:READ+DELETE']"
icon="el-icon-delete" @exec="handleDelete(scope.row)" type="danger"/>
</template>
</el-table-column>

View File

@ -21,6 +21,7 @@
</el-button>
<ms-schedule-config :schedule="test.schedule" :save="saveCronExpression" @scheduleChange="saveSchedule"
v-permission="['PROJECT_PERFORMANCE_TEST:READ+SCHEDULE']"
:check-open="checkScheduleEdit" :test-id="testId" :custom-validate="durationValidate"/>
</el-col>
</el-row>

View File

@ -3,8 +3,9 @@
<ms-main-container>
<el-card class="table-card" v-loading="result.loading">
<template v-slot:header>
<ms-table-header :is-tester-permission="true" :condition.sync="condition" @search="search"
<ms-table-header :condition.sync="condition" @search="search"
:title="$t('commons.test')"
v-permission="['PROJECT_PERFORMANCE_TEST:READ+CREATE']"
@create="create" :createTip="$t('load_test.create')"/>
</template>
@ -129,13 +130,16 @@ export default {
buttons: [
{
tip: this.$t('commons.edit'), icon: "el-icon-edit",
exec: this.handleEdit
exec: this.handleEdit,
meta: {permissions: ['PROJECT_PERFORMANCE_TEST:READ+EDIT']}
}, {
tip: this.$t('commons.copy'), icon: "el-icon-copy-document", type: "success",
exec: this.handleCopy
exec: this.handleCopy,
meta: {permissions: ['PROJECT_PERFORMANCE_TEST:READ+COPY']}
}, {
tip: this.$t('commons.delete'), icon: "el-icon-delete", type: "danger",
exec: this.handleDelete
exec: this.handleDelete,
meta: {permissions: ['PROJECT_PERFORMANCE_TEST:READ+DELETE']}
}
],
statusFilters: [