refactor: 创建组织,工作空间,项目后为当前用户添加管理员权限
This commit is contained in:
parent
312a122df1
commit
89b24fe0cc
|
@ -6,12 +6,16 @@ import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
|
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
|
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
|
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
|
||||||
|
import io.metersphere.commons.constants.UserGroupConstants;
|
||||||
import io.metersphere.commons.constants.UserGroupType;
|
import io.metersphere.commons.constants.UserGroupType;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.user.SessionUser;
|
import io.metersphere.commons.user.SessionUser;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.controller.request.OrganizationRequest;
|
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.i18n.Translator;
|
||||||
import io.metersphere.log.utils.ReflexObjectUtil;
|
import io.metersphere.log.utils.ReflexObjectUtil;
|
||||||
import io.metersphere.log.vo.DetailColumn;
|
import io.metersphere.log.vo.DetailColumn;
|
||||||
|
@ -65,6 +69,16 @@ public class OrganizationService {
|
||||||
organization.setUpdateTime(currentTimeMillis);
|
organization.setUpdateTime(currentTimeMillis);
|
||||||
organization.setCreateUser(SessionUtils.getUserId());
|
organization.setCreateUser(SessionUtils.getUserId());
|
||||||
organizationMapper.insertSelective(organization);
|
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;
|
return organization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
|
import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtProjectMapper;
|
import io.metersphere.base.mapper.ext.ExtProjectMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
|
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
|
||||||
|
import io.metersphere.commons.constants.UserGroupConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.ServiceUtils;
|
import io.metersphere.commons.utils.ServiceUtils;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
|
@ -37,7 +38,10 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.IOException;
|
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;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -93,7 +97,7 @@ public class ProjectService {
|
||||||
|
|
||||||
|
|
||||||
long allCount = projectMapper.countByExample(null);
|
long allCount = projectMapper.countByExample(null);
|
||||||
String systemId = String.valueOf(100001+allCount);
|
String systemId = String.valueOf(100001 + allCount);
|
||||||
|
|
||||||
long createTime = System.currentTimeMillis();
|
long createTime = System.currentTimeMillis();
|
||||||
project.setCreateTime(createTime);
|
project.setCreateTime(createTime);
|
||||||
|
@ -103,6 +107,17 @@ public class ProjectService {
|
||||||
project.setCreateUser(SessionUtils.getUserId());
|
project.setCreateUser(SessionUtils.getUserId());
|
||||||
project.setSystemId(systemId);
|
project.setSystemId(systemId);
|
||||||
projectMapper.insertSelective(project);
|
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;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,9 +442,9 @@ public class ProjectService {
|
||||||
ProjectExample example = new ProjectExample();
|
ProjectExample example = new ProjectExample();
|
||||||
example.createCriteria().andSystemIdEqualTo(systemId);
|
example.createCriteria().andSystemIdEqualTo(systemId);
|
||||||
List<Project> returnList = projectMapper.selectByExample(example);
|
List<Project> returnList = projectMapper.selectByExample(example);
|
||||||
if(CollectionUtils.isEmpty(returnList)){
|
if (CollectionUtils.isEmpty(returnList)) {
|
||||||
return null;
|
return null;
|
||||||
}else {
|
} else {
|
||||||
return returnList.get(0);
|
return returnList.get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import io.metersphere.base.mapper.ext.ExtOrganizationMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
|
import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
|
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
|
||||||
import io.metersphere.base.mapper.ext.ExtWorkspaceMapper;
|
import io.metersphere.base.mapper.ext.ExtWorkspaceMapper;
|
||||||
|
import io.metersphere.commons.constants.UserGroupConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
import io.metersphere.controller.request.WorkspaceRequest;
|
import io.metersphere.controller.request.WorkspaceRequest;
|
||||||
|
@ -75,6 +76,15 @@ public class WorkspaceService {
|
||||||
workspace.setUpdateTime(currentTime);
|
workspace.setUpdateTime(currentTime);
|
||||||
workspace.setCreateUser(SessionUtils.getUserId());
|
workspace.setCreateUser(SessionUtils.getUserId());
|
||||||
workspaceMapper.insertSelective(workspace);
|
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 {
|
} else {
|
||||||
workspace.setUpdateTime(currentTime);
|
workspace.setUpdateTime(currentTime);
|
||||||
workspaceMapper.updateByPrimaryKeySelective(workspace);
|
workspaceMapper.updateByPrimaryKeySelective(workspace);
|
||||||
|
@ -260,6 +270,17 @@ public class WorkspaceService {
|
||||||
workspace.setUpdateTime(System.currentTimeMillis());
|
workspace.setUpdateTime(System.currentTimeMillis());
|
||||||
workspace.setCreateUser(SessionUtils.getUserId());
|
workspace.setCreateUser(SessionUtils.getUserId());
|
||||||
workspaceMapper.insertSelective(workspace);
|
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;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue