2022-05-30 14:38:57 +00:00
|
|
|
|
<script lang="ts" setup>
|
2022-06-14 07:56:55 +00:00
|
|
|
|
import {
|
|
|
|
|
IconShieldUser,
|
|
|
|
|
VButton,
|
|
|
|
|
VCard,
|
|
|
|
|
VPageHeader,
|
|
|
|
|
VTabbar,
|
|
|
|
|
VTag,
|
2022-12-07 04:40:53 +00:00
|
|
|
|
VAlert,
|
2023-04-23 02:49:32 +00:00
|
|
|
|
VDescription,
|
|
|
|
|
VDescriptionItem,
|
2022-06-14 07:56:55 +00:00
|
|
|
|
} from "@halo-dev/components";
|
2022-07-26 12:21:11 +00:00
|
|
|
|
import { useRoute } from "vue-router";
|
2024-01-24 02:34:11 +00:00
|
|
|
|
import { computed, ref, watch } from "vue";
|
2022-09-22 08:46:32 +00:00
|
|
|
|
import { apiClient } from "@/utils/api-client";
|
2022-12-07 04:40:53 +00:00
|
|
|
|
import { pluginLabels, roleLabels } from "@/constants/labels";
|
2022-07-20 14:47:10 +00:00
|
|
|
|
import { rbacAnnotations } from "@/constants/annotations";
|
2023-11-13 08:56:08 +00:00
|
|
|
|
import { useRoleForm, useRoleTemplateSelection } from "@/composables/use-role";
|
2022-12-07 04:40:53 +00:00
|
|
|
|
import { SUPER_ROLE_NAME } from "@/constants/constants";
|
2023-03-23 08:54:33 +00:00
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
|
import { formatDatetime } from "@/utils/date";
|
2023-09-25 03:30:14 +00:00
|
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
2024-01-24 02:34:11 +00:00
|
|
|
|
import type { Role } from "packages/api-client/dist";
|
|
|
|
|
import { resolveDeepDependencies } from "@/utils/role";
|
2022-07-04 11:28:53 +00:00
|
|
|
|
|
2022-05-30 14:38:57 +00:00
|
|
|
|
const route = useRoute();
|
2023-03-23 08:54:33 +00:00
|
|
|
|
const { t } = useI18n();
|
2022-05-30 14:38:57 +00:00
|
|
|
|
|
2022-07-26 12:21:11 +00:00
|
|
|
|
const tabActiveId = ref("detail");
|
2022-07-04 11:28:53 +00:00
|
|
|
|
|
2023-09-25 03:30:14 +00:00
|
|
|
|
const { data: roleTemplates } = useQuery({
|
|
|
|
|
queryKey: ["role-templates"],
|
|
|
|
|
queryFn: async () => {
|
2024-05-24 04:04:50 +00:00
|
|
|
|
const { data } = await apiClient.extension.role.listV1alpha1Role({
|
2023-09-25 03:30:14 +00:00
|
|
|
|
page: 0,
|
|
|
|
|
size: 0,
|
|
|
|
|
labelSelector: [`${roleLabels.TEMPLATE}=true`, "!halo.run/hidden"],
|
|
|
|
|
});
|
|
|
|
|
return data.items;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2022-07-26 10:04:51 +00:00
|
|
|
|
const { roleTemplateGroups, handleRoleTemplateSelect, selectedRoleTemplates } =
|
2023-09-25 03:30:14 +00:00
|
|
|
|
useRoleTemplateSelection(roleTemplates);
|
2022-05-30 14:38:57 +00:00
|
|
|
|
|
2022-07-26 12:21:11 +00:00
|
|
|
|
const { formState, saving, handleCreateOrUpdate } = useRoleForm();
|
|
|
|
|
|
2022-12-07 04:40:53 +00:00
|
|
|
|
const isSystemReserved = computed(() => {
|
|
|
|
|
return (
|
|
|
|
|
formState.value.metadata.labels?.[roleLabels.SYSTEM_RESERVED] === "true"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const isSuperRole = computed(() => {
|
|
|
|
|
return formState.value.metadata.name === SUPER_ROLE_NAME;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const getRoleCountText = computed(() => {
|
|
|
|
|
if (formState.value.metadata.name === SUPER_ROLE_NAME) {
|
2023-03-23 08:54:33 +00:00
|
|
|
|
return t("core.role.common.text.contains_all_permissions");
|
2022-12-07 04:40:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 02:34:11 +00:00
|
|
|
|
const dependencies = new Set<string>(
|
|
|
|
|
resolveDeepDependencies(formState.value, roleTemplates.value || [])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
console.log(dependencies);
|
2022-12-07 04:40:53 +00:00
|
|
|
|
|
2023-03-23 08:54:33 +00:00
|
|
|
|
return t("core.role.common.text.contains_n_permissions", {
|
2024-01-24 02:34:11 +00:00
|
|
|
|
count: dependencies.size || 0,
|
2023-03-23 08:54:33 +00:00
|
|
|
|
});
|
2022-12-07 04:40:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
2022-07-26 12:21:11 +00:00
|
|
|
|
watch(
|
|
|
|
|
() => selectedRoleTemplates.value,
|
|
|
|
|
(newValue) => {
|
|
|
|
|
if (formState.value.metadata.annotations) {
|
|
|
|
|
formState.value.metadata.annotations[rbacAnnotations.DEPENDENCIES] =
|
|
|
|
|
JSON.stringify(Array.from(newValue));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2024-01-24 02:34:11 +00:00
|
|
|
|
const { refetch } = useQuery<Role>({
|
|
|
|
|
queryKey: ["role", route.params.name],
|
|
|
|
|
queryFn: async () => {
|
2024-05-24 04:04:50 +00:00
|
|
|
|
const { data } = await apiClient.extension.role.getV1alpha1Role({
|
refactor: method parameters of api client (halo-dev/console#605)
<!-- Thanks for sending a pull request! Here are some tips for you:
1. 如果这是你的第一次,请阅读我们的贡献指南:<https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>。
1. If this is your first time, please read our contributor guidelines: <https://github.com/halo-dev/halo/blob/master/CONTRIBUTING.md>.
2. 请根据你解决问题的类型为 Pull Request 添加合适的标签。
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request.
3. 请确保你已经添加并运行了适当的测试。
3. Ensure you have added or ran the appropriate tests for your PR.
-->
#### What type of PR is this?
/kind improvement
/milestone 2.0
<!--
添加其中一个类别:
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind optimization
适当添加其中一个或多个类别(可选):
Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->
#### What this PR does / why we need it:
修改 api-client 的请求参数结构,改为所有参数由一个对象包裹,而不是将各个参数作为方法的参数,防止因为后端参数结构发生改变,或者生成 api-client 时参数顺序发生改变导致请求异常。如:
```diff
await apiClient.extension.storage.group.updatestorageHaloRunV1alpha1Group(
- formState.value.metadata.name,
- formState.value
+ {
+ name: formState.value.metadata.name,
+ group: formState.value,
+ }
);
```
#### Which issue(s) this PR fixes:
<!--
PR 合并时自动关闭 issue。
Automatically closes linked issue when PR is merged.
用法:`Fixes #<issue 号>`,或者 `Fixes (粘贴 issue 完整链接)`
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
None
#### Screenshots:
<!--
如果此 PR 有 UI 的改动,最好截图说明这个 PR 的改动。
If there are UI changes to this PR, it is best to take a screenshot to illustrate the changes to this PR.
eg.
Before:

After:

-->
None
#### Special notes for your reviewer:
/cc @halo-dev/sig-halo-admin
#### Does this PR introduce a user-facing change?
<!--
如果当前 Pull Request 的修改不会造成用户侧的任何变更,在 `release-note` 代码块儿中填写 `NONE`。
否则请填写用户侧能够理解的 Release Note。如果当前 Pull Request 包含破坏性更新(Break Change),
Release Note 需要以 `action required` 开头。
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note
None
```
2022-09-06 02:26:11 +00:00
|
|
|
|
name: route.params.name as string,
|
|
|
|
|
});
|
2024-01-24 02:34:11 +00:00
|
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
onSuccess(data) {
|
|
|
|
|
formState.value = data;
|
|
|
|
|
selectedRoleTemplates.value = new Set<string>(
|
|
|
|
|
resolveDeepDependencies(data, roleTemplates.value || [])
|
2022-07-04 11:28:53 +00:00
|
|
|
|
);
|
2024-01-24 02:34:11 +00:00
|
|
|
|
},
|
|
|
|
|
enabled: computed(() => !!roleTemplates.value),
|
|
|
|
|
});
|
2022-05-30 14:38:57 +00:00
|
|
|
|
|
2022-07-04 11:28:53 +00:00
|
|
|
|
const handleUpdateRole = async () => {
|
2022-07-26 12:21:11 +00:00
|
|
|
|
await handleCreateOrUpdate();
|
2024-01-24 02:34:11 +00:00
|
|
|
|
await refetch();
|
2022-05-30 14:38:57 +00:00
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<template>
|
2023-03-23 08:54:33 +00:00
|
|
|
|
<VPageHeader :title="$t('core.role.detail.title')">
|
2022-05-30 14:38:57 +00:00
|
|
|
|
<template #icon>
|
|
|
|
|
<IconShieldUser class="mr-2 self-center" />
|
|
|
|
|
</template>
|
|
|
|
|
</VPageHeader>
|
|
|
|
|
<div class="m-0 md:m-4">
|
|
|
|
|
<VCard :body-class="['!p-0']">
|
|
|
|
|
<template #header>
|
|
|
|
|
<VTabbar
|
2022-07-26 12:21:11 +00:00
|
|
|
|
v-model:active-id="tabActiveId"
|
2022-05-30 14:38:57 +00:00
|
|
|
|
:items="[
|
2023-03-23 08:54:33 +00:00
|
|
|
|
{ id: 'detail', label: $t('core.role.detail.tabs.detail') },
|
|
|
|
|
{
|
|
|
|
|
id: 'permissions',
|
|
|
|
|
label: $t('core.role.detail.tabs.permissions'),
|
|
|
|
|
},
|
2022-05-30 14:38:57 +00:00
|
|
|
|
]"
|
|
|
|
|
class="w-full !rounded-none"
|
|
|
|
|
type="outline"
|
|
|
|
|
></VTabbar>
|
|
|
|
|
</template>
|
2022-07-26 12:21:11 +00:00
|
|
|
|
<div v-if="tabActiveId === 'detail'">
|
2022-05-30 14:38:57 +00:00
|
|
|
|
<div class="px-4 py-4 sm:px-6">
|
2023-03-23 08:54:33 +00:00
|
|
|
|
<h3 class="text-lg font-medium leading-6 text-gray-900">
|
|
|
|
|
{{ $t("core.role.detail.header.title") }}
|
|
|
|
|
</h3>
|
2022-05-30 14:38:57 +00:00
|
|
|
|
<p
|
|
|
|
|
class="mt-1 flex max-w-2xl items-center gap-2 text-sm text-gray-500"
|
|
|
|
|
>
|
2022-12-07 04:40:53 +00:00
|
|
|
|
<span>{{ getRoleCountText }}</span>
|
2022-05-30 14:38:57 +00:00
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="border-t border-gray-200">
|
2023-04-23 02:49:32 +00:00
|
|
|
|
<VDescription>
|
|
|
|
|
<VDescriptionItem
|
|
|
|
|
:label="$t('core.role.detail.fields.display_name')"
|
2022-05-30 14:38:57 +00:00
|
|
|
|
>
|
2023-04-23 02:49:32 +00:00
|
|
|
|
{{
|
|
|
|
|
formState.metadata?.annotations?.[
|
|
|
|
|
rbacAnnotations.DISPLAY_NAME
|
|
|
|
|
] || formState.metadata?.name
|
|
|
|
|
}}
|
|
|
|
|
</VDescriptionItem>
|
|
|
|
|
<VDescriptionItem
|
|
|
|
|
:label="$t('core.role.detail.fields.name')"
|
|
|
|
|
:content="formState.metadata?.name"
|
|
|
|
|
/>
|
|
|
|
|
<VDescriptionItem :label="$t('core.role.detail.fields.type')">
|
|
|
|
|
<VTag>
|
2022-07-04 11:28:53 +00:00
|
|
|
|
{{
|
2023-04-23 02:49:32 +00:00
|
|
|
|
isSystemReserved
|
|
|
|
|
? t("core.role.common.text.system_reserved")
|
|
|
|
|
: t("core.role.common.text.custom")
|
2022-07-04 11:28:53 +00:00
|
|
|
|
}}
|
2023-04-23 02:49:32 +00:00
|
|
|
|
</VTag>
|
|
|
|
|
</VDescriptionItem>
|
|
|
|
|
<VDescriptionItem
|
|
|
|
|
:label="$t('core.role.detail.fields.creation_time')"
|
|
|
|
|
:content="formatDatetime(formState.metadata.creationTimestamp)"
|
|
|
|
|
/>
|
|
|
|
|
</VDescription>
|
2022-05-30 14:38:57 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-05-31 03:34:48 +00:00
|
|
|
|
|
2022-07-26 12:21:11 +00:00
|
|
|
|
<div v-if="tabActiveId === 'permissions'">
|
2022-12-07 04:40:53 +00:00
|
|
|
|
<div v-if="isSystemReserved" class="px-4 py-5">
|
|
|
|
|
<VAlert
|
2023-03-23 08:54:33 +00:00
|
|
|
|
:title="$t('core.common.text.tip')"
|
|
|
|
|
:description="
|
|
|
|
|
$t(
|
|
|
|
|
'core.role.permissions_detail.system_reserved_alert.description'
|
|
|
|
|
)
|
|
|
|
|
"
|
2022-12-07 04:40:53 +00:00
|
|
|
|
class="w-full sm:w-1/4"
|
2024-05-14 07:02:33 +00:00
|
|
|
|
:closable="false"
|
2022-12-07 04:40:53 +00:00
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2022-05-31 03:34:48 +00:00
|
|
|
|
<div>
|
|
|
|
|
<dl class="divide-y divide-gray-100">
|
|
|
|
|
<div
|
2022-07-04 11:28:53 +00:00
|
|
|
|
v-for="(group, groupIndex) in roleTemplateGroups"
|
|
|
|
|
:key="groupIndex"
|
2022-05-31 03:34:48 +00:00
|
|
|
|
class="bg-white px-4 py-5 hover:bg-gray-50 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"
|
|
|
|
|
>
|
|
|
|
|
<dt class="text-sm font-medium text-gray-900">
|
2022-07-20 14:47:10 +00:00
|
|
|
|
<div>
|
2023-03-23 08:54:33 +00:00
|
|
|
|
{{ $t(`core.rbac.${group.module}`, group.module as string) }}
|
2022-07-20 14:47:10 +00:00
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
v-if="
|
|
|
|
|
group.roles.length &&
|
|
|
|
|
group.roles[0].metadata.labels?.[pluginLabels.NAME]
|
|
|
|
|
"
|
|
|
|
|
class="mt-3 text-xs text-gray-500"
|
|
|
|
|
>
|
2023-03-23 08:54:33 +00:00
|
|
|
|
<i18n-t
|
|
|
|
|
keypath="core.role.common.text.provided_by_plugin"
|
|
|
|
|
tag="div"
|
2022-07-20 14:47:10 +00:00
|
|
|
|
>
|
2023-03-23 08:54:33 +00:00
|
|
|
|
<template #plugin>
|
|
|
|
|
<RouterLink
|
|
|
|
|
:to="{
|
|
|
|
|
name: 'PluginDetail',
|
|
|
|
|
params: {
|
|
|
|
|
name: group.roles[0].metadata.labels?.[
|
|
|
|
|
pluginLabels.NAME
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}"
|
|
|
|
|
class="hover:text-blue-600"
|
|
|
|
|
>
|
|
|
|
|
{{
|
|
|
|
|
group.roles[0].metadata.labels?.[pluginLabels.NAME]
|
|
|
|
|
}}
|
|
|
|
|
</RouterLink>
|
|
|
|
|
</template>
|
|
|
|
|
</i18n-t>
|
2022-07-20 14:47:10 +00:00
|
|
|
|
</div>
|
2022-05-31 03:58:02 +00:00
|
|
|
|
</dt>
|
|
|
|
|
<dd class="mt-1 text-sm text-gray-900 sm:col-span-2 sm:mt-0">
|
|
|
|
|
<ul class="space-y-2">
|
2022-07-04 11:28:53 +00:00
|
|
|
|
<li v-for="(role, index) in group.roles" :key="index">
|
2022-07-19 03:18:47 +00:00
|
|
|
|
<label
|
2022-07-26 10:04:51 +00:00
|
|
|
|
class="inline-flex w-72 cursor-pointer flex-row items-center gap-4 rounded-base border p-5 hover:border-primary"
|
2022-05-31 03:58:02 +00:00
|
|
|
|
>
|
|
|
|
|
<input
|
2022-12-07 04:40:53 +00:00
|
|
|
|
v-if="!isSuperRole"
|
2022-07-26 10:04:51 +00:00
|
|
|
|
v-model="selectedRoleTemplates"
|
2022-07-04 11:28:53 +00:00
|
|
|
|
:value="role.metadata.name"
|
2022-05-31 03:58:02 +00:00
|
|
|
|
type="checkbox"
|
2022-12-07 04:40:53 +00:00
|
|
|
|
:disabled="isSystemReserved"
|
2022-07-26 10:04:51 +00:00
|
|
|
|
@change="handleRoleTemplateSelect"
|
2022-05-31 03:58:02 +00:00
|
|
|
|
/>
|
2023-11-23 09:32:09 +00:00
|
|
|
|
<input v-else type="checkbox" checked disabled />
|
2022-07-19 03:18:47 +00:00
|
|
|
|
<div class="flex flex-1 flex-col gap-y-3">
|
2022-05-31 03:58:02 +00:00
|
|
|
|
<span class="font-medium text-gray-900">
|
2022-07-04 11:28:53 +00:00
|
|
|
|
{{
|
2023-02-21 05:16:10 +00:00
|
|
|
|
$t(
|
2023-03-23 08:54:33 +00:00
|
|
|
|
`core.rbac.${
|
2023-02-21 05:16:10 +00:00
|
|
|
|
role.metadata.annotations?.[
|
|
|
|
|
rbacAnnotations.DISPLAY_NAME
|
|
|
|
|
]
|
|
|
|
|
}`,
|
|
|
|
|
role.metadata.annotations?.[
|
|
|
|
|
rbacAnnotations.DISPLAY_NAME
|
|
|
|
|
] as string
|
|
|
|
|
)
|
2022-07-04 11:28:53 +00:00
|
|
|
|
}}
|
2022-05-31 03:58:02 +00:00
|
|
|
|
</span>
|
2022-07-04 11:28:53 +00:00
|
|
|
|
<span
|
|
|
|
|
v-if="
|
|
|
|
|
role.metadata.annotations?.[
|
2022-07-20 14:47:10 +00:00
|
|
|
|
rbacAnnotations.DEPENDENCIES
|
2022-07-04 11:28:53 +00:00
|
|
|
|
]
|
|
|
|
|
"
|
|
|
|
|
class="text-xs text-gray-400"
|
|
|
|
|
>
|
|
|
|
|
{{
|
2023-03-23 08:54:33 +00:00
|
|
|
|
$t("core.role.common.text.dependent_on", {
|
|
|
|
|
roles: JSON.parse(
|
|
|
|
|
role.metadata.annotations?.[
|
|
|
|
|
rbacAnnotations.DEPENDENCIES
|
|
|
|
|
]
|
2023-02-21 05:16:10 +00:00
|
|
|
|
)
|
2023-03-23 08:54:33 +00:00
|
|
|
|
.map((item: string) =>
|
|
|
|
|
$t(`core.rbac.${item}`, item as string)
|
|
|
|
|
)
|
|
|
|
|
.join(","),
|
|
|
|
|
})
|
2022-07-04 11:28:53 +00:00
|
|
|
|
}}
|
2022-05-31 03:58:02 +00:00
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2022-07-19 03:18:47 +00:00
|
|
|
|
</label>
|
2022-05-31 03:58:02 +00:00
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</dd>
|
|
|
|
|
</div>
|
2022-05-31 03:34:48 +00:00
|
|
|
|
</dl>
|
2022-07-19 06:07:28 +00:00
|
|
|
|
<div v-permission="['system:roles:manage']" class="p-4">
|
2022-07-04 11:28:53 +00:00
|
|
|
|
<VButton
|
2022-07-26 12:21:11 +00:00
|
|
|
|
:loading="saving"
|
2022-07-04 11:28:53 +00:00
|
|
|
|
type="secondary"
|
2022-12-07 04:40:53 +00:00
|
|
|
|
:disabled="isSystemReserved"
|
2022-07-04 11:28:53 +00:00
|
|
|
|
@click="handleUpdateRole"
|
2022-12-07 04:40:53 +00:00
|
|
|
|
>
|
2023-03-23 08:54:33 +00:00
|
|
|
|
{{ $t("core.common.buttons.save") }}
|
2022-07-04 11:28:53 +00:00
|
|
|
|
</VButton>
|
2022-05-31 03:34:48 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-05-30 14:38:57 +00:00
|
|
|
|
</VCard>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|