组织和工作空间切换0.1

This commit is contained in:
shiziyuan9527 2020-02-25 14:53:22 +08:00
parent fe12305ec2
commit 9e9951adcb
9 changed files with 72 additions and 49 deletions

View File

@ -2,11 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtUserRoleMapper"> <mapper namespace="io.metersphere.base.mapper.ext.ExtUserRoleMapper">
<resultMap id="BaseResultMap" type="io.metersphere.dto.LoadTestDTO"
extends="io.metersphere.base.mapper.LoadTestMapper.BaseResultMap">
<result column="project_name" property="projectName"/>
</resultMap>
<select id="getUserRoleHelpList" parameterType="java.lang.String" <select id="getUserRoleHelpList" parameterType="java.lang.String"
resultType="io.metersphere.dto.UserRoleHelpDTO"> resultType="io.metersphere.dto.UserRoleHelpDTO">
SELECT SELECT

View File

@ -61,10 +61,10 @@ public class UserController {
return userService.getUserRoleList(userId); return userService.getUserRoleList(userId);
} }
@PostMapping("/switch/source/{sourceId}") @PostMapping("/switch/source/{sign}/{sourceId}")
public UserDTO switchUserRole(@PathVariable(value = "sourceId") String sourceId) { public UserDTO switchUserRole(@PathVariable String sign, @PathVariable(value = "sourceId") String sourceId) {
UserDTO user = SessionUtils.getUser(); UserDTO user = SessionUtils.getUser();
userService.switchUserRole(user, sourceId); userService.switchUserRole(user, sign, sourceId);
return SessionUtils.getUser(); return SessionUtils.getUser();
} }

View File

@ -53,4 +53,10 @@ public class WorkspaceController {
public List<Workspace> getWorkspaceListByUserId(@PathVariable String userId) { public List<Workspace> getWorkspaceListByUserId(@PathVariable String userId) {
return workspaceService.getWorkspaceListByUserId(userId); return workspaceService.getWorkspaceListByUserId(userId);
} }
@GetMapping("/list/orgworkspace/")
public List<Workspace> getWorkspaceListByOrgId() {
String currentOrganizationId = SessionUtils.getCurrentOrganizationId();
return workspaceService.getWorkspaceListByOrgId(currentOrganizationId);
}
} }

View File

@ -21,9 +21,9 @@ public class UserDTO {
private Long updateTime; private Long updateTime;
private String workspaceId; private String lastWorkspaceId;
private String organizationId; private String lastOrganizationId;
private List<Role> roles = new ArrayList<>(); private List<Role> roles = new ArrayList<>();
@ -103,19 +103,19 @@ public class UserDTO {
this.userRoles = userRoles; this.userRoles = userRoles;
} }
public String getWorkspaceId() { public String getLastWorkspaceId() {
return workspaceId; return lastWorkspaceId;
} }
public void setWorkspaceId(String workspaceId) { public void setLastWorkspaceId(String lastWorkspaceId) {
this.workspaceId = workspaceId; this.lastWorkspaceId = lastWorkspaceId;
} }
public String getOrganizationId() { public String getLastOrganizationId() {
return organizationId; return lastOrganizationId;
} }
public void setOrganizationId(String organizationId) { public void setLastOrganizationId(String lastOrganizationId) {
this.organizationId = organizationId; this.lastOrganizationId = lastOrganizationId;
} }
} }

View File

@ -1,10 +1,7 @@
package io.metersphere.service; package io.metersphere.service;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.OrganizationMapper; import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.RoleMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.UserRoleMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper; 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;
@ -22,7 +19,6 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -41,6 +37,8 @@ public class UserService {
private ExtUserRoleMapper extUserRoleMapper; private ExtUserRoleMapper extUserRoleMapper;
@Resource @Resource
private OrganizationMapper organizationMapper; private OrganizationMapper organizationMapper;
@Resource
private WorkspaceMapper workspaceMapper;
public UserDTO insert(User user) { public UserDTO insert(User user) {
checkUserParam(user); checkUserParam(user);
@ -221,10 +219,17 @@ public class UserService {
return resultList; return resultList;
} }
public void switchUserRole(UserDTO user, String sourceId) { public void switchUserRole(UserDTO user,String sign,String sourceId) {
User newUser = new User(); User newUser = new User();
// todo 切换处理 if (StringUtils.equals("organization", sign)) {
// user.setLastSourceId(sourceId); user.setLastOrganizationId(sourceId);
user.setLastWorkspaceId("");
}
if (StringUtils.equals("workspace", sign)) {
Workspace workspace = workspaceMapper.selectByPrimaryKey(sourceId);
user.setLastOrganizationId(workspace.getOrganizationId());
user.setLastWorkspaceId(sourceId);
}
BeanUtils.copyProperties(user, newUser); BeanUtils.copyProperties(user, newUser);
// 切换工作空间或组织之后更新 session 里的 user // 切换工作空间或组织之后更新 session 里的 user
SessionUtils.putUser(SessionUser.fromUser(user)); SessionUtils.putUser(SessionUser.fromUser(user));

View File

@ -100,4 +100,10 @@ public class WorkspaceService {
return workspaceMapper.selectByExample(workspaceExample); return workspaceMapper.selectByExample(workspaceExample);
} }
public List<Workspace> getWorkspaceListByOrgId(String orgId) {
WorkspaceExample workspaceExample = new WorkspaceExample();
workspaceExample.createCriteria().andOrganizationIdEqualTo(orgId);
return workspaceMapper.selectByExample(workspaceExample);
}
} }

