feat: disallow deletion of system-protected attachment policies (#6735)

#### What type of PR is this?

/area core
/kind improvement
/milestone 2.20.x

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

为系统默认的存储策略添加保护措施,不允许删除。

<img width="893" alt="image" src="https://github.com/user-attachments/assets/990f834f-3d97-4ee8-9c24-01cc188b7be6">


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

```release-note
为系统默认的存储策略添加保护措施,不允许删除。
```
pull/6766/head
Ryan Wang 2024-10-04 22:10:44 +08:00 committed by GitHub
parent 4dd5b7e103
commit 8896e16615
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 2 deletions

View File

@ -10,6 +10,8 @@ apiVersion: storage.halo.run/v1alpha1
kind: Policy kind: Policy
metadata: metadata:
name: default-policy name: default-policy
finalizers:
- system-protection
spec: spec:
displayName: 本地存储 displayName: 本地存储
templateName: local templateName: local

View File

@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { SYSTEM_PROTECTION } from "@/constants/finalizers";
import { formatDatetime } from "@/utils/date"; import { formatDatetime } from "@/utils/date";
import type { Policy, PolicyTemplate } from "@halo-dev/api-client"; import type { Policy, PolicyTemplate } from "@halo-dev/api-client";
import { consoleApiClient, coreApiClient } from "@halo-dev/api-client"; import { consoleApiClient, coreApiClient } from "@halo-dev/api-client";
@ -15,6 +16,7 @@ import {
VModal, VModal,
VSpace, VSpace,
VStatusDot, VStatusDot,
VTag,
} from "@halo-dev/components"; } from "@halo-dev/components";
import { ref } from "vue"; import { ref } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
@ -171,6 +173,14 @@ function getPolicyTemplateDisplayName(templateName: string) {
></VEntityField> ></VEntityField>
</template> </template>
<template #end> <template #end>
<VEntityField>
<template
v-if="policy.metadata.finalizers?.includes(SYSTEM_PROTECTION)"
#description
>
<VTag>{{ $t("core.common.text.system_protection") }}</VTag>
</template>
</VEntityField>
<VEntityField v-if="policy.metadata.deletionTimestamp"> <VEntityField v-if="policy.metadata.deletionTimestamp">
<template #description> <template #description>
<VStatusDot <VStatusDot
@ -189,10 +199,21 @@ function getPolicyTemplateDisplayName(templateName: string) {
</VEntityField> </VEntityField>
</template> </template>
<template #dropdownItems> <template #dropdownItems>
<VDropdownItem @click="handleOpenEditingModal(policy)"> <VDropdownItem
:disabled="
policy.metadata.finalizers?.includes(SYSTEM_PROTECTION)
"
@click="handleOpenEditingModal(policy)"
>
{{ $t("core.common.buttons.edit") }} {{ $t("core.common.buttons.edit") }}
</VDropdownItem> </VDropdownItem>
<VDropdownItem type="danger" @click="handleDelete(policy)"> <VDropdownItem
:disabled="
policy.metadata.finalizers?.includes(SYSTEM_PROTECTION)
"
type="danger"
@click="handleDelete(policy)"
>
{{ $t("core.common.buttons.delete") }} {{ $t("core.common.buttons.delete") }}
</VDropdownItem> </VDropdownItem>
</template> </template>

View File

@ -0,0 +1 @@
export const SYSTEM_PROTECTION = "system-protection";

View File

@ -1779,6 +1779,7 @@ core:
none: None none: None
tip: Tip tip: Tip
warning: Warning warning: Warning
system_protection: System protection
tooltips: tooltips:
unpublished_content_tip: There is content that has been saved but not yet published. unpublished_content_tip: There is content that has been saved but not yet published.
publishing: Publishing publishing: Publishing

View File

@ -1664,6 +1664,7 @@ core:
none: none:
tip: 提示 tip: 提示
warning: 警告 warning: 警告
system_protection: 系统保留
tooltips: tooltips:
unpublished_content_tip: 当前有内容已保存,但还未发布。 unpublished_content_tip: 当前有内容已保存,但还未发布。
publishing: 发布中 publishing: 发布中

View File

@ -1645,6 +1645,7 @@ core:
none: none:
tip: 提示 tip: 提示
warning: 警告 warning: 警告
system_protection: 系統保留
tooltips: tooltips:
unpublished_content_tip: 當前有內容已保存,但還未發布。 unpublished_content_tip: 當前有內容已保存,但還未發布。
publishing: 發布中 publishing: 發布中