Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
haifeng414 2020-02-20 12:10:47 +08:00
commit 5f6368d1b5
9 changed files with 164 additions and 12 deletions

View File

@ -24,7 +24,7 @@ public class OrganizationController {
public List<Organization> getOrganizationList() { return organizationService.getOrganizationList(); } public List<Organization> getOrganizationList() { return organizationService.getOrganizationList(); }
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<Organization>> getUserList(@PathVariable int goPage, @PathVariable int pageSize) { public Pager<List<Organization>> getOrganizationList(@PathVariable int goPage, @PathVariable int pageSize) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, organizationService.getOrganizationList()); return PageUtils.setPageInfo(page, organizationService.getOrganizationList());
} }
@ -34,4 +34,9 @@ public class OrganizationController {
@PostMapping("/update") @PostMapping("/update")
public void updateOrganization(@RequestBody Organization organization) { organizationService.updateOrganization(organization); } public void updateOrganization(@RequestBody Organization organization) { organizationService.updateOrganization(organization); }
@GetMapping("/list/userorg/{userId}")
public List<Organization> getOrganizationListByUserId(@PathVariable String userId) {
return organizationService.getOrganizationListByUserId(userId);
}
} }

View File

@ -6,7 +6,9 @@ import io.metersphere.base.domain.Project;
import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.ProjectRequest;
import io.metersphere.service.ProjectService; import io.metersphere.service.ProjectService;
import io.metersphere.user.SessionUtils;
import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -33,9 +35,10 @@ public class ProjectController {
@PostMapping("/list/{goPage}/{pageSize}") @PostMapping("/list/{goPage}/{pageSize}")
@RequiresRoles(RoleConstants.TEST_MANAGER) @RequiresRoles(RoleConstants.TEST_MANAGER)
public Pager<List<Project>> getProjectList(@PathVariable int goPage, @PathVariable int pageSize) { public Pager<List<Project>> getProjectList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ProjectRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, projectService.getProjectList()); return PageUtils.setPageInfo(page, projectService.getProjectList(request));
} }
@GetMapping("/delete/{projectId}") @GetMapping("/delete/{projectId}")

View File

@ -45,4 +45,9 @@ public class WorkspaceController {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList()); return PageUtils.setPageInfo(page, workspaceService.getWorkspaceList());
} }
@GetMapping("/list/userworkspace/{userId}")
public List<Workspace> getWorkspaceListByUserId(@PathVariable String userId) {
return workspaceService.getWorkspaceListByUserId(userId);
}
} }

View File

@ -0,0 +1,13 @@
package io.metersphere.controller.request;
public class ProjectRequest {
private String workspaceId;
public String getWorkspaceId() {
return workspaceId;
}
public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId;
}
}

View File

@ -1,11 +1,17 @@
package io.metersphere.service; package io.metersphere.service;
import io.metersphere.base.domain.Organization; import io.metersphere.base.domain.Organization;
import io.metersphere.base.domain.OrganizationExample;
import io.metersphere.base.mapper.OrganizationMapper; import io.metersphere.base.mapper.OrganizationMapper;
import io.metersphere.base.mapper.UserRoleMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.dto.UserRoleHelpDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -15,6 +21,10 @@ public class OrganizationService {
@Resource @Resource
private OrganizationMapper organizationMapper; private OrganizationMapper organizationMapper;
@Resource
private UserRoleMapper userRoleMapper;
@Resource
private ExtUserRoleMapper extUserRoleMapper;
public Organization addOrganization(Organization organization) { public Organization addOrganization(Organization organization) {
long currentTimeMillis = System.currentTimeMillis(); long currentTimeMillis = System.currentTimeMillis();
@ -37,4 +47,19 @@ public class OrganizationService {
organization.setUpdateTime(System.currentTimeMillis()); organization.setUpdateTime(System.currentTimeMillis());
organizationMapper.updateByPrimaryKeySelective(organization); organizationMapper.updateByPrimaryKeySelective(organization);
} }
public List<Organization> getOrganizationListByUserId(String userId) {
List<UserRoleHelpDTO> userRoleHelpList = extUserRoleMapper.getUserRoleHelpList(userId);
List<String> list = new ArrayList<>();
userRoleHelpList.forEach(r -> {
if (StringUtils.isEmpty(r.getParentId())) {
list.add(r.getSourceId());
} else {
list.add(r.getParentId());
}
});
OrganizationExample organizationExample = new OrganizationExample();
organizationExample.createCriteria().andIdIn(list);
return organizationMapper.selectByExample(organizationExample);
}
} }

