Skip to content

Commit

Permalink
Fix #6946: Prevent duplicate storage policy and group names
Browse files Browse the repository at this point in the history
  • Loading branch information
LEIYOUSU committed Oct 28, 2024
1 parent f81ce26 commit 5515dd8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ const modalTitle = props.group
const handleSave = async () => {
try {
isSubmitting.value = true;
const existingGroupsResponse =
await coreApiClient.storage.group.listGroup();
const existingGroups = existingGroupsResponse.data.items || [];
const nameExists = existingGroups.some(
(group) => group.spec.displayName === formState.value.spec.displayName
);
if (nameExists) {
alert("该分组名称已存在,请重新创建!");
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
Expand Up @@ -47,6 +47,14 @@ const formState = ref<Policy>({
const isUpdateMode = !!props.policy;
const { data: policies } = useQuery({
queryKey: ["core:attachment:policies"],
queryFn: async () => {
const { data } = await coreApiClient.storage.policy.listPolicy(); // 修改为 listPolicy
return data;
},
});
onMounted(async () => {
if (props.policy) {
formState.value = cloneDeep(props.policy);
Expand Down Expand Up @@ -135,6 +143,14 @@ const submitting = ref(false);
const handleSave = async () => {
try {
submitting.value = true;
const nameExists = policies.value?.items.some(
(policy) => policy.spec.displayName === formState.value.spec.displayName
);
if (nameExists) {
alert("该存储策略名称已存在,请重新创建!");
return;
}
const configMapToUpdate = convertToSave();
Expand Down

0 comments on commit 5515dd8

Please sign in to comment.