perf: refine ui permissions adapter

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/3445/head
Ryan Wang 2022-10-10 15:29:05 +08:00
parent d2fbb8b98f
commit f761c64035
12 changed files with 216 additions and 160 deletions

View File

@ -15,10 +15,13 @@ import {
import { computed, markRaw, onMounted, ref, watch, type Component } from "vue";
import Fuse from "fuse.js";
import { apiClient } from "@/utils/api-client";
import { usePermission } from "@/utils/permission";
const router = useRouter();
const route = useRoute();
const { currentUserHasPermission } = usePermission();
const props = withDefaults(
defineProps<{
visible: boolean;
@ -74,6 +77,7 @@ const handleBuildSearchIndex = () => {
});
});
if (currentUserHasPermission(["system:users:view"])) {
apiClient.extension.user.listv1alpha1User().then((response) => {
response.data.items.forEach((user) => {
fuse.add({
@ -91,7 +95,9 @@ const handleBuildSearchIndex = () => {
});
});
});
}
if (currentUserHasPermission(["system:plugins:view"])) {
apiClient.extension.plugin
.listpluginHaloRunV1alpha1Plugin()
.then((response) => {
@ -111,8 +117,12 @@ const handleBuildSearchIndex = () => {
});
});
});
}
apiClient.extension.post.listcontentHaloRunV1alpha1Post().then((response) => {
if (currentUserHasPermission(["system:posts:view"])) {
apiClient.extension.post
.listcontentHaloRunV1alpha1Post()
.then((response) => {
response.data.items.forEach((post) => {
fuse.add({
title: post.spec.title,
@ -167,7 +177,9 @@ const handleBuildSearchIndex = () => {
});
});
});
}
if (currentUserHasPermission(["system:singlepages:view"])) {
apiClient.extension.singlePage
.listcontentHaloRunV1alpha1SinglePage()
.then((response) => {
@ -187,7 +199,9 @@ const handleBuildSearchIndex = () => {
});
});
});
}
if (currentUserHasPermission(["system:attachments:view"])) {
apiClient.extension.storage.attachment
.liststorageHaloRunV1alpha1Attachment()
.then((response) => {
@ -207,7 +221,12 @@ const handleBuildSearchIndex = () => {
});
});
});
}
if (
currentUserHasPermission(["system:settings:view"]) &&
currentUserHasPermission(["system:configmaps:view"])
) {
apiClient.extension.setting
.getv1alpha1Setting({ name: "system" })
.then((response) => {
@ -268,6 +287,7 @@ const handleBuildSearchIndex = () => {
});
}
});
}
};
const handleKeydown = (e: KeyboardEvent) => {

View File

@ -10,6 +10,9 @@ import Draggable from "vuedraggable";
import type { CategoryTree } from "../utils";
import { ref } from "vue";
import { formatDatetime } from "@/utils/date";
import { usePermission } from "@/utils/permission";
const { currentUserHasPermission } = usePermission();
withDefaults(
defineProps<{
@ -87,7 +90,10 @@ function onDelete(category: CategoryTree) {
</template>
</VEntityField>
</template>
<template #dropdownItems>
<template
v-if="currentUserHasPermission(['system:posts:manage'])"
#dropdownItems
>
<VButton
v-permission="['system:posts:manage']"
v-close-popper

View File

@ -28,6 +28,9 @@ import { formatDatetime } from "@/utils/date";
import { useRouteQuery } from "@vueuse/router";
import { apiClient } from "@/utils/api-client";
import { usePermission } from "@/utils/permission";
const { currentUserHasPermission } = usePermission();
const viewTypes = [
{
@ -206,7 +209,10 @@ onMounted(async () => {
</template>
</VEntityField>
</template>
<template #dropdownItems>
<template
v-if="currentUserHasPermission(['system:posts:manage'])"
#dropdownItems
>
<VButton
v-permission="['system:posts:manage']"
v-close-popper

View File

@ -68,7 +68,7 @@ watch(
<FormKitSchema :schema="formSchema" />
</FormKit>
</div>
<div class="pt-5">
<div v-permission="['system:configmaps:manage']" class="pt-5">
<div class="flex justify-start">
<VButton
:loading="saving"

View File

@ -27,6 +27,9 @@ import {
} from "@halo-dev/components";
import ThemeListModal from "../components/ThemeListModal.vue";
import type { SettingForm, Theme } from "@halo-dev/api-client";
import { usePermission } from "@/utils/permission";
const { currentUserHasPermission } = usePermission();
interface ThemeTab {
id: string;
@ -83,6 +86,12 @@ watch(
if (selectedTheme.value) {
// reset tabs
tabs.value = cloneDeep(initialTabs);
if (!currentUserHasPermission(["system:settings:view"])) {
handleTriggerTabChange();
return;
}
await handleFetchSettings();
if (setting.value) {

View File

@ -29,7 +29,7 @@ export default definePlugin({
component: ThemeSetting,
meta: {
title: "主题设置",
permissions: ["system:themes:view"],
permissions: ["system:settings:view"],
},
},
],

View File

@ -16,6 +16,9 @@ import PluginInstallModal from "./components/PluginInstallModal.vue";
import { onMounted, ref } from "vue";
import { apiClient } from "@/utils/api-client";
import type { PluginList } from "@halo-dev/api-client";
import { usePermission } from "@/utils/permission";
const { currentUserHasPermission } = usePermission();
const plugins = ref<PluginList>({
page: 1,
@ -119,8 +122,8 @@ function handleSortItemChange(sortItem?: SortItem) {
</script>
<template>
<PluginInstallModal
v-if="currentUserHasPermission(['system:plugins:manage'])"
v-model:visible="pluginInstall"
v-permission="['system:plugins:manage']"
@close="handleFetchPlugins"
/>

View File

@ -77,7 +77,7 @@ await handleFetchPlugin();
<FormKitSchema :schema="formSchema" />
</FormKit>
</div>
<div class="pt-5">
<div v-permission="['system:configmaps:manage']" class="pt-5">
<div class="flex justify-start">
<VButton
:loading="saving"

View File

@ -17,6 +17,9 @@ import { BasicLayout } from "@halo-dev/console-shared";
// types
import type { Ref } from "vue";
import type { Plugin, SettingForm } from "@halo-dev/api-client";
import { usePermission } from "@/utils/permission";
const { currentUserHasPermission } = usePermission();
interface PluginTab {
id: string;
@ -96,6 +99,12 @@ const handleTriggerTabChange = () => {
onMounted(async () => {
await handleFetchPlugin();
if (!currentUserHasPermission(["system:settings:view"])) {
handleTriggerTabChange();
return;
}
await handleFetchSettings();
tabs.value = cloneDeep(initialTabs);

View File

@ -43,6 +43,7 @@ export default definePlugin({
component: PluginDetail,
meta: {
title: "插件详情",
permissions: ["system:plugins:view"],
},
},
{
@ -51,6 +52,7 @@ export default definePlugin({
component: PluginSetting,
meta: {
title: "插件设置",
permissions: ["system:settings:view"],
},
},
],

View File

@ -48,7 +48,7 @@ await handleFetchConfigMap();
<FormKitSchema :schema="formSchema" />
</FormKit>
</div>
<div class="pt-5">
<div v-permission="['system:configmaps:manage']" class="pt-5">
<div class="flex justify-start">
<VButton
:loading="saving"

View File

@ -18,6 +18,7 @@ export default definePlugin({
component: SystemSetting,
meta: {
title: "系统设置",
permissions: ["system:settings:view"],
},
},
],