diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index 5b9281419a7b8851f871cb2d1bab63d0866f509a..72128457d153e377810746221fba043367f551a6 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -230,6 +230,19 @@ public class WorkspaceService { } public void addWorkspaceByAdmin(Workspace workspace) { + if (StringUtils.isBlank(workspace.getName())) { + MSException.throwException(Translator.get("workspace_name_is_null")); + } + if (StringUtils.isBlank(workspace.getOrganizationId())) { + MSException.throwException(Translator.get("organization_id_is_null")); + } + WorkspaceExample example = new WorkspaceExample(); + example.createCriteria() + .andOrganizationIdEqualTo(workspace.getOrganizationId()) + .andNameEqualTo(workspace.getName()); + 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()); diff --git a/backend/src/main/resources/i18n/en-US.json b/backend/src/main/resources/i18n/en-US.json index c8ad2464fdcf3eefe6b447bf643d478ce7875997..b88c7427250f8092ba2976cf2c0aa8ce072ba5be 100644 --- a/backend/src/main/resources/i18n/en-US.json +++ b/backend/src/main/resources/i18n/en-US.json @@ -17,5 +17,6 @@ "node_deep_limit": "The node depth does not exceed 5 layers!", "no_nodes_message": "No node message", "duplicate_node_ip": "Duplicate IPs", - "only_one_k8s": "Only one K8s can be added" + "only_one_k8s": "Only one K8s can be added", + "organization_id_is_null": "Organization ID cannot be null" } \ No newline at end of file diff --git a/backend/src/main/resources/i18n/zh-CN.json b/backend/src/main/resources/i18n/zh-CN.json index 3a1b0f7255d55b027fe5ad9f0aeb101b3671882e..56352f221adb3740eddac5b939f9da5a976ff91e 100644 --- a/backend/src/main/resources/i18n/zh-CN.json +++ b/backend/src/main/resources/i18n/zh-CN.json @@ -17,5 +17,6 @@ "node_deep_limit": "节点深度不超过5层!", "no_nodes_message": "没有节点信息", "duplicate_node_ip": "节点 IP 重复", - "only_one_k8s": "只能添加一个 K8s" + "only_one_k8s": "只能添加一个 K8s", + "organization_id_is_null": "组织 ID 不能为空" } \ No newline at end of file