refactor: 创建组织,工作空间,项目后为当前用户添加管理员权限

This commit is contained in:
Captain.B 2021-05-31 18:42:23 +08:00 committed by 刘瑞斌
parent 312a122df1
commit 89b24fe0cc
3 changed files with 55 additions and 5 deletions

View File

@ -6,12 +6,16 @@ import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.commons.constants.UserGroupConstants;
import io.metersphere.commons.constants.UserGroupType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.OrganizationRequest;
import io.metersphere.dto.*;
import io.metersphere.dto.OrganizationMemberDTO;
import io.metersphere.dto.OrganizationResource;
import io.metersphere.dto.RelatedSource;
import io.metersphere.dto.UserDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn;
@ -65,6 +69,16 @@ public class OrganizationService {
organization.setUpdateTime(currentTimeMillis);
organization.setCreateUser(SessionUtils.getUserId());
organizationMapper.insertSelective(organization);
// 创建组织为当前用户添加用户组
UserGroup userGroup = new UserGroup();
userGroup.setId(UUID.randomUUID().toString());
userGroup.setUserId(SessionUtils.getUserId());
userGroup.setCreateTime(System.currentTimeMillis());
userGroup.setUpdateTime(System.currentTimeMillis());
userGroup.setGroupId(UserGroupConstants.ORG_ADMIN);
userGroup.setSourceId(organization.getId());
userGroupMapper.insert(userGroup);
return organization;
}

View File

@ -10,6 +10,7 @@ import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
import io.metersphere.commons.constants.UserGroupConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils;
@ -37,7 +38,10 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@ -93,7 +97,7 @@ public class ProjectService {
long allCount = projectMapper.countByExample(null);
String systemId = String.valueOf(100001+allCount);
String systemId = String.valueOf(100001 + allCount);
long createTime = System.currentTimeMillis();
project.setCreateTime(createTime);
@ -103,6 +107,17 @@ public class ProjectService {
project.setCreateUser(SessionUtils.getUserId());
project.setSystemId(systemId);
projectMapper.insertSelective(project);
// 创建项目为当前用户添加用户组
UserGroup userGroup = new UserGroup();
userGroup.setId(UUID.randomUUID().toString());
userGroup.setUserId(SessionUtils.getUserId());
userGroup.setCreateTime(System.currentTimeMillis());
userGroup.setUpdateTime(System.currentTimeMillis());
userGroup.setGroupId(UserGroupConstants.PROJECT_ADMIN);
userGroup.setSourceId(project.getId());
userGroupMapper.insert(userGroup);
return project;
}
@ -427,9 +442,9 @@ public class ProjectService {
ProjectExample example = new ProjectExample();
example.createCriteria().andSystemIdEqualTo(systemId);
List<Project> returnList = projectMapper.selectByExample(example);
if(CollectionUtils.isEmpty(returnList)){
if (CollectionUtils.isEmpty(returnList)) {
return null;
}else {
} else {
return returnList.get(0);
}
}

View File

@ -7,6 +7,7 @@ import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.base.mapper.ext.ExtWorkspaceMapper;
import io.metersphere.commons.constants.UserGroupConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.WorkspaceRequest;
@ -75,6 +76,15 @@ public class WorkspaceService {
workspace.setUpdateTime(currentTime);
workspace.setCreateUser(SessionUtils.getUserId());
workspaceMapper.insertSelective(workspace);
// 创建工作空间为当前用户添加用户组
UserGroup userGroup = new UserGroup();
userGroup.setId(UUID.randomUUID().toString());
userGroup.setUserId(SessionUtils.getUserId());
userGroup.setCreateTime(System.currentTimeMillis());
userGroup.setUpdateTime(System.currentTimeMillis());
userGroup.setGroupId(UserGroupConstants.WS_ADMIN);
userGroup.setSourceId(workspace.getId());
userGroupMapper.insert(userGroup);
} else {
workspace.setUpdateTime(currentTime);
workspaceMapper.updateByPrimaryKeySelective(workspace);
@ -260,6 +270,17 @@ public class WorkspaceService {
workspace.setUpdateTime(System.currentTimeMillis());
workspace.setCreateUser(SessionUtils.getUserId());
workspaceMapper.insertSelective(workspace);
// 创建工作空间为当前用户添加用户组
UserGroup userGroup = new UserGroup();
userGroup.setId(UUID.randomUUID().toString());
userGroup.setUserId(SessionUtils.getUserId());
userGroup.setCreateTime(System.currentTimeMillis());
userGroup.setUpdateTime(System.currentTimeMillis());
userGroup.setGroupId(UserGroupConstants.WS_ADMIN);
userGroup.setSourceId(workspace.getId());
userGroupMapper.insert(userGroup);
return workspace;
}