Merge branch 'dev' of github.com:fit2cloudrd/metersphere-server into dev
This commit is contained in:
commit
e2e3d799ab
|
@ -54,10 +54,10 @@ public class LoginController {
|
||||||
List<UserRole> org = userRoles.stream().filter(ur -> ur.getRoleId().startsWith("org")).collect(Collectors.toList());
|
List<UserRole> org = userRoles.stream().filter(ur -> ur.getRoleId().startsWith("org")).collect(Collectors.toList());
|
||||||
if (test.size() > 0) {
|
if (test.size() > 0) {
|
||||||
String wsId = test.get(0).getSourceId();
|
String wsId = test.get(0).getSourceId();
|
||||||
userService.switchUserRole(user, "workspace", wsId);
|
userService.switchUserRole("workspace", wsId);
|
||||||
} else if (org.size() > 0) {
|
} else if (org.size() > 0) {
|
||||||
String orgId = org.get(0).getSourceId();
|
String orgId = org.get(0).getSourceId();
|
||||||
userService.switchUserRole(user, "organization", orgId);
|
userService.switchUserRole("organization", orgId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 返回 userDTO
|
// 返回 userDTO
|
||||||
|
|
|
@ -129,16 +129,14 @@ public class UserController {
|
||||||
@PostMapping("/switch/source/org/{sourceId}")
|
@PostMapping("/switch/source/org/{sourceId}")
|
||||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||||
public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) {
|
public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) {
|
||||||
UserDTO user = SessionUtils.getUser();
|
userService.switchUserRole("organization",sourceId);
|
||||||
userService.switchUserRole(user,"organization",sourceId);
|
|
||||||
return SessionUtils.getUser();
|
return SessionUtils.getUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/switch/source/ws/{sourceId}")
|
@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) {
|
public UserDTO switchWorkspace(@PathVariable(value = "sourceId") String sourceId) {
|
||||||
UserDTO user = SessionUtils.getUser();
|
userService.switchUserRole("workspace", sourceId);
|
||||||
userService.switchUserRole(user, "workspace", sourceId);
|
|
||||||
return SessionUtils.getUser();
|
return SessionUtils.getUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ public class WorkspaceController {
|
||||||
@PostMapping("add")
|
@PostMapping("add")
|
||||||
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
@RequiresRoles(RoleConstants.ORG_ADMIN)
|
||||||
public Workspace addWorkspace(@RequestBody Workspace workspace) {
|
public Workspace addWorkspace(@RequestBody Workspace workspace) {
|
||||||
|
workspaceService.checkWorkspaceOwnerByOrgAdmin(workspace.getId());
|
||||||
return workspaceService.saveWorkspace(workspace);
|
return workspaceService.saveWorkspace(workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,14 @@ import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.OrganizationMapper;
|
import io.metersphere.base.mapper.OrganizationMapper;
|
||||||
import io.metersphere.base.mapper.UserMapper;
|
import io.metersphere.base.mapper.UserMapper;
|
||||||
import io.metersphere.base.mapper.UserRoleMapper;
|
import io.metersphere.base.mapper.UserRoleMapper;
|
||||||
|
import io.metersphere.base.mapper.WorkspaceMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
|
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
|
||||||
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;
|
||||||
import io.metersphere.controller.request.OrganizationRequest;
|
import io.metersphere.controller.request.OrganizationRequest;
|
||||||
import io.metersphere.dto.OrganizationMemberDTO;
|
import io.metersphere.dto.OrganizationMemberDTO;
|
||||||
|
import io.metersphere.dto.UserDTO;
|
||||||
import io.metersphere.dto.UserRoleHelpDTO;
|
import io.metersphere.dto.UserRoleHelpDTO;
|
||||||
import io.metersphere.i18n.Translator;
|
import io.metersphere.i18n.Translator;
|
||||||
import io.metersphere.user.SessionUser;
|
import io.metersphere.user.SessionUser;
|
||||||
|
@ -39,6 +41,12 @@ public class OrganizationService {
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtOrganizationMapper extOrganizationMapper;
|
private ExtOrganizationMapper extOrganizationMapper;
|
||||||
|
@Resource
|
||||||
|
private WorkspaceMapper workspaceMapper;
|
||||||
|
@Resource
|
||||||
|
private WorkspaceService workspaceService;
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
public Organization addOrganization(Organization organization) {
|
public Organization addOrganization(Organization organization) {
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
|
@ -123,7 +131,8 @@ public class OrganizationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkOrgOwner(String organizationId) {
|
public void checkOrgOwner(String organizationId) {
|
||||||
SessionUser user = SessionUtils.getUser();
|
SessionUser sessionUser = SessionUtils.getUser();
|
||||||
|
UserDTO user = userService.getUserDTO(sessionUser.getId());
|
||||||
List<String> collect = user.getUserRoles().stream()
|
List<String> collect = user.getUserRoles().stream()
|
||||||
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
|
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
|
||||||
.map(UserRole::getSourceId)
|
.map(UserRole::getSourceId)
|
||||||
|
|
|
@ -128,7 +128,11 @@ public class UserService {
|
||||||
userMapper.updateByPrimaryKeySelective(user);
|
userMapper.updateByPrimaryKeySelective(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchUserRole(UserDTO user, String sign, String sourceId) {
|
public void switchUserRole(String sign, String sourceId) {
|
||||||
|
SessionUser sessionUser = SessionUtils.getUser();
|
||||||
|
// 获取最新UserDTO
|
||||||
|
UserDTO user = getUserDTO(sessionUser.getId());
|
||||||
|
|
||||||
User newUser = new User();
|
User newUser = new User();
|
||||||
if (StringUtils.equals("organization", sign)) {
|
if (StringUtils.equals("organization", sign)) {
|
||||||
user.setLastOrganizationId(sourceId);
|
user.setLastOrganizationId(sourceId);
|
||||||
|
|
|
@ -1,6 +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.ProjectMapper;
|
||||||
import io.metersphere.base.mapper.UserMapper;
|
import io.metersphere.base.mapper.UserMapper;
|
||||||
import io.metersphere.base.mapper.UserRoleMapper;
|
import io.metersphere.base.mapper.UserRoleMapper;
|
||||||
import io.metersphere.base.mapper.WorkspaceMapper;
|
import io.metersphere.base.mapper.WorkspaceMapper;
|
||||||
|
@ -10,6 +11,7 @@ import io.metersphere.base.mapper.ext.ExtWorkspaceMapper;
|
||||||
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.controller.request.WorkspaceRequest;
|
import io.metersphere.controller.request.WorkspaceRequest;
|
||||||
|
import io.metersphere.dto.UserDTO;
|
||||||
import io.metersphere.dto.UserRoleHelpDTO;
|
import io.metersphere.dto.UserRoleHelpDTO;
|
||||||
import io.metersphere.dto.WorkspaceDTO;
|
import io.metersphere.dto.WorkspaceDTO;
|
||||||
import io.metersphere.dto.WorkspaceMemberDTO;
|
import io.metersphere.dto.WorkspaceMemberDTO;
|
||||||
|
@ -41,6 +43,12 @@ public class WorkspaceService {
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtOrganizationMapper extOrganizationMapper;
|
private ExtOrganizationMapper extOrganizationMapper;
|
||||||
|
@Resource
|
||||||
|
private ProjectService projectService;
|
||||||
|
@Resource
|
||||||
|
private ProjectMapper projectMapper;
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
public Workspace saveWorkspace(Workspace workspace) {
|
public Workspace saveWorkspace(Workspace workspace) {
|
||||||
if (StringUtils.isBlank(workspace.getName())) {
|
if (StringUtils.isBlank(workspace.getName())) {
|
||||||
|
@ -98,7 +106,8 @@ public class WorkspaceService {
|
||||||
public void checkWorkspaceOwnerByOrgAdmin(String workspaceId) {
|
public void checkWorkspaceOwnerByOrgAdmin(String workspaceId) {
|
||||||
checkWorkspaceIsExist(workspaceId);
|
checkWorkspaceIsExist(workspaceId);
|
||||||
WorkspaceExample example = new WorkspaceExample();
|
WorkspaceExample example = new WorkspaceExample();
|
||||||
SessionUser user = SessionUtils.getUser();
|
SessionUser sessionUser = SessionUtils.getUser();
|
||||||
|
UserDTO user = userService.getUserDTO(sessionUser.getId());
|
||||||
List<String> orgIds = user.getUserRoles().stream()
|
List<String> orgIds = user.getUserRoles().stream()
|
||||||
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
|
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
|
||||||
.map(UserRole::getSourceId)
|
.map(UserRole::getSourceId)
|
||||||
|
@ -114,7 +123,8 @@ public class WorkspaceService {
|
||||||
public void checkWorkspaceOwner(String workspaceId) {
|
public void checkWorkspaceOwner(String workspaceId) {
|
||||||
checkWorkspaceIsExist(workspaceId);
|
checkWorkspaceIsExist(workspaceId);
|
||||||
WorkspaceExample example = new WorkspaceExample();
|
WorkspaceExample example = new WorkspaceExample();
|
||||||
SessionUser user = SessionUtils.getUser();
|
SessionUser sessionUser = SessionUtils.getUser();
|
||||||
|
UserDTO user = userService.getUserDTO(sessionUser.getId());
|
||||||
List<String> orgIds = user.getUserRoles().stream()
|
List<String> orgIds = user.getUserRoles().stream()
|
||||||
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
|
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
|
||||||
.map(UserRole::getSourceId)
|
.map(UserRole::getSourceId)
|
||||||
|
|
Loading…
Reference in New Issue