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 7 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 @@ -11,9 +11,11 @@ import { useI18n } from "vue-i18n";
const props = withDefaults(
defineProps<{
group?: Group;
isNew?: boolean;
}>(),
{
group: undefined,
isNew: false,
ruibaby marked this conversation as resolved.
Show resolved Hide resolved
}
);

Expand Down Expand Up @@ -44,6 +46,19 @@ const modalTitle = props.group
const handleSave = async () => {
try {
isSubmitting.value = true;
if (props.isNew) {
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;
}
}

if (props.group) {
await coreApiClient.storage.group.updateGroup({
name: formState.value.metadata.name,
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,7 @@ const emit = defineEmits<{
}>();

const queryClient = useQueryClient();

const isNewGroup = ref(false);
const defaultGroups: Group[] = [
{
spec: {
Expand Down Expand Up @@ -67,10 +68,16 @@ const onCreationModalClose = () => {
queryClient.invalidateQueries({ queryKey: ["attachment-groups"] });
creationModalVisible.value = false;
};

const handleBadgeClick = () => {
creationModalVisible.value = true;
isNewGroup.value = true;
};
</script>
<template>
<AttachmentGroupEditingModal
v-if="!readonly && creationModalVisible"
:is-new="isNewGroup"
@close="onCreationModalClose"
/>
<div
Expand Down Expand Up @@ -100,7 +107,7 @@ const onCreationModalClose = () => {
>
<AttachmentGroupBadge
:features="{ actions: false }"
@click="creationModalVisible = true"
@click="handleBadgeClick"
>
<template #text>
<span>{{ $t("core.common.buttons.new") }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ const selectedPolicy = ref<Policy>();
const selectedTemplateName = ref();

const policyEditingModal = ref(false);
const isNewPolicy = ref(false);

const handleOpenEditingModal = (policy: Policy) => {
selectedPolicy.value = policy;
isNewPolicy.value = false;
policyEditingModal.value = true;
};

const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
selectedTemplateName.value = policyTemplate.metadata.name;
isNewPolicy.value = true;
policyEditingModal.value = true;
};

Expand Down Expand Up @@ -231,6 +234,7 @@ function getPolicyTemplateDisplayName(templateName: string) {
v-if="policyEditingModal"
:policy="selectedPolicy"
:template-name="selectedTemplateName"
:is-new="isNewPolicy"
@close="onEditingModalClose"
/>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const props = withDefaults(
defineProps<{
policy?: Policy;
templateName?: string;
isNew?: boolean;
ruibaby marked this conversation as resolved.
Show resolved Hide resolved
}>(),
{
policy: undefined,
templateName: undefined,
isNew: false,
}
);

Expand Down Expand Up @@ -135,7 +137,20 @@ const submitting = ref(false);
const handleSave = async () => {
try {
submitting.value = true;

if (props.isNew) {
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 configMapToUpdate = convertToSave();

if (isUpdateMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const selectedGroupName = useLocalStorage("attachment-upload-group", "");
const selectedPolicyName = useLocalStorage("attachment-upload-policy", "");
const policyEditingModal = ref(false);
const groupEditingModal = ref(false);
const isNewPolicy = ref(false);
const isNewGroup = ref(false);
const policyTemplateNameToCreate = ref();

onMounted(() => {
Expand All @@ -41,12 +43,16 @@ onMounted(() => {
}
});

const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
const handleOpenCreateNewPolicyModal = async (
policyTemplate: PolicyTemplate
) => {
policyTemplateNameToCreate.value = policyTemplate.metadata.name;
isNewPolicy.value = true;
policyEditingModal.value = true;
};

const handleOpenCreateNewGroupModal = () => {
isNewGroup.value = true;
groupEditingModal.value = true;
};

Expand Down Expand Up @@ -143,7 +149,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 Expand Up @@ -174,11 +183,13 @@ const onGroupEditingModalClose = async () => {
<AttachmentPolicyEditingModal
v-if="policyEditingModal"
:template-name="policyTemplateNameToCreate"
:is-new="isNewPolicy"
@close="onEditingModalClose"
/>

<AttachmentGroupEditingModal
v-if="groupEditingModal"
:is-new="isNewGroup"
@close="onGroupEditingModalClose"
/>
</template>
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