From 2afa1bca4cd25bbc1a6922c0573603c203bf3f24 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Mon, 24 Feb 2020 18:55:44 +0800 Subject: [PATCH] roles indexOf bug fix --- .../controller/WorkspaceController.java | 7 ++++-- .../controller/request/WorkspaceRequest.java | 25 +++++++++++++++++++ .../metersphere/service/WorkspaceService.java | 13 ++++++++-- .../src/performance/components/HeaderUser.vue | 12 ++++----- .../components/settings/Workspace.vue | 2 +- 5 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/controller/request/WorkspaceRequest.java diff --git a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java index dc3291c9ff..b0e9cf760a 100644 --- a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java +++ b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java @@ -6,7 +6,9 @@ import io.metersphere.base.domain.Workspace; import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; +import io.metersphere.controller.request.WorkspaceRequest; import io.metersphere.service.WorkspaceService; +import io.metersphere.user.SessionUtils; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; @@ -41,9 +43,10 @@ public class WorkspaceController { @PostMapping("list/{goPage}/{pageSize}") @RequiresRoles(RoleConstants.ORG_ADMIN) - public Pager> getWorkspaceList(@PathVariable int goPage, @PathVariable int pageSize) { + public Pager> getWorkspaceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody WorkspaceRequest request) { + request.setOrganizationId(SessionUtils.getCurrentOrganizationId()); Page page = PageHelper.startPage(goPage, pageSize, true); - return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList()); + return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList(request)); } @GetMapping("/list/userworkspace/{userId}") diff --git a/backend/src/main/java/io/metersphere/controller/request/WorkspaceRequest.java b/backend/src/main/java/io/metersphere/controller/request/WorkspaceRequest.java new file mode 100644 index 0000000000..1e12ac3970 --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/request/WorkspaceRequest.java @@ -0,0 +1,25 @@ +package io.metersphere.controller.request; + +import io.metersphere.commons.annotations.FuzzyQuery; + +public class WorkspaceRequest { + private String organizationId; + @FuzzyQuery + private String name; + + public String getOrganizationId() { + return organizationId; + } + + public void setOrganizationId(String organizationId) { + this.organizationId = organizationId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index d47f365b1c..4852bab564 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -7,6 +7,7 @@ import io.metersphere.base.mapper.WorkspaceMapper; import io.metersphere.base.mapper.ext.ExtUserRoleMapper; import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.exception.MSException; +import io.metersphere.controller.request.WorkspaceRequest; import io.metersphere.dto.UserRoleHelpDTO; import io.metersphere.user.SessionUser; import io.metersphere.user.SessionUtils; @@ -55,8 +56,16 @@ public class WorkspaceService { return workspace; } - public List getWorkspaceList() { - return workspaceMapper.selectByExample(null); + public List getWorkspaceList(WorkspaceRequest request) { + WorkspaceExample example = new WorkspaceExample(); + WorkspaceExample.Criteria criteria = example.createCriteria(); + if (StringUtils.isNotBlank(request.getOrganizationId())) { + criteria.andOrganizationIdEqualTo(request.getOrganizationId()); + } + if (StringUtils.isNotBlank(request.getName())) { + criteria.andNameLike(request.getName()); + } + return workspaceMapper.selectByExample(example); } public void deleteWorkspace(String workspaceId) { diff --git a/frontend/src/performance/components/HeaderUser.vue b/frontend/src/performance/components/HeaderUser.vue index 0772afc3c5..ee0216ad12 100644 --- a/frontend/src/performance/components/HeaderUser.vue +++ b/frontend/src/performance/components/HeaderUser.vue @@ -99,12 +99,12 @@ }, initMenuData() { let roles = this.currentUser.roles.map(r => r.id); - if (roles.indexOf(ROLE_ORG_ADMIN) > 0) { + if (roles.indexOf(ROLE_ORG_ADMIN) > -1) { this.$get("/organization/list/userorg/" + this.currentUserId, response => { this.organizationList = response.data; }); } - if (roles.indexOf(ROLE_TEST_MANAGER) > 0 || roles.indexOf(ROLE_TEST_USER) > 0 || roles.indexOf(ROLE_TEST_VIEWER) > 0) { + if (roles.indexOf(ROLE_TEST_MANAGER) > -1 || roles.indexOf(ROLE_TEST_USER) > -1 || roles.indexOf(ROLE_TEST_VIEWER) > -1) { this.$get("/workspace/list/userworkspace/" + this.currentUserId, response => { this.workspaceList = response.data; this.workspaceIds = response.data.map(r => r.id); @@ -124,10 +124,10 @@ let user = {}; user.id = this.currentUserInfo.id; user.lastSourceId = data.id; - this.$post("/user/switch/source/" + user.lastSourceId, {},response => { - Cookies.set(TokenKey, response.data); - window.location.reload(); - }) + this.$post("/user/switch/source/" + user.lastSourceId, {}, response => { + Cookies.set(TokenKey, response.data); + window.location.reload(); + }) } } diff --git a/frontend/src/performance/components/settings/Workspace.vue b/frontend/src/performance/components/settings/Workspace.vue index f8d80481c4..f211aae422 100644 --- a/frontend/src/performance/components/settings/Workspace.vue +++ b/frontend/src/performance/components/settings/Workspace.vue @@ -118,7 +118,7 @@ }, list() { let url = '/workspace/list/' + this.currentPage + '/' + this.pageSize; - this.result = this.$post(url, {}, response => { + this.result = this.$post(url, {name: this.condition}, response => { let data = response.data; this.items = data.listObject; this.total = data.itemCount;