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,
});
} 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({
group: formState.value,
});

View File

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

View File

@ -135,9 +135,7 @@ const submitting = ref(false);
const handleSave = async () => {
try {
submitting.value = true;
const configMapToUpdate = convertToSave();
if (isUpdateMode) {
await coreApiClient.configMap.updateConfigMap({
name: configMap.value.metadata.name,
@ -149,6 +147,18 @@ const handleSave = async () => {
policy: formState.value,
});
} 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 } =
await coreApiClient.configMap.createConfigMap({
configMap: configMapToUpdate,

View File

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

View File

@ -26,7 +26,9 @@ core:
logout:
tooltip: 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:
tooltip: Profile
visit_homepage:
@ -598,6 +600,8 @@ core:
fields:
display_name:
label: Display name
toast:
group_name_exists: Group name already exists
group_list:
internal_groups:
all: All
@ -643,6 +647,8 @@ core:
fields:
display_name:
label: Display name
toast:
policy_name_exists: Storage policy name already exists
upload_modal:
title: Upload attachment
filters:
@ -666,8 +672,8 @@ core:
empty:
title: There are no attachments.
message: >-
There are no attachments, you can try refreshing or
uploading attachments.
There are no attachments, you can try refreshing or uploading
attachments.
actions:
upload: Upload Attachment
filters:
@ -1457,7 +1463,9 @@ core:
first: >-
1. The restore process may last for a long time, please do not refresh
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: >-
3. After the restore is completed, you need to restart Halo to load
the system resources normally.
@ -1673,7 +1681,9 @@ core:
creation_label: Create {text} tag
validation:
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:
no_action_defined: "{label} interface not defined"
verify_success: "{label} successful"
@ -1791,7 +1801,10 @@ core:
editor_not_found: >-
No editor found that matches the {raw_type} format. Please check if
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:
results:
keyword: "Keyword: {keyword}"
@ -1832,7 +1845,9 @@ core:
title: Cancel publish
delete:
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:
title: Publish post
setting_modal:

View File

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

View File

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