feat: add name existence check before creating attachment group and storage policy (#6959)

#### What type of PR is this?

/area ui
/kind improvement
/milestone 2.20.x

#### What this PR does / why we need it:

在创建附件分组或者存储策略时,支持检查是否有已存在的名称。

#### Which issue(s) this PR fixes:

Fixes #6946

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?

```release-note
在创建附件分组或者存储策略时,支持检查是否有已存在的名称。
```
pull/6972/head
Nancy 2024-10-30 11:30:38 +08:00 committed by GitHub
parent fdc90aff5c
commit 77548ec5a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 60 additions and 12 deletions

View File

@ -50,6 +50,16 @@ const handleSave = async () => {
group: formState.value, group: formState.value,
}); });
} else { } else {
const { data: groups } = await coreApiClient.storage.group.listGroup();
const hasDisplayNameDuplicate = groups.items.some(
(group) => group.spec.displayName === formState.value.spec.displayName
);
if (hasDisplayNameDuplicate) {
Toast.error(
t("core.attachment.group_editing_modal.toast.group_name_exists")
);
return;
}
await coreApiClient.storage.group.createGroup({ await coreApiClient.storage.group.createGroup({
group: formState.value, group: formState.value,
}); });

View File

@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import HasPermission from "@/components/permission/HasPermission.vue";
import type { Group } from "@halo-dev/api-client"; import type { Group } from "@halo-dev/api-client";
import { IconAddCircle } from "@halo-dev/components"; import { IconAddCircle } from "@halo-dev/components";
import { useQueryClient } from "@tanstack/vue-query"; import { useQueryClient } from "@tanstack/vue-query";
@ -25,7 +26,6 @@ const emit = defineEmits<{
}>(); }>();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const defaultGroups: Group[] = [ const defaultGroups: Group[] = [
{ {
spec: { spec: {

View File

@ -135,9 +135,7 @@ const submitting = ref(false);
const handleSave = async () => { const handleSave = async () => {
try { try {
submitting.value = true; submitting.value = true;
const configMapToUpdate = convertToSave(); const configMapToUpdate = convertToSave();
if (isUpdateMode) { if (isUpdateMode) {
await coreApiClient.configMap.updateConfigMap({ await coreApiClient.configMap.updateConfigMap({
name: configMap.value.metadata.name, name: configMap.value.metadata.name,
@ -149,6 +147,18 @@ const handleSave = async () => {
policy: formState.value, policy: formState.value,
}); });
} else { } else {
const { data: policies } =
await coreApiClient.storage.policy.listPolicy();
const hasDisplayNameDuplicate = policies.items.some(
(policy) => policy.spec.displayName === formState.value.spec.displayName
);
if (hasDisplayNameDuplicate) {
Toast.error(
t("core.attachment.policy_editing_modal.toast.policy_name_exists")
);
return;
}
const { data: newConfigMap } = const { data: newConfigMap } =
await coreApiClient.configMap.createConfigMap({ await coreApiClient.configMap.createConfigMap({
configMap: configMapToUpdate, configMap: configMapToUpdate,

View File

@ -41,7 +41,9 @@ onMounted(() => {
} }
}); });
const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => { const handleOpenCreateNewPolicyModal = async (
policyTemplate: PolicyTemplate
) => {
policyTemplateNameToCreate.value = policyTemplate.metadata.name; policyTemplateNameToCreate.value = policyTemplate.metadata.name;
policyEditingModal.value = true; policyEditingModal.value = true;
}; };
@ -143,7 +145,10 @@ const onGroupEditingModalClose = async () => {
@click="selectedGroupName = group.metadata.name" @click="selectedGroupName = group.metadata.name"
/> />
<AttachmentGroupBadge @click="handleOpenCreateNewGroupModal"> <AttachmentGroupBadge
:features="{ actions: false }"
@click="handleOpenCreateNewGroupModal"
>
<template #text> <template #text>
<span>{{ $t("core.common.buttons.new") }}</span> <span>{{ $t("core.common.buttons.new") }}</span>
</template> </template>

View File

@ -26,7 +26,9 @@ core:
logout: logout:
tooltip: Logout tooltip: Logout
title: Logout title: Logout
description: Clicking Confirm will redirect to the logout page. Please ensure that the content you are editing is saved. description: >-
Clicking Confirm will redirect to the logout page. Please ensure that
the content you are editing is saved.
profile: profile:
tooltip: Profile tooltip: Profile
visit_homepage: visit_homepage:
@ -598,6 +600,8 @@ core:
fields: fields:
display_name: display_name:
label: Display name label: Display name
toast:
group_name_exists: Group name already exists
group_list: group_list:
internal_groups: internal_groups:
all: All all: All
@ -643,6 +647,8 @@ core:
fields: fields:
display_name: display_name:
label: Display name label: Display name
toast:
policy_name_exists: Storage policy name already exists
upload_modal: upload_modal:
title: Upload attachment title: Upload attachment
filters: filters:
@ -666,8 +672,8 @@ core:
empty: empty:
title: There are no attachments. title: There are no attachments.
message: >- message: >-
There are no attachments, you can try refreshing or There are no attachments, you can try refreshing or uploading
uploading attachments. attachments.
actions: actions:
upload: Upload Attachment upload: Upload Attachment
filters: filters:
@ -1457,7 +1463,9 @@ core:
first: >- first: >-
1. The restore process may last for a long time, please do not refresh 1. The restore process may last for a long time, please do not refresh
the page during this period. the page during this period.
second: 2. Before performing the restore, all existing data will be cleared. Please ensure that there is no data that needs to be retained. second: >-
2. Before performing the restore, all existing data will be cleared.
Please ensure that there is no data that needs to be retained.
third: >- third: >-
3. After the restore is completed, you need to restart Halo to load 3. After the restore is completed, you need to restart Halo to load
the system resources normally. the system resources normally.
@ -1673,7 +1681,9 @@ core:
creation_label: Create {text} tag creation_label: Create {text} tag
validation: validation:
trim: Please remove the leading and trailing spaces trim: Please remove the leading and trailing spaces
password: "The password can only use uppercase and lowercase letters (A-Z, a-z), numbers (0-9), and the following special characters: !{'@'}#$%^&*" password: >-
The password can only use uppercase and lowercase letters (A-Z, a-z),
numbers (0-9), and the following special characters: !{'@'}#$%^&*
verification_form: verification_form:
no_action_defined: "{label} interface not defined" no_action_defined: "{label} interface not defined"
verify_success: "{label} successful" verify_success: "{label} successful"
@ -1791,7 +1801,10 @@ core:
editor_not_found: >- editor_not_found: >-
No editor found that matches the {raw_type} format. Please check if No editor found that matches the {raw_type} format. Please check if
the editor plugin has been installed. the editor plugin has been installed.
login_expired: The current session has expired. Click Confirm to go to the login page. Please ensure that the current content is saved. You can click Cancel to manually copy any unsaved content. login_expired: >-
The current session has expired. Click Confirm to go to the login
page. Please ensure that the current content is saved. You can click
Cancel to manually copy any unsaved content.
filters: filters:
results: results:
keyword: "Keyword: {keyword}" keyword: "Keyword: {keyword}"
@ -1832,7 +1845,9 @@ core:
title: Cancel publish title: Cancel publish
delete: delete:
title: Delete post title: Delete post
description: This action will move the post to the recycle bin, where it will be managed by the site administrator. description: >-
This action will move the post to the recycle bin, where it will be
managed by the site administrator.
publish_modal: publish_modal:
title: Publish post title: Publish post
setting_modal: setting_modal:

View File

@ -572,6 +572,8 @@ core:
fields: fields:
display_name: display_name:
label: 名称 label: 名称
toast:
group_name_exists: 分组名称已存在
group_list: group_list:
internal_groups: internal_groups:
all: 全部 all: 全部
@ -607,6 +609,8 @@ core:
fields: fields:
display_name: display_name:
label: 名称 label: 名称
toast:
policy_name_exists: 存储策略名称已存在
upload_modal: upload_modal:
title: 上传附件 title: 上传附件
filters: filters:

View File

@ -549,6 +549,8 @@ core:
fields: fields:
display_name: display_name:
label: 名稱 label: 名稱
toast:
group_name_exists: 分組名稱已存在
group_list: group_list:
internal_groups: internal_groups:
all: 全部 all: 全部
@ -584,6 +586,8 @@ core:
fields: fields:
display_name: display_name:
label: 名稱 label: 名稱
toast:
policy_name_exists: 儲存策略名稱已存在
upload_modal: upload_modal:
title: 上傳附件 title: 上傳附件
filters: filters: