From c04eeff4ecde05217c0a8826383c3d047901b170 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Fri, 21 May 2021 14:57:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApiDefinitionController.java | 4 +- .../PerformanceReportController.java | 10 +-- .../controller/PerformanceTestController.java | 13 +++- .../components/api/head/ApiHeaderMenus.vue | 13 ++-- .../common/components/MsTableOperators.vue | 65 ++++++++-------- .../head/PerformanceHeaderMenus.vue | 9 ++- .../performance/home/PerformanceTestHome.vue | 76 +++++++++---------- .../report/PerformanceTestReportList.vue | 3 +- .../performance/test/EditPerformanceTest.vue | 1 + .../performance/test/PerformanceTestList.vue | 12 ++- 10 files changed, 113 insertions(+), 93 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java index f2e8c4749f..ff3e65dc1c 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java @@ -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(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) { Page 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 list(@RequestBody ApiDefinitionRequest request) { return apiDefinitionService.list(request); } diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java index 581c93953a..008a5b1a1b 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java @@ -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 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); diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java index 8a6c5da44a..ffbf20b98d 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java @@ -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(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); return PageUtils.setPageInfo(page, performanceTestService.list(request)); } @GetMapping("/list/{projectId}") + @RequiresPermissions("PROJECT_PERFORMANCE_TEST:READ") public List 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 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 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 listSchedule(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryScheduleRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); return performanceTestService.listSchedule(request); diff --git a/frontend/src/business/components/api/head/ApiHeaderMenus.vue b/frontend/src/business/components/api/head/ApiHeaderMenus.vue index 45bd639abb..56d80281aa 100644 --- a/frontend/src/business/components/api/head/ApiHeaderMenus.vue +++ b/frontend/src/business/components/api/head/ApiHeaderMenus.vue @@ -12,15 +12,16 @@ {{ $t("i18n.home") }} - + {{ $t("i18n.definition") }} - + {{ $t("i18n.automation") }} - + {{ $t("i18n.report") }} @@ -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); } -} +}; diff --git a/frontend/src/business/components/common/components/MsTableOperators.vue b/frontend/src/business/components/common/components/MsTableOperators.vue index 212a092bfd..39475cd16d 100644 --- a/frontend/src/business/components/common/components/MsTableOperators.vue +++ b/frontend/src/business/components/common/components/MsTableOperators.vue @@ -1,6 +1,7 @@ diff --git a/frontend/src/business/components/performance/report/PerformanceTestReportList.vue b/frontend/src/business/components/performance/report/PerformanceTestReportList.vue index 2028ecf08c..7819be72c5 100644 --- a/frontend/src/business/components/performance/report/PerformanceTestReportList.vue +++ b/frontend/src/business/components/performance/report/PerformanceTestReportList.vue @@ -108,7 +108,8 @@ @exec="handleView(scope.row)" type="primary"/> - diff --git a/frontend/src/business/components/performance/test/EditPerformanceTest.vue b/frontend/src/business/components/performance/test/EditPerformanceTest.vue index e682086de6..cd03f5a234 100644 --- a/frontend/src/business/components/performance/test/EditPerformanceTest.vue +++ b/frontend/src/business/components/performance/test/EditPerformanceTest.vue @@ -21,6 +21,7 @@ diff --git a/frontend/src/business/components/performance/test/PerformanceTestList.vue b/frontend/src/business/components/performance/test/PerformanceTestList.vue index 693ca5d30d..dec8510b6c 100644 --- a/frontend/src/business/components/performance/test/PerformanceTestList.vue +++ b/frontend/src/business/components/performance/test/PerformanceTestList.vue @@ -3,8 +3,9 @@ @@ -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: [