diff --git a/backend/src/main/java/io/metersphere/service/OrganizationService.java b/backend/src/main/java/io/metersphere/service/OrganizationService.java index 2e981f3a3f..e1e57631c6 100644 --- a/backend/src/main/java/io/metersphere/service/OrganizationService.java +++ b/backend/src/main/java/io/metersphere/service/OrganizationService.java @@ -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; } diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index cdadc7c4e2..12cc29a404 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -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 returnList = projectMapper.selectByExample(example); - if(CollectionUtils.isEmpty(returnList)){ + if (CollectionUtils.isEmpty(returnList)) { return null; - }else { + } else { return returnList.get(0); } } diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index 3eccb9f95b..b76140eb79 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -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; }