Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -25,7 +26,6 @@ const emit = defineEmits<{
}>();

const queryClient = useQueryClient();

const defaultGroups: Group[] = [
{
spec: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ onMounted(() => {
}
});

const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
const handleOpenCreateNewPolicyModal = async (
policyTemplate: PolicyTemplate
) => {
policyTemplateNameToCreate.value = policyTemplate.metadata.name;
policyEditingModal.value = true;
};
Expand Down Expand Up @@ -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>
Expand Down
29 changes: 22 additions & 7 deletions ui/src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions ui/src/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ core:
fields:
display_name:
label: 名称
toast:
group_name_exists: 分组名称已存在
group_list:
internal_groups:
all: 全部
Expand Down Expand Up @@ -607,6 +609,8 @@ core:
fields:
display_name:
label: 名称
toast:
policy_name_exists: 存储策略名称已存在
upload_modal:
title: 上传附件
filters:
Expand Down
4 changes: 4 additions & 0 deletions ui/src/locales/zh-TW.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ core:
fields:
display_name:
label: 名稱
toast:
group_name_exists: 分組名稱已存在
group_list:
internal_groups:
all: 全部
Expand Down Expand Up @@ -584,6 +586,8 @@ core:
fields:
display_name:
label: 名稱
toast:
policy_name_exists: 儲存策略名稱已存在
upload_modal:
title: 上傳附件
filters:
Expand Down
Loading