View File

@ -4,6 +4,7 @@ import io.metersphere.base.domain.Project;
import io.metersphere.base.domain.ProjectExample; import io.metersphere.base.domain.ProjectExample;
import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.ProjectRequest;
import io.metersphere.user.SessionUtils; import io.metersphere.user.SessionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -40,9 +41,13 @@ public class ProjectService {
return project; return project;
} }
public List<Project> getProjectList() { public List<Project> getProjectList(ProjectRequest request) {
// todo 查询条件设置 ProjectExample example = new ProjectExample();
return projectMapper.selectByExample(null); ProjectExample.Criteria criteria = example.createCriteria();
if (StringUtils.isNotBlank(request.getWorkspaceId())) {
criteria.andWorkspaceIdEqualTo(request.getWorkspaceId());
}
return projectMapper.selectByExample(example);
} }
public void deleteProject(String projectId) { public void deleteProject(String projectId) {

View File

@ -13,6 +13,8 @@ import io.metersphere.controller.request.member.QueryMemberRequest;
import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleDTO; import io.metersphere.dto.UserRoleDTO;
import io.metersphere.dto.UserRoleHelpDTO; import io.metersphere.dto.UserRoleHelpDTO;
import io.metersphere.user.SessionUser;
import io.metersphere.user.SessionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -219,8 +221,10 @@ public class UserService {
public void switchUserRole(UserDTO user, String sourceId) { public void switchUserRole(UserDTO user, String sourceId) {
User newUser = new User(); User newUser = new User();
user.setLastSourceId(sourceId);
BeanUtils.copyProperties(user, newUser); BeanUtils.copyProperties(user, newUser);
newUser.setLastSourceId(sourceId); // 切换工作空间或组织之后更新 session 里的 user
SessionUtils.putUser(SessionUser.fromUser(user));
userMapper.updateByPrimaryKeySelective(newUser); userMapper.updateByPrimaryKeySelective(newUser);
} }

View File

@ -4,8 +4,10 @@ import io.metersphere.base.domain.UserRole;
import io.metersphere.base.domain.Workspace; import io.metersphere.base.domain.Workspace;
import io.metersphere.base.domain.WorkspaceExample; import io.metersphere.base.domain.WorkspaceExample;
import io.metersphere.base.mapper.WorkspaceMapper; import io.metersphere.base.mapper.WorkspaceMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.dto.UserRoleHelpDTO;
import io.metersphere.user.SessionUser; import io.metersphere.user.SessionUser;
import io.metersphere.user.SessionUtils; import io.metersphere.user.SessionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -13,6 +15,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -22,6 +25,8 @@ import java.util.stream.Collectors;
public class WorkspaceService { public class WorkspaceService {
@Resource @Resource
private WorkspaceMapper workspaceMapper; private WorkspaceMapper workspaceMapper;
@Resource
private ExtUserRoleMapper extUserRoleMapper;
public Workspace saveWorkspace(Workspace workspace) { public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) { if (StringUtils.isBlank(workspace.getName())) {
@ -73,4 +78,17 @@ public class WorkspaceService {
} }
} }
public List<Workspace> getWorkspaceListByUserId(String userId) {
List<UserRoleHelpDTO> userRoleHelpList = extUserRoleMapper.getUserRoleHelpList(userId);
List<String> workspaceIds = new ArrayList<>();
userRoleHelpList.forEach(r -> {
if (!StringUtils.isEmpty(r.getParentId())) {
workspaceIds.add(r.getSourceId());
}
});
WorkspaceExample workspaceExample = new WorkspaceExample();
workspaceExample.createCriteria().andIdIn(workspaceIds);
return workspaceMapper.selectByExample(workspaceExample);
}
} }

View File

@ -2,11 +2,23 @@
<el-menu class="header-menu" :unique-opened="true" mode="horizontal" router <el-menu class="header-menu" :unique-opened="true" mode="horizontal" router
menu-trigger="click"> menu-trigger="click">
<el-menu-item index="1"><a href="/" style="text-decoration: none;">{{ $t("i18n.home") }}</a></el-menu-item> <el-menu-item index="1"><a href="/" style="text-decoration: none;">{{ $t("i18n.home") }}</a></el-menu-item>
<el-submenu index="2" popper-class="submenu" v-permission="['org_admin']"> <el-submenu index="7" popper-class="submenu">
<template slot="title">组织</template>
<label v-for="(item,index) in organizationList" :key="index">
<el-menu-item @click="clickMenu(item)">{{item.name}}
<i class="el-icon-check"
v-if="item.id === currentUserInfo.lastSourceId || item.id === workspaceParentId"></i>
</el-menu-item>
</label>
</el-submenu>
<el-submenu index="2" popper-class="submenu">
<template slot="title">工作空间</template> <template slot="title">工作空间</template>
<el-menu-item index="2-1">工作空间1</el-menu-item> <label v-for="(item,index) in workspaceList" :key="index">
<el-menu-item index="2-2">工作空间2</el-menu-item> <el-menu-item @click="clickMenu(item)">
<el-menu-item index="2-3">显示全部</el-menu-item> {{item.name}}
<i class="el-icon-check" v-if="item.id === currentUserInfo.lastSourceId"></i>
</el-menu-item>
</label>
</el-submenu> </el-submenu>
<el-submenu index="3" popper-class="submenu" v-permission="['test_manager']"> <el-submenu index="3" popper-class="submenu" v-permission="['test_manager']">
<template slot="title">项目</template> <template slot="title">项目</template>
@ -44,10 +56,68 @@
<script> <script>
import RecentTestPlan from "./testPlan/RecentTestPlan"; import RecentTestPlan from "./testPlan/RecentTestPlan";
import Cookies from "js-cookie";
import {TokenKey} from "../../common/constants";
export default { export default {
name: "MsMenus", name: "MsMenus",
components: {RecentTestPlan} components: {RecentTestPlan},
created() {
this.initMenuData();
this.getCurrentUserInfo();
},
computed: {
workspaceParentId() {
let result = '';
if (this.workspaceIds.includes(this.currentUserInfo.lastSourceId)) {
let obj = this.workspaceList.filter(r => r.id === this.currentUserInfo.lastSourceId);
if (obj.length > 0) {
result = obj[0].organizationId;
}
}
return result;
}
},
data() {
return {
organizationList: [
{index: '7-1', name: '组织1'},
],
workspaceList: [
{index: '2-1', name: '无工作空间'},
],
currentUserInfo: {},
currentUserId: JSON.parse(Cookies.get(TokenKey)).id,
workspaceIds: []
}
},
methods: {
initMenuData() {
this.$get("/organization/list/userorg/" + this.currentUserId, response => {
this.organizationList = response.data;
})
this.$get("/workspace/list/userworkspace/" + this.currentUserId, response => {
this.workspaceList = response.data;
this.workspaceIds = response.data.map(r => r.id);
})
},
getCurrentUserInfo() {
this.$get("/user/info/" + this.currentUserId, response => {
this.currentUserInfo = response.data;
})
},
clickMenu(data) {
if (data.id === this.currentUserInfo.lastSourceId) {
return false;
}
window.console.log(data.id);
let user = {};
user.id = this.currentUserInfo.id;
user.lastSourceId = data.id;
this.$post("/user/switch/source/" + user.lastSourceId, {});
window.location.reload();
}
}
} }
</script> </script>
@ -73,4 +143,8 @@
.el-divider--horizontal { .el-divider--horizontal {
margin: 0; margin: 0;
} }
.el-icon-check {
color: #44b349;
}
</style> </style>