diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index dc7246aa0a..b14ef7aa24 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -15,6 +15,7 @@ import io.metersphere.dto.OrganizationMemberDTO; import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserRoleDTO; import io.metersphere.dto.UserRoleHelpDTO; +import io.metersphere.i18n.Translator; import io.metersphere.user.SessionUser; import io.metersphere.user.SessionUtils; import org.apache.commons.lang3.StringUtils; @@ -22,7 +23,6 @@ import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; - import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @@ -54,11 +54,11 @@ public class UserService { private void checkUserParam(User user) { if (StringUtils.isBlank(user.getName())) { - MSException.throwException("user_name_empty"); + MSException.throwException(Translator.get("user_name_is_null")); } if (StringUtils.isBlank(user.getEmail())) { - MSException.throwException("user_email_empty"); + MSException.throwException(Translator.get("user_email_is_null")); } // password } @@ -76,7 +76,7 @@ public class UserService { criteria.andEmailEqualTo(user.getEmail()); List userList = userMapper.selectByExample(userExample); if (!CollectionUtils.isEmpty(userList)) { - MSException.throwException("user_email_is_exist"); + MSException.throwException(Translator.get("user_email_already_exists")); } userMapper.insertSelective(user); } @@ -128,107 +128,6 @@ public class UserService { userMapper.updateByPrimaryKeySelective(user); } - /*public List getUserRolesList(String userId) { - UserRoleExample userRoleExample = new UserRoleExample(); - userRoleExample.createCriteria().andUserIdEqualTo(userId); - List userRolesList = userRoleMapper.selectByExample(userRoleExample); - List roleIds = userRolesList.stream().map(UserRole::getRoleId).collect(Collectors.toList()); - RoleExample roleExample = new RoleExample(); - roleExample.createCriteria().andIdIn(roleIds); - return roleMapper.selectByExample(roleExample); - } - - public List getUserRoleList(String userId) { - if (StringUtils.isEmpty(userId)) { - return new ArrayList<>(); - } - return convertUserRoleDTO(extUserRoleMapper.getUserRoleHelpList(userId)); - }*/ - - private List convertUserRoleDTO(List helpDTOList) { - StringBuilder buffer = new StringBuilder(); - - Map roleMap = new HashMap<>(); - - List resultList = new ArrayList<>(); - - List otherList = new ArrayList<>(); - - Set orgSet = new HashSet<>(); - - Set workspaceSet = new HashSet<>(); - - for (UserRoleHelpDTO helpDTO : helpDTOList) { - UserRoleDTO userRoleDTO = roleMap.get(helpDTO.getSourceId()); - - if (userRoleDTO == null) { - userRoleDTO = new UserRoleDTO(); - - if (!StringUtils.isEmpty(helpDTO.getParentId())) { - workspaceSet.add(helpDTO.getParentId()); - userRoleDTO.setType("workspace"); - } else { - orgSet.add(helpDTO.getSourceId()); - userRoleDTO.setType("organization"); - } - - userRoleDTO.setId(helpDTO.getSourceId()); - userRoleDTO.setRoleId(helpDTO.getRoleId()); - userRoleDTO.setName(helpDTO.getSourceName()); - userRoleDTO.setParentId(helpDTO.getParentId()); - userRoleDTO.setDesc(helpDTO.getRoleName()); - - } else { - userRoleDTO.setDesc(userRoleDTO.getDesc() + "," + helpDTO.getRoleName()); - } - roleMap.put(helpDTO.getSourceId(), userRoleDTO); - } - - if (!StringUtils.isEmpty(buffer.toString())) { - UserRoleDTO dto = new UserRoleDTO(); - dto.setId("admin"); - dto.setType("admin"); - dto.setDesc(buffer.toString()); - resultList.add(dto); - } - - for (String org : orgSet) { - workspaceSet.remove(org); - } - - List orgWorkSpace = new ArrayList<>(roleMap.values()); - - if (!CollectionUtils.isEmpty(workspaceSet)) { - for (String orgId : workspaceSet) { - Organization organization = organizationMapper.selectByPrimaryKey(orgId); - if (organization != null) { - UserRoleDTO dto = new UserRoleDTO(); - dto.setId(orgId); - dto.setName(organization.getName()); - dto.setSwitchable(false); - dto.setType("organization"); - orgWorkSpace.add(dto); - } - } - } - - orgWorkSpace.sort((o1, o2) -> { - if (o1.getParentId() == null) { - return -1; - } - - if (o2.getParentId() == null) { - return 1; - } - - return o1.getParentId().compareTo(o2.getParentId()); - }); - resultList.addAll(orgWorkSpace); - resultList.addAll(otherList); - - return resultList; - } - public void switchUserRole(UserDTO user, String sign, String sourceId) { User newUser = new User(); if (StringUtils.equals("organization", sign)) { @@ -325,20 +224,16 @@ public class UserService { public boolean checkUserPassword(String userId, String password) { if (StringUtils.isBlank(userId)) { - MSException.throwException("Username cannot be null"); + MSException.throwException(Translator.get("user_name_is_null")); } if (StringUtils.isBlank(password)) { - MSException.throwException("Password cannot be null"); + MSException.throwException(Translator.get("password_is_null")); } UserExample example = new UserExample(); example.createCriteria().andIdEqualTo(userId).andPasswordEqualTo(CodingUtil.md5(password)); return userMapper.countByExample(example) > 0; } - public List getOrganizationMemberDTO(QueryOrgMemberRequest request) { - return extUserRoleMapper.getOrganizationMemberDTO(request); - } - /** * 查询该组织外的其他用户列表 */ diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index 7956a9f90c..79b1c1c894 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; @@ -59,9 +58,9 @@ public class WorkspaceService { if (workspaceMapper.countByExample(example) > 0) { MSException.throwException(Translator.get("workspace_name_already_exists")); } - workspace.setId(UUID.randomUUID().toString()); // 设置ID + workspace.setId(UUID.randomUUID().toString()); workspace.setCreateTime(currentTime); - workspace.setUpdateTime(currentTime); // 首次 update time + workspace.setUpdateTime(currentTime); workspaceMapper.insertSelective(workspace); } else { workspace.setUpdateTime(currentTime); @@ -112,19 +111,6 @@ public class WorkspaceService { } } - public void checkWorkspaceOwnerByTestManager(String workspaceId) { - checkWorkspaceIsExist(workspaceId); - SessionUser user = SessionUtils.getUser(); - List wsIds = user.getUserRoles().stream() - .filter(ur -> RoleConstants.TEST_MANAGER.equals(ur.getRoleId())) - .map(UserRole::getSourceId) - .collect(Collectors.toList()); - boolean contains = wsIds.contains(workspaceId); - if (!contains) { - MSException.throwException(Translator.get("workspace_does_not_belong_to_user")); - } - } - public void checkWorkspaceOwner(String workspaceId) { checkWorkspaceIsExist(workspaceId); WorkspaceExample example = new WorkspaceExample(); @@ -150,7 +136,7 @@ public class WorkspaceService { WorkspaceExample example = new WorkspaceExample(); example.createCriteria().andIdEqualTo(workspaceId); if (workspaceMapper.countByExample(example) == 0) { - MSException.throwException("workspace_not_exist"); + MSException.throwException(Translator.get("workspace_not_exists")); } } diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 97c25ebe9c..5dcf8e7cb9 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -23,4 +23,9 @@ max_thread_insufficient=The number of concurrent users exceeds cannot_edit_load_test_running=Cannot modify the running test test_not_found=Test cannot be found: test_not_running=Test is not running -before_delete_plan=There is an associated test case under this plan, please unlink it first! \ No newline at end of file +before_delete_plan=There is an associated test case under this plan, please unlink it first! +user_email_already_exists=User email already exists +user_name_is_null=User name cannot be null +user_email_is_null=User email cannot be null +password_is_null=Password cannot be null +workspace_not_exists=Workspace is not exists \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 150bd0d446..4203e0043e 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -23,4 +23,9 @@ max_thread_insufficient=并发用户数超额 cannot_edit_load_test_running=不能修改正在运行的测试 test_not_found=测试不存在: test_not_running=测试未运行 -before_delete_plan=该计划下存在关联测试用例,请先取消关联! \ No newline at end of file +before_delete_plan=该计划下存在关联测试用例,请先取消关联! +user_email_already_exists=用户邮箱已存在 +user_name_is_null=用户名不能为空 +user_email_is_null=用户邮箱不能为空 +password_is_null=密码不能为空 +workspace_not_exists=工作空间不存在 \ No newline at end of file