mirror of https://github.com/halo-dev/halo
perf: refine ui permissions adapter
Signed-off-by: Ryan Wang <i@ryanc.cc>pull/3445/head
parent
d2fbb8b98f
commit
f761c64035
|
@ -15,10 +15,13 @@ import {
|
||||||
import { computed, markRaw, onMounted, ref, watch, type Component } from "vue";
|
import { computed, markRaw, onMounted, ref, watch, type Component } from "vue";
|
||||||
import Fuse from "fuse.js";
|
import Fuse from "fuse.js";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
|
import { usePermission } from "@/utils/permission";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
|
const { currentUserHasPermission } = usePermission();
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
|
@ -74,6 +77,7 @@ const handleBuildSearchIndex = () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (currentUserHasPermission(["system:users:view"])) {
|
||||||
apiClient.extension.user.listv1alpha1User().then((response) => {
|
apiClient.extension.user.listv1alpha1User().then((response) => {
|
||||||
response.data.items.forEach((user) => {
|
response.data.items.forEach((user) => {
|
||||||
fuse.add({
|
fuse.add({
|
||||||
|
@ -91,7 +95,9 @@ const handleBuildSearchIndex = () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentUserHasPermission(["system:plugins:view"])) {
|
||||||
apiClient.extension.plugin
|
apiClient.extension.plugin
|
||||||
.listpluginHaloRunV1alpha1Plugin()
|
.listpluginHaloRunV1alpha1Plugin()
|
||||||
.then((response) => {
|
.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) => {
|
response.data.items.forEach((post) => {
|
||||||
fuse.add({
|
fuse.add({
|
||||||
title: post.spec.title,
|
title: post.spec.title,
|
||||||
|
@ -167,7 +177,9 @@ const handleBuildSearchIndex = () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentUserHasPermission(["system:singlepages:view"])) {
|
||||||
apiClient.extension.singlePage
|
apiClient.extension.singlePage
|
||||||
.listcontentHaloRunV1alpha1SinglePage()
|
.listcontentHaloRunV1alpha1SinglePage()
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -187,7 +199,9 @@ const handleBuildSearchIndex = () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentUserHasPermission(["system:attachments:view"])) {
|
||||||
apiClient.extension.storage.attachment
|
apiClient.extension.storage.attachment
|
||||||
.liststorageHaloRunV1alpha1Attachment()
|
.liststorageHaloRunV1alpha1Attachment()
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -207,7 +221,12 @@ const handleBuildSearchIndex = () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentUserHasPermission(["system:settings:view"]) &&
|
||||||
|
currentUserHasPermission(["system:configmaps:view"])
|
||||||
|
) {
|
||||||
apiClient.extension.setting
|
apiClient.extension.setting
|
||||||
.getv1alpha1Setting({ name: "system" })
|
.getv1alpha1Setting({ name: "system" })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -268,6 +287,7 @@ const handleBuildSearchIndex = () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleKeydown = (e: KeyboardEvent) => {
|
const handleKeydown = (e: KeyboardEvent) => {
|
||||||
|
|
|
@ -10,6 +10,9 @@ import Draggable from "vuedraggable";
|
||||||
import type { CategoryTree } from "../utils";
|
import type { CategoryTree } from "../utils";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import { formatDatetime } from "@/utils/date";
|
import { formatDatetime } from "@/utils/date";
|
||||||
|
import { usePermission } from "@/utils/permission";
|
||||||
|
|
||||||
|
const { currentUserHasPermission } = usePermission();
|
||||||
|
|
||||||
withDefaults(
|
withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
@ -87,7 +90,10 @@ function onDelete(category: CategoryTree) {
|
||||||
</template>
|
</template>
|
||||||
</VEntityField>
|
</VEntityField>
|
||||||
</template>
|
</template>
|
||||||
<template #dropdownItems>
|
<template
|
||||||
|
v-if="currentUserHasPermission(['system:posts:manage'])"
|
||||||
|
#dropdownItems
|
||||||
|
>
|
||||||
<VButton
|
<VButton
|
||||||
v-permission="['system:posts:manage']"
|
v-permission="['system:posts:manage']"
|
||||||
v-close-popper
|
v-close-popper
|
||||||
|
|
|
@ -28,6 +28,9 @@ import { formatDatetime } from "@/utils/date";
|
||||||
|
|
||||||
import { useRouteQuery } from "@vueuse/router";
|
import { useRouteQuery } from "@vueuse/router";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
|
import { usePermission } from "@/utils/permission";
|
||||||
|
|
||||||
|
const { currentUserHasPermission } = usePermission();
|
||||||
|
|
||||||
const viewTypes = [
|
const viewTypes = [
|
||||||
{
|
{
|
||||||
|
@ -206,7 +209,10 @@ onMounted(async () => {
|
||||||
</template>
|
</template>
|
||||||
</VEntityField>
|
</VEntityField>
|
||||||
</template>
|
</template>
|
||||||
<template #dropdownItems>
|
<template
|
||||||
|
v-if="currentUserHasPermission(['system:posts:manage'])"
|
||||||
|
#dropdownItems
|
||||||
|
>
|
||||||
<VButton
|
<VButton
|
||||||
v-permission="['system:posts:manage']"
|
v-permission="['system:posts:manage']"
|
||||||
v-close-popper
|
v-close-popper
|
||||||
|
|
|
@ -68,7 +68,7 @@ watch(
|
||||||
<FormKitSchema :schema="formSchema" />
|
<FormKitSchema :schema="formSchema" />
|
||||||
</FormKit>
|
</FormKit>
|
||||||
</div>
|
</div>
|
||||||
<div class="pt-5">
|
<div v-permission="['system:configmaps:manage']" class="pt-5">
|
||||||
<div class="flex justify-start">
|
<div class="flex justify-start">
|
||||||
<VButton
|
<VButton
|
||||||
:loading="saving"
|
:loading="saving"
|
||||||
|
|
|
@ -27,6 +27,9 @@ import {
|
||||||
} from "@halo-dev/components";
|
} from "@halo-dev/components";
|
||||||
import ThemeListModal from "../components/ThemeListModal.vue";
|
import ThemeListModal from "../components/ThemeListModal.vue";
|
||||||
import type { SettingForm, Theme } from "@halo-dev/api-client";
|
import type { SettingForm, Theme } from "@halo-dev/api-client";
|
||||||
|
import { usePermission } from "@/utils/permission";
|
||||||
|
|
||||||
|
const { currentUserHasPermission } = usePermission();
|
||||||
|
|
||||||
interface ThemeTab {
|
interface ThemeTab {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -83,6 +86,12 @@ watch(
|
||||||
if (selectedTheme.value) {
|
if (selectedTheme.value) {
|
||||||
// reset tabs
|
// reset tabs
|
||||||
tabs.value = cloneDeep(initialTabs);
|
tabs.value = cloneDeep(initialTabs);
|
||||||
|
|
||||||
|
if (!currentUserHasPermission(["system:settings:view"])) {
|
||||||
|
handleTriggerTabChange();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await handleFetchSettings();
|
await handleFetchSettings();
|
||||||
|
|
||||||
if (setting.value) {
|
if (setting.value) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ export default definePlugin({
|
||||||
component: ThemeSetting,
|
component: ThemeSetting,
|
||||||
meta: {
|
meta: {
|
||||||
title: "主题设置",
|
title: "主题设置",
|
||||||
permissions: ["system:themes:view"],
|
permissions: ["system:settings:view"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -16,6 +16,9 @@ import PluginInstallModal from "./components/PluginInstallModal.vue";
|
||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import type { PluginList } from "@halo-dev/api-client";
|
import type { PluginList } from "@halo-dev/api-client";
|
||||||
|
import { usePermission } from "@/utils/permission";
|
||||||
|
|
||||||
|
const { currentUserHasPermission } = usePermission();
|
||||||
|
|
||||||
const plugins = ref<PluginList>({
|
const plugins = ref<PluginList>({
|
||||||
page: 1,
|
page: 1,
|
||||||
|
@ -119,8 +122,8 @@ function handleSortItemChange(sortItem?: SortItem) {
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<PluginInstallModal
|
<PluginInstallModal
|
||||||
|
v-if="currentUserHasPermission(['system:plugins:manage'])"
|
||||||
v-model:visible="pluginInstall"
|
v-model:visible="pluginInstall"
|
||||||
v-permission="['system:plugins:manage']"
|
|
||||||
@close="handleFetchPlugins"
|
@close="handleFetchPlugins"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ await handleFetchPlugin();
|
||||||
<FormKitSchema :schema="formSchema" />
|
<FormKitSchema :schema="formSchema" />
|
||||||
</FormKit>
|
</FormKit>
|
||||||
</div>
|
</div>
|
||||||
<div class="pt-5">
|
<div v-permission="['system:configmaps:manage']" class="pt-5">
|
||||||
<div class="flex justify-start">
|
<div class="flex justify-start">
|
||||||
<VButton
|
<VButton
|
||||||
:loading="saving"
|
:loading="saving"
|
||||||
|
|
|
@ -17,6 +17,9 @@ import { BasicLayout } from "@halo-dev/console-shared";
|
||||||
// types
|
// types
|
||||||
import type { Ref } from "vue";
|
import type { Ref } from "vue";
|
||||||
import type { Plugin, SettingForm } from "@halo-dev/api-client";
|
import type { Plugin, SettingForm } from "@halo-dev/api-client";
|
||||||
|
import { usePermission } from "@/utils/permission";
|
||||||
|
|
||||||
|
const { currentUserHasPermission } = usePermission();
|
||||||
|
|
||||||
interface PluginTab {
|
interface PluginTab {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -96,6 +99,12 @@ const handleTriggerTabChange = () => {
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await handleFetchPlugin();
|
await handleFetchPlugin();
|
||||||
|
|
||||||
|
if (!currentUserHasPermission(["system:settings:view"])) {
|
||||||
|
handleTriggerTabChange();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await handleFetchSettings();
|
await handleFetchSettings();
|
||||||
|
|
||||||
tabs.value = cloneDeep(initialTabs);
|
tabs.value = cloneDeep(initialTabs);
|
||||||
|
|
|
@ -43,6 +43,7 @@ export default definePlugin({
|
||||||
component: PluginDetail,
|
component: PluginDetail,
|
||||||
meta: {
|
meta: {
|
||||||
title: "插件详情",
|
title: "插件详情",
|
||||||
|
permissions: ["system:plugins:view"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -51,6 +52,7 @@ export default definePlugin({
|
||||||
component: PluginSetting,
|
component: PluginSetting,
|
||||||
meta: {
|
meta: {
|
||||||
title: "插件设置",
|
title: "插件设置",
|
||||||
|
permissions: ["system:settings:view"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -48,7 +48,7 @@ await handleFetchConfigMap();
|
||||||
<FormKitSchema :schema="formSchema" />
|
<FormKitSchema :schema="formSchema" />
|
||||||
</FormKit>
|
</FormKit>
|
||||||
</div>
|
</div>
|
||||||
<div class="pt-5">
|
<div v-permission="['system:configmaps:manage']" class="pt-5">
|
||||||
<div class="flex justify-start">
|
<div class="flex justify-start">
|
||||||
<VButton
|
<VButton
|
||||||
:loading="saving"
|
:loading="saving"
|
||||||
|
|
|
@ -18,6 +18,7 @@ export default definePlugin({
|
||||||
component: SystemSetting,
|
component: SystemSetting,
|
||||||
meta: {
|
meta: {
|
||||||
title: "系统设置",
|
title: "系统设置",
|
||||||
|
permissions: ["system:settings:view"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue