roles indexOf bug fix

This commit is contained in:
Captain.B 2020-02-24 18:55:44 +08:00
parent eeadaa2c78
commit 2afa1bca4c
5 changed files with 48 additions and 11 deletions

View File

@ -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<List<Workspace>> getWorkspaceList(@PathVariable int goPage, @PathVariable int pageSize) {
public Pager<List<Workspace>> getWorkspaceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody WorkspaceRequest request) {
request.setOrganizationId(SessionUtils.getCurrentOrganizationId());
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList());
return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList(request));
}
@GetMapping("/list/userworkspace/{userId}")

View File

@ -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;
}
}

View File

@ -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<Workspace> getWorkspaceList() {
return workspaceMapper.selectByExample(null);
public List<Workspace> 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) {

View File

@ -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();
})
}
}

View File

@ -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;