View File

@ -26,10 +26,10 @@ public class SessionUtils {
} }
public static String getCurrentWorkspaceId() { public static String getCurrentWorkspaceId() {
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getWorkspaceId(); return Optional.ofNullable(getUser()).orElse(new SessionUser()).getLastWorkspaceId();
} }
public static String getCurrentOrganizationId() { public static String getCurrentOrganizationId() {
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getOrganizationId(); return Optional.ofNullable(getUser()).orElse(new SessionUser()).getLastOrganizationId();
} }
} }

View File

@ -9,18 +9,18 @@
<el-submenu index="1" popper-class="submenu" v-permission="['org_admin']"> <el-submenu index="1" popper-class="submenu" v-permission="['org_admin']">
<template slot="title">组织</template> <template slot="title">组织</template>
<label v-for="(item,index) in organizationList" :key="index"> <label v-for="(item,index) in organizationList" :key="index">
<el-menu-item @click="clickMenu(item)">{{item.name}} <el-menu-item @click="changeOrg(item)">{{item.name}}
<i class="el-icon-check" <i class="el-icon-check"
v-if="item.id === currentUserInfo.lastSourceId || item.id === workspaceParentId"></i> v-if="item.id === currentUserInfo.lastOrganizationId"></i>
</el-menu-item> </el-menu-item>
</label> </label>
</el-submenu> </el-submenu>
<el-submenu index="2" popper-class="submenu" v-permission="['test_manager', 'test_user', 'test_viewer']"> <el-submenu index="2" popper-class="submenu" v-permission="['test_manager', 'test_user', 'test_viewer']">
<template slot="title">工作空间</template> <template slot="title">工作空间</template>
<label v-for="(item,index) in workspaceList" :key="index"> <label v-for="(item,index) in workspaceList" :key="index">
<el-menu-item @click="clickMenu(item)"> <el-menu-item @click="changeWs(item)">
{{item.name}} {{item.name}}
<i class="el-icon-check" v-if="item.id === currentUserInfo.lastSourceId"></i> <i class="el-icon-check" v-if="item.id === currentUserInfo.lastWorkspaceId"></i>
</el-menu-item> </el-menu-item>
</label> </label>
</el-submenu> </el-submenu>
@ -54,7 +54,7 @@
data() { data() {
return { return {
organizationList: [ organizationList: [
{index: '7-1', name: '组织1'}, {index: '7-1', name: '组织'},
], ],
workspaceList: [ workspaceList: [
{index: '2-1', name: '无工作空间'}, {index: '2-1', name: '无工作空间'},
@ -105,10 +105,15 @@
}); });
} }
if (roles.indexOf(ROLE_TEST_MANAGER) > -1 || roles.indexOf(ROLE_TEST_USER) > -1 || roles.indexOf(ROLE_TEST_VIEWER) > -1) { 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.$get("/workspace/list/orgworkspace/", response => {
this.workspaceList = response.data; let data = response.data;
this.workspaceIds = response.data.map(r => r.id); if (data.length == 0) {
}); this.workspaceList = [{index:'1-1', name: '无工作区间'}]
} else {
this.workspaceList = data;
}
// this.workspaceIds = response.data.map(r = r.id);
})
} }
}, },
getCurrentUserInfo() { getCurrentUserInfo() {
@ -116,19 +121,25 @@
this.currentUserInfo = response.data; this.currentUserInfo = response.data;
}) })
}, },
clickMenu(data) { changeOrg(data) {
if (data.id === this.currentUserInfo.lastSourceId) { let orgId = data.id;
return false; let sign = "organization";
} this.$post("/user/switch/source/" + sign + "/" + orgId, {}, response => {
window.console.log(data.id); Cookies.set(TokenKey, response.data);
let user = {}; window.location.reload();
user.id = this.currentUserInfo.id; })
user.lastSourceId = data.id; },
this.$post("/user/switch/source/" + user.lastSourceId, {}, response => { changeWs(data) {
let sign = "workspace";
let workspaceId = data.id;
// todo
if (typeof(workspaceId) == "undefined") {
return false;
}
this.$post("/user/switch/source/" + sign + "/" + workspaceId, {}, response => {
Cookies.set(TokenKey, response.data); Cookies.set(TokenKey, response.data);
window.location.reload(); window.location.reload();
}) })
} }
} }
} }

View File

@ -127,7 +127,7 @@
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.result = this.$get('/user/orgmember/delete/' + this.currentOrganizationId + '/' + row.id, () => { this.result = this.$get('/user/orgmember/delete/' + this.currentUser().organizationId + '/' + row.id, () => {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '删除成功!' message: '删除成功!'
@ -153,7 +153,7 @@
if (valid) { if (valid) {
let param = { let param = {
userIds: this.form.userIds, userIds: this.form.userIds,
organizationId: this.currentOrganizationId organizationId: this.currentUser().organizationId
}; };
this.result = this.$post("user/orgmember/add", param,() => { this.result = this.$post("user/orgmember/add", param,() => {
this.initTableData(); this.initTableData();