Merge branch 'dev' of github.com:fit2cloudrd/metersphere-server into dev

This commit is contained in:
Captain.B 2020-04-30 15:18:56 +08:00
commit e2e3d799ab
6 changed files with 32 additions and 10 deletions

View File

@ -54,10 +54,10 @@ public class LoginController {
List<UserRole> org = userRoles.stream().filter(ur -> ur.getRoleId().startsWith("org")).collect(Collectors.toList());
if (test.size() > 0) {
String wsId = test.get(0).getSourceId();
userService.switchUserRole(user, "workspace", wsId);
userService.switchUserRole("workspace", wsId);
} else if (org.size() > 0) {
String orgId = org.get(0).getSourceId();
userService.switchUserRole(user, "organization", orgId);
userService.switchUserRole("organization", orgId);
}
}
// 返回 userDTO

View File

@ -129,16 +129,14 @@ public class UserController {
@PostMapping("/switch/source/org/{sourceId}")
@RequiresRoles(RoleConstants.ORG_ADMIN)
public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) {
UserDTO user = SessionUtils.getUser();
userService.switchUserRole(user,"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)
public UserDTO switchWorkspace(@PathVariable(value = "sourceId") String sourceId) {
UserDTO user = SessionUtils.getUser();
userService.switchUserRole(user, "workspace", sourceId);
userService.switchUserRole("workspace", sourceId);
return SessionUtils.getUser();
}

View File

@ -27,6 +27,7 @@ public class WorkspaceController {
@PostMapping("add")
@RequiresRoles(RoleConstants.ORG_ADMIN)
public Workspace addWorkspace(@RequestBody Workspace workspace) {
workspaceService.checkWorkspaceOwnerByOrgAdmin(workspace.getId());
return workspaceService.saveWorkspace(workspace);
}

View File

@ -4,12 +4,14 @@ import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.OrganizationMapper;
import io.metersphere.base.mapper.UserMapper;
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.ExtUserRoleMapper;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.OrganizationRequest;
import io.metersphere.dto.OrganizationMemberDTO;
import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleHelpDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.user.SessionUser;
@ -39,6 +41,12 @@ public class OrganizationService {
private UserMapper userMapper;
@Resource
private ExtOrganizationMapper extOrganizationMapper;
@Resource
private WorkspaceMapper workspaceMapper;
@Resource
private WorkspaceService workspaceService;
@Resource
private UserService userService;
public Organization addOrganization(Organization organization) {
long currentTimeMillis = System.currentTimeMillis();
@ -123,7 +131,8 @@ public class OrganizationService {
}
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()
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
.map(UserRole::getSourceId)

View File

@ -128,7 +128,11 @@ public class UserService {
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();
if (StringUtils.equals("organization", sign)) {
user.setLastOrganizationId(sourceId);

View File

@ -1,6 +1,7 @@
package io.metersphere.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.UserRoleMapper;
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.exception.MSException;
import io.metersphere.controller.request.WorkspaceRequest;
import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleHelpDTO;
import io.metersphere.dto.WorkspaceDTO;
import io.metersphere.dto.WorkspaceMemberDTO;
@ -41,6 +43,12 @@ public class WorkspaceService {
private UserMapper userMapper;
@Resource
private ExtOrganizationMapper extOrganizationMapper;
@Resource
private ProjectService projectService;
@Resource
private ProjectMapper projectMapper;
@Resource
private UserService userService;
public Workspace saveWorkspace(Workspace workspace) {
if (StringUtils.isBlank(workspace.getName())) {
@ -98,7 +106,8 @@ public class WorkspaceService {
public void checkWorkspaceOwnerByOrgAdmin(String workspaceId) {
checkWorkspaceIsExist(workspaceId);
WorkspaceExample example = new WorkspaceExample();
SessionUser user = SessionUtils.getUser();
SessionUser sessionUser = SessionUtils.getUser();
UserDTO user = userService.getUserDTO(sessionUser.getId());
List<String> orgIds = user.getUserRoles().stream()
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
.map(UserRole::getSourceId)
@ -114,7 +123,8 @@ public class WorkspaceService {
public void checkWorkspaceOwner(String workspaceId) {
checkWorkspaceIsExist(workspaceId);
WorkspaceExample example = new WorkspaceExample();
SessionUser user = SessionUtils.getUser();
SessionUser sessionUser = SessionUtils.getUser();
UserDTO user = userService.getUserDTO(sessionUser.getId());
List<String> orgIds = user.getUserRoles().stream()
.filter(ur -> RoleConstants.ORG_ADMIN.equals(ur.getRoleId()))
.map(UserRole::getSourceId)