diff --git a/backend/src/main/java/io/metersphere/service/OrganizationService.java b/backend/src/main/java/io/metersphere/service/OrganizationService.java index 5ec81898ff..0a5be48d04 100644 --- a/backend/src/main/java/io/metersphere/service/OrganizationService.java +++ b/backend/src/main/java/io/metersphere/service/OrganizationService.java @@ -48,6 +48,7 @@ public class OrganizationService { private UserService userService; public Organization addOrganization(Organization organization) { + checkOrgNameRepeat(organization); long currentTimeMillis = System.currentTimeMillis(); organization.setId(UUID.randomUUID().toString()); organization.setCreateTime(currentTimeMillis); @@ -65,6 +66,17 @@ public class OrganizationService { return organizationMapper.selectByExample(example); } + private void checkOrgNameRepeat(Organization organization) { + if (StringUtils.isBlank(organization.getName())) { + MSException.throwException(Translator.get("organization_name_is_null")); + } + OrganizationExample organizationExample = new OrganizationExample(); + organizationExample.createCriteria().andNameEqualTo(organization.getName()); + if (organizationMapper.countByExample(organizationExample) > 0) { + MSException.throwException(Translator.get("organization_name_already_exists")); + } + } + public void deleteOrganization(String organizationId) { WorkspaceExample example = new WorkspaceExample(); WorkspaceExample.Criteria criteria = example.createCriteria(); @@ -87,6 +99,7 @@ public class OrganizationService { } public void updateOrganization(Organization organization) { + checkOrgNameRepeat(organization); organization.setCreateTime(null); organization.setUpdateTime(System.currentTimeMillis()); organizationMapper.updateByPrimaryKeySelective(organization); diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index 214a244fe9..9cd4c05719 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -58,14 +58,16 @@ public class WorkspaceService { workspace.setOrganizationId(SessionUtils.getCurrentOrganizationId()); long currentTime = System.currentTimeMillis(); + + WorkspaceExample example = new WorkspaceExample(); + example.createCriteria() + .andOrganizationIdEqualTo(SessionUtils.getCurrentOrganizationId()) + .andNameEqualTo(workspace.getName()); + if (workspaceMapper.countByExample(example) > 0) { + MSException.throwException(Translator.get("workspace_name_already_exists")); + } + if (StringUtils.isBlank(workspace.getId())) { - WorkspaceExample example = new WorkspaceExample(); - example.createCriteria() - .andOrganizationIdEqualTo(SessionUtils.getCurrentOrganizationId()) - .andNameEqualTo(workspace.getName()); - if (workspaceMapper.countByExample(example) > 0) { - MSException.throwException(Translator.get("workspace_name_already_exists")); - } workspace.setId(UUID.randomUUID().toString()); workspace.setCreateTime(currentTime); workspace.setUpdateTime(currentTime); @@ -235,12 +237,21 @@ public class WorkspaceService { } public void updateWorkspaceByAdmin(Workspace workspace) { + checkWorkspace(workspace); workspace.setCreateTime(null); workspace.setUpdateTime(System.currentTimeMillis()); workspaceMapper.updateByPrimaryKeySelective(workspace); } public void addWorkspaceByAdmin(Workspace workspace) { + checkWorkspace(workspace); + workspace.setId(UUID.randomUUID().toString()); + workspace.setCreateTime(System.currentTimeMillis()); + workspace.setUpdateTime(System.currentTimeMillis()); + workspaceMapper.insertSelective(workspace); + } + + private void checkWorkspace(Workspace workspace) { if (StringUtils.isBlank(workspace.getName())) { MSException.throwException(Translator.get("workspace_name_is_null")); } @@ -254,9 +265,5 @@ public class WorkspaceService { if (workspaceMapper.countByExample(example) > 0) { MSException.throwException(Translator.get("workspace_name_already_exists")); } - workspace.setId(UUID.randomUUID().toString()); - workspace.setCreateTime(System.currentTimeMillis()); - workspace.setUpdateTime(System.currentTimeMillis()); - workspaceMapper.insertSelective(workspace); } } diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index d6355bf12e..458d0856ad 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -33,6 +33,8 @@ workspace_not_exists=Workspace is not exists project_name_is_null=Project name cannot be null project_name_already_exists=The project name already exists #organization +organization_name_is_null=organization name cannot be null +organization_name_already_exists=The organization name already exists organization_does_not_belong_to_user=The current organization does not belong to the current user organization_id_is_null=Organization ID cannot be null #api diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index a991a24075..b901e7da93 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -33,6 +33,8 @@ workspace_not_exists=工作空间不存在 project_name_is_null=项目名称不能为空 project_name_already_exists=项目名称已存在 #organization +organization_name_is_null=组织名不能为空 +organization_name_already_exists=组织名已存在 organization_does_not_belong_to_user=当前组织不属于当前用户 organization_id_is_null=组织 ID 不能为空 #api diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 922dbb0c10..123329744a 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -33,6 +33,8 @@ workspace_not_exists=工作空間不存在 project_name_is_null=項目名稱不能為空 project_name_already_exists=項目名稱已存在 #organization +organization_name_is_null=組織名不能為空 +organization_name_already_exists=組織名已存在 organization_does_not_belong_to_user=當前組織不屬於當前用戶 organization_id_is_null=組織 ID 不能為空 #api