优化工作空间和组织相关部分
This commit is contained in:
parent
c1e6062645
commit
5abece2d37
|
@ -9,6 +9,7 @@ import io.metersphere.commons.utils.Pager;
|
|||
import io.metersphere.controller.request.OrganizationRequest;
|
||||
import io.metersphere.dto.OrganizationMemberDTO;
|
||||
import io.metersphere.service.OrganizationService;
|
||||
import io.metersphere.service.UserService;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -22,6 +23,8 @@ public class OrganizationController {
|
|||
|
||||
@Resource
|
||||
private OrganizationService organizationService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
|
@ -45,6 +48,7 @@ public class OrganizationController {
|
|||
@GetMapping("/delete/{organizationId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void deleteOrganization(@PathVariable(value = "organizationId") String organizationId) {
|
||||
userService.refreshSessionUser("organization", organizationId);
|
||||
organizationService.deleteOrganization(organizationId);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.shiro.authz.annotation.Logical;
|
|||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -115,7 +116,7 @@ public class UserController {
|
|||
// admin api
|
||||
|
||||
@GetMapping("/list")
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN,RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
@RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public List<User> getUserList() {
|
||||
return userService.getUserList();
|
||||
}
|
||||
|
@ -132,17 +133,24 @@ public class UserController {
|
|||
@PostMapping("/switch/source/org/{sourceId}")
|
||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||
public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) {
|
||||
userService.switchUserRole("organization",sourceId);
|
||||
userService.switchUserRole("organization", sourceId);
|
||||
return SessionUtils.getUser();
|
||||
}
|
||||
|
||||
@PostMapping("/switch/source/ws/{sourceId}")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.TEST_VIEWER,RoleConstants.TEST_USER}, logical = Logical.OR)
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_VIEWER, RoleConstants.TEST_USER}, logical = Logical.OR)
|
||||
public UserDTO switchWorkspace(@PathVariable(value = "sourceId") String sourceId) {
|
||||
userService.switchUserRole("workspace", sourceId);
|
||||
return SessionUtils.getUser();
|
||||
}
|
||||
|
||||
@PostMapping("/refresh/{sign}/{sourceId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public UserDTO refreshSessionUser(@PathVariable String sign, @PathVariable String sourceId) {
|
||||
userService.refreshSessionUser(sign, sourceId);
|
||||
return SessionUtils.getUser();
|
||||
}
|
||||
|
||||
@GetMapping("/info/{userId}")
|
||||
public User getUserInfo(@PathVariable(value = "userId") String userId) {
|
||||
return userService.getUserInfo(userId);
|
||||
|
@ -152,8 +160,8 @@ public class UserController {
|
|||
* 获取工作空间成员用户
|
||||
*/
|
||||
@PostMapping("/ws/member/list/{goPage}/{pageSize}")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER,
|
||||
RoleConstants.TEST_USER,RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER,
|
||||
RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
public Pager<List<User>> getMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, userService.getMemberList(request));
|
||||
|
@ -163,8 +171,8 @@ public class UserController {
|
|||
* 获取工作空间成员用户 不分页
|
||||
*/
|
||||
@PostMapping("/ws/member/list/all")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER,
|
||||
RoleConstants.TEST_USER,RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER,
|
||||
RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
public List<User> getMemberList(@RequestBody QueryMemberRequest request) {
|
||||
return userService.getMemberList(request);
|
||||
}
|
||||
|
@ -173,7 +181,7 @@ public class UserController {
|
|||
* 添加工作空间成员
|
||||
*/
|
||||
@PostMapping("/ws/member/add")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public void addMember(@RequestBody AddMemberRequest request) {
|
||||
String wsId = request.getWorkspaceId();
|
||||
workspaceService.checkWorkspaceOwner(wsId);
|
||||
|
@ -184,7 +192,7 @@ public class UserController {
|
|||
* 删除工作空间成员
|
||||
*/
|
||||
@GetMapping("/ws/member/delete/{workspaceId}/{userId}")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.ORG_ADMIN}, logical = Logical.OR)
|
||||
public void deleteMember(@PathVariable String workspaceId, @PathVariable String userId) {
|
||||
workspaceService.checkWorkspaceOwner(workspaceId);
|
||||
String currentUserId = SessionUtils.getUser().getId();
|
||||
|
@ -222,7 +230,7 @@ public class UserController {
|
|||
* 查询组织成员列表
|
||||
*/
|
||||
@PostMapping("/org/member/list/{goPage}/{pageSize}")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public Pager<List<User>> getOrgMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryOrgMemberRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, userService.getOrgMemberList(request));
|
||||
|
@ -232,7 +240,7 @@ public class UserController {
|
|||
* 组织成员列表不分页
|
||||
*/
|
||||
@PostMapping("/org/member/list/all")
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
@RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public List<User> getOrgMemberList(@RequestBody QueryOrgMemberRequest request) {
|
||||
return userService.getOrgMemberList(request);
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@ import io.metersphere.controller.request.WorkspaceRequest;
|
|||
import io.metersphere.dto.WorkspaceDTO;
|
||||
import io.metersphere.dto.WorkspaceMemberDTO;
|
||||
import io.metersphere.service.OrganizationService;
|
||||
import io.metersphere.service.UserService;
|
||||
import io.metersphere.service.WorkspaceService;
|
||||
import io.metersphere.user.SessionUtils;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -26,6 +26,8 @@ public class WorkspaceController {
|
|||
private WorkspaceService workspaceService;
|
||||
@Resource
|
||||
private OrganizationService organizationService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("add")
|
||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||
|
@ -57,6 +59,7 @@ public class WorkspaceController {
|
|||
@GetMapping("special/delete/{workspaceId}")
|
||||
@RequiresRoles(RoleConstants.ADMIN)
|
||||
public void deleteWorkspaceByAdmin(@PathVariable String workspaceId) {
|
||||
userService.refreshSessionUser("workspace", workspaceId);
|
||||
workspaceService.deleteWorkspace(workspaceId);
|
||||
}
|
||||
|
||||
|
@ -64,6 +67,7 @@ public class WorkspaceController {
|
|||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||
public void deleteWorkspace(@PathVariable String workspaceId) {
|
||||
workspaceService.checkWorkspaceOwnerByOrgAdmin(workspaceId);
|
||||
userService.refreshSessionUser("workspace", workspaceId);
|
||||
workspaceService.deleteWorkspace(workspaceId);
|
||||
}
|
||||
|
||||
|
|
|
@ -256,4 +256,23 @@ public class UserService {
|
|||
SessionUtils.getUser().setLanguage(lang);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshSessionUser(String sign, String sourceId) {
|
||||
SessionUser sessionUser = SessionUtils.getUser();
|
||||
// 获取最新UserDTO
|
||||
UserDTO user = getUserDTO(sessionUser.getId());
|
||||
User newUser = new User();
|
||||
if (StringUtils.equals("organization", sign) && StringUtils.equals(sourceId, user.getLastOrganizationId())) {
|
||||
user.setLastOrganizationId("");
|
||||
user.setLastWorkspaceId("");
|
||||
}
|
||||
if (StringUtils.equals("workspace", sign) && StringUtils.equals(sourceId, user.getLastWorkspaceId())) {
|
||||
user.setLastWorkspaceId("");
|
||||
}
|
||||
|
||||
BeanUtils.copyProperties(user, newUser);
|
||||
|
||||
SessionUtils.putUser(SessionUser.fromUser(user));
|
||||
userMapper.updateByPrimaryKeySelective(newUser);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,12 +145,13 @@
|
|||
<script>
|
||||
import MsCreateBox from "../CreateBox";
|
||||
import {Message} from "element-ui";
|
||||
import {TokenKey} from "../../../../common/js/constants";
|
||||
import {DEFAULT, TokenKey} from "../../../../common/js/constants";
|
||||
import MsTablePagination from "../../common/pagination/TablePagination";
|
||||
import MsTableHeader from "../../common/components/MsTableHeader";
|
||||
import MsRolesTag from "../../common/components/MsRolesTag";
|
||||
import MsTableOperator from "../../common/components/MsTableOperator";
|
||||
import MsDialogFooter from "../../common/components/MsDialogFooter";
|
||||
import {getCurrentWorkspaceId, refreshSessionAndCookies} from "../../../../common/js/utils";
|
||||
|
||||
export default {
|
||||
name: "MsOrganizationWorkspace",
|
||||
|
@ -197,6 +198,12 @@
|
|||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.$get('/workspace/delete/' + row.id, () => {
|
||||
let lastWorkspaceId = getCurrentWorkspaceId();
|
||||
let sourceId = row.id;
|
||||
if (lastWorkspaceId === sourceId) {
|
||||
let sign = DEFAULT;
|
||||
refreshSessionAndCookies(sign, sourceId);
|
||||
}
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
this.list();
|
||||
});
|
||||
|
|
|
@ -175,6 +175,8 @@
|
|||
import MsRolesTag from "../../common/components/MsRolesTag";
|
||||
import MsTableOperator from "../../common/components/MsTableOperator";
|
||||
import MsDialogFooter from "../../common/components/MsDialogFooter";
|
||||
import {getCurrentOrganizationId, getCurrentUser, refreshSessionAndCookies} from "../../../../common/js/utils";
|
||||
import {DEFAULT, ORGANIZATION} from "../../../../common/js/constants";
|
||||
|
||||
export default {
|
||||
name: "MsOrganization",
|
||||
|
@ -311,6 +313,12 @@
|
|||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.result = this.$get(this.deletePath + row.id, () => {
|
||||
let lastOrganizationId = getCurrentOrganizationId();
|
||||
let sourceId = row.id;
|
||||
if (lastOrganizationId === sourceId) {
|
||||
let sign = DEFAULT;
|
||||
refreshSessionAndCookies(sign, sourceId);
|
||||
}
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
this.initTableData();
|
||||
});
|
||||
|
@ -325,6 +333,13 @@
|
|||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.result = this.$get('/user/special/org/member/delete/' + this.currentRow.id + '/' + row.id, () => {
|
||||
let sourceId = this.currentRow.id;
|
||||
let currentUser = getCurrentUser();
|
||||
let userId = row.id;
|
||||
if (currentUser.id === userId) {
|
||||
let sign = ORGANIZATION;
|
||||
refreshSessionAndCookies(sign, sourceId);
|
||||
}
|
||||
this.$success(this.$t('commons.delete_success'))
|
||||
this.cellClick(this.currentRow);
|
||||
});
|
||||
|
@ -395,6 +410,9 @@
|
|||
organizationId: this.currentRow.id
|
||||
};
|
||||
this.result = this.$post("user/special/org/member/add", param, () => {
|
||||
let sign = "other";
|
||||
let sourceId = this.currentRow.id;
|
||||
refreshSessionAndCookies(sign, sourceId);
|
||||
this.cellClick(this.currentRow);
|
||||
this.dialogOrgMemberAddVisible = false;
|
||||
})
|
||||
|
|
|
@ -195,6 +195,8 @@
|
|||
import MsRolesTag from "../../common/components/MsRolesTag";
|
||||
import MsTableOperator from "../../common/components/MsTableOperator";
|
||||
import MsDialogFooter from "../../common/components/MsDialogFooter";
|
||||
import {getCurrentUser, getCurrentWorkspaceId, refreshSessionAndCookies} from "../../../../common/js/utils";
|
||||
import {DEFAULT, WORKSPACE} from "../../../../common/js/constants";
|
||||
|
||||
export default {
|
||||
name: "MsSystemWorkspace",
|
||||
|
@ -307,6 +309,12 @@
|
|||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.$get('/workspace/special/delete/' + row.id, () => {
|
||||
let lastWorkspaceId = getCurrentWorkspaceId();
|
||||
let sourceId = row.id;
|
||||
if (lastWorkspaceId === sourceId) {
|
||||
let sign = DEFAULT;
|
||||
refreshSessionAndCookies(sign, sourceId);
|
||||
}
|
||||
Message.success(this.$t('commons.delete_success'));
|
||||
this.list();
|
||||
});
|
||||
|
@ -374,6 +382,13 @@
|
|||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.result = this.$get('/user/special/ws/member/delete/' + this.currentWorkspaceRow.id + '/' + row.id, () => {
|
||||
let sourceId = this.currentWorkspaceRow.id;
|
||||
let userId = row.id;
|
||||
let user = getCurrentUser();
|
||||
if (user.id === userId) {
|
||||
let sign = WORKSPACE;
|
||||
refreshSessionAndCookies(sign, sourceId);
|
||||
}
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
this.cellClick(this.currentWorkspaceRow);
|
||||
});
|
||||
|
|
|
@ -8,3 +8,8 @@ export const ROLE_TEST_VIEWER = 'test_viewer';
|
|||
|
||||
export const WORKSPACE_ID = 'workspace_id';
|
||||
export const CURRENT_PROJECT = 'current_project';
|
||||
|
||||
export const REFRESH_SESSION_USER_URL = 'user/refresh';
|
||||
export const WORKSPACE = 'workspace';
|
||||
export const ORGANIZATION = 'organization';
|
||||
export const DEFAULT = 'default';
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
import {ROLE_ORG_ADMIN, ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER, TokenKey} from "./constants";
|
||||
import {
|
||||
REFRESH_SESSION_USER_URL,
|
||||
ROLE_ORG_ADMIN,
|
||||
ROLE_TEST_MANAGER,
|
||||
ROLE_TEST_USER,
|
||||
ROLE_TEST_VIEWER,
|
||||
TokenKey
|
||||
} from "./constants";
|
||||
import axios from "axios";
|
||||
|
||||
export function hasRole(role) {
|
||||
let user = JSON.parse(localStorage.getItem(TokenKey));
|
||||
|
@ -29,6 +37,20 @@ export function checkoutCurrentWorkspace() {
|
|||
return user.userRoles.filter(ur => hasRoles(ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER) && user.lastWorkspaceId === ur.sourceId).length > 0;
|
||||
}
|
||||
|
||||
export function getCurrentOrganizationId() {
|
||||
let user = JSON.parse(localStorage.getItem(TokenKey));
|
||||
return user.lastOrganizationId;
|
||||
}
|
||||
|
||||
export function getCurrentWorkspaceId() {
|
||||
let user = JSON.parse(localStorage.getItem(TokenKey));
|
||||
return user.lastWorkspaceId;
|
||||
}
|
||||
|
||||
export function getCurrentUser() {
|
||||
return JSON.parse(localStorage.getItem(TokenKey));
|
||||
}
|
||||
|
||||
export function saveLocalStorage(response) {
|
||||
// 登录信息保存 cookie
|
||||
localStorage.setItem(TokenKey, JSON.stringify(response.data));
|
||||
|
@ -38,19 +60,26 @@ export function saveLocalStorage(response) {
|
|||
localStorage.setItem("roles", roles);
|
||||
}
|
||||
|
||||
export function refreshSessionAndCookies(sign, sourceId) {
|
||||
axios.post(REFRESH_SESSION_USER_URL + "/" + sign + "/" + sourceId).then(r => {
|
||||
saveLocalStorage(r.data);
|
||||
window.location.reload();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export function jsonToMap(jsonStr) {
|
||||
let obj = JSON.parse(jsonStr);
|
||||
let strMap = new Map();
|
||||
for (let k of Object.keys(obj)) {
|
||||
strMap.set(k,obj[k]);
|
||||
strMap.set(k, obj[k]);
|
||||
}
|
||||
return strMap;
|
||||
}
|
||||
|
||||
export function mapToJson(strMap){
|
||||
let obj= Object.create(null);
|
||||
for (let[k,v] of strMap) {
|
||||
export function mapToJson(strMap) {
|
||||
let obj = Object.create(null);
|
||||
for (let [k, v] of strMap) {
|
||||
obj[k] = v;
|
||||
}
|
||||
return JSON.stringify(obj);
|
||||
|
@ -58,5 +87,5 @@ export function mapToJson(strMap){
|
|||
|
||||
// 驼峰转换下划线
|
||||
export function humpToLine(name) {
|
||||
return name.replace(/([A-Z])/g,"_$1").toLowerCase();
|
||||
return name.replace(/([A-Z])/g, "_$1").toLowerCase();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue