aops-hermes/0001-Modify-host-group-input-parameter-verification.patch

194 lines
7.1 KiB
Diff

From 1e59894bd65c00ecc8d7b546b034df40c79c6494 Mon Sep 17 00:00:00 2001
From: Hu Gang <18768366022@163.com>
Date: Wed, 27 Nov 2024 11:25:40 +0800
Subject: [PATCH] Modify host group input parameter verification
---
.eslintignore | 1 +
.eslintrc.js | 3 ++
src/locales/lang/en.json | 4 +-
src/locales/lang/zh-cn.json | 4 +-
.../assests/components/AddHostGroupModal.vue | 41 ++++++++-----------
src/views/execution/Scripts.vue | 8 +++-
6 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/.eslintignore b/.eslintignore
index 2b26093..b33de94 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -4,3 +4,4 @@ package.json
.vscode
.idea
+.eslintrc.js
diff --git a/.eslintrc.js b/.eslintrc.js
index c83a20c..5942158 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -32,5 +32,8 @@ module.exports = {
indent: ["error", 2],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-expressions": 'off',
+ "vue/valid-define-props": "off",
+ "vue/valid-define-emits": "off",
+ "vue/multi-word-component-names": "off"
},
}
diff --git a/src/locales/lang/en.json b/src/locales/lang/en.json
index 4440bbe..a9f9f06 100644
--- a/src/locales/lang/en.json
+++ b/src/locales/lang/en.json
@@ -138,9 +138,9 @@
"descriptionTwo": "There cannot be a >< symbol",
"hostGroup": "Please select the host group",
"hostGroup_input": "Please enter a host group name",
- "hostGroup_one": "It must start with a lowercase letter and cannot end with an underscore.",
+ "hostGroup_one": "The host group name must start with a lowercase letter and not end with an underscore.",
"hostGroup_three": "The name should consist of numbers, lowercase letters, and underscores.",
- "hostGroup_two": "It must start with a lowercase letter and cannot end with an underscore.",
+ "hostGroup_two": "The host group name should be less than 20 characters long.",
"hostName": "The host name length should be less than 50",
"hostName_one": "No leading or trailing spaces are allowed",
"hostName_two": "No full spaces allowed",
diff --git a/src/locales/lang/zh-cn.json b/src/locales/lang/zh-cn.json
index e8d58d5..207110f 100644
--- a/src/locales/lang/zh-cn.json
+++ b/src/locales/lang/zh-cn.json
@@ -138,9 +138,9 @@
"descriptionTwo": "不能有><符号",
"hostGroup": "请选择所属主机组",
"hostGroup_input": "请输入主机组名称",
- "hostGroup_one": "以小写字母开头,且结尾不能是英文下划线",
+ "hostGroup_one": "主机组名称以小写字母开头,且不以英文下划线结尾",
"hostGroup_three": "名称应由数字、小写字母、英文下划线组成",
- "hostGroup_two": "以小写字母开头,且结尾不能是英文下划线",
+ "hostGroup_two": "主机组名称长度应小于20",
"hostName": "主机名长度应小于50",
"hostName_one": "首尾不允许空格",
"hostName_two": "不允许全空格",
diff --git a/src/views/assests/components/AddHostGroupModal.vue b/src/views/assests/components/AddHostGroupModal.vue
index 205e904..ecac117 100644
--- a/src/views/assests/components/AddHostGroupModal.vue
+++ b/src/views/assests/components/AddHostGroupModal.vue
@@ -44,12 +44,15 @@ const form = reactive<Form>({
* @param value
*/
function validateGroupName(_rule: Rule, value: string) {
- if (/[^0-9a-z_]/.test(value))
- return Promise.reject(new Error(t('assests.validateMsg.hostGroup_one')))
- if (/^[^a-z]/.test(value))
+ if (!value) {
+ return Promise.resolve()
+ }
+ if (value.length > 20) {
return Promise.reject(new Error(t('assests.validateMsg.hostGroup_two')))
- if (value.endsWith('_'))
- return Promise.reject(new Error(t('assests.validateMsg.hostGroup_three')))
+ }
+ if (!/^[a-z](?:[^\n]{0,18})(?<!_)$/.test(value)) {
+ return Promise.reject(new Error(t('assests.validateMsg.hostGroup_one')))
+ }
return Promise.resolve()
}
@@ -59,10 +62,8 @@ function validateGroupName(_rule: Rule, value: string) {
* @param value
*/
function validateDesc(_rule: Rule, value: string) {
- if (value.length > 60)
- return Promise.reject(new Error(t('assests.validateMsg.descriptionOne')))
- if (/[<>]/.test(value))
- return Promise.reject(new Error(t('assests.validateMsg.descriptionTwo')))
+ if (value.length > 60) return Promise.reject(new Error(t('assests.validateMsg.descriptionOne')))
+ if (/[<>]/.test(value)) return Promise.reject(new Error(t('assests.validateMsg.descriptionTwo')))
return Promise.resolve()
}
@@ -74,10 +75,7 @@ async function addNewHostGroup() {
try {
await formRef.value.validate()
- const params: Record<
- string,
- { host_group_name: string, description: string, cluster_id: string }
- > = {}
+ const params: Record<string, { host_group_name: string; description: string; cluster_id: string }> = {}
params[form.cluster_id!] = {
description: form.desc,
host_group_name: form.hostName,
@@ -91,19 +89,16 @@ async function addNewHostGroup() {
message: t('common.fail'),
description: Object.values(res)[0].label,
})
- }
- else {
+ } else {
message.success(t('common.succeed'))
}
visible.value = false
emits('success')
formRef.value.resetFields()
}
- }
- catch {
+ } catch {
isLoading.value = false
- }
- finally {
+ } finally {
isLoading.value = false
}
}
@@ -139,9 +134,7 @@ function handleClose() {
<a-select v-model:value="form.cluster_id" :placeholder="t('assests.placeHolder.cluster')">
<template v-for="cluster in clusters" :key="cluster.cluster_id">
<a-select-option :value="cluster.cluster_id">
- {{
- cluster.cluster_name
- }}
+ {{ cluster.cluster_name }}
</a-select-option>
</template>
</a-select>
@@ -164,9 +157,7 @@ function handleClose() {
:placeholder="t('assests.placeHolder.hostGroupInput')"
>
<template #suffix>
- <a-tooltip
- :title="$t('assests.tips.hostGroupName')"
- >
+ <a-tooltip :title="$t('assests.tips.hostGroupName')">
<InfoCircleOutlined style="color: rgba(0, 0, 0, 0.45)" />
</a-tooltip>
</template>
diff --git a/src/views/execution/Scripts.vue b/src/views/execution/Scripts.vue
index ae98301..00959f7 100644
--- a/src/views/execution/Scripts.vue
+++ b/src/views/execution/Scripts.vue
@@ -108,6 +108,11 @@ function handleRefresh() {
getScripts()
}
+function handleNewScriptCanceled() {
+ tableState.selectedScriptId = ''
+ isModalVisible.value = false
+}
+
onMounted(() => {
getScripts()
})
@@ -168,9 +173,8 @@ onMounted(() => {
:visible="isModalVisible"
:script-id="tableState.selectedScriptId"
@success="handleSuccess"
- @cancel="isModalVisible = false"
+ @cancel="handleNewScriptCanceled"
/>
</template>
<style scoped></style>
-
--
2.33.0