mirror of
https://github.com/halo-dev/halo.git
synced 2025-12-20 16:44:38 +08:00
Refactor permission checks to use shared utils (#7853)
#### What type of PR is this?
/area ui
/kind feature
/milestone 2.22.x
#### What this PR does / why we need it:
This PR introduces a developer-friendly utility for checking UI permissions, which is also exposed for use by plugins.
Usage:
```ts
import { utils } from "@halo-dev/console-shared"
utils.permission.has(['any:permission'])
```
#### Does this PR introduce a user-facing change?
```release-note
在 `@halo-dev/console-shared` 包中提供 UI 权限检查工具
```
This commit is contained in:
@@ -8,7 +8,6 @@ import { useSessionKeepAlive } from "@/composables/use-session-keep-alive";
|
||||
import { contentAnnotations } from "@/constants/annotations";
|
||||
import { FormType } from "@/types/slug";
|
||||
import { randomUUID } from "@/utils/id";
|
||||
import { usePermission } from "@/utils/permission";
|
||||
import { useContentSnapshot } from "@console/composables/use-content-snapshot";
|
||||
import { useSaveKeybinding } from "@console/composables/use-save-keybinding";
|
||||
import useSlugify from "@console/composables/use-slugify";
|
||||
@@ -30,7 +29,7 @@ import {
|
||||
VButton,
|
||||
VPageHeader,
|
||||
} from "@halo-dev/components";
|
||||
import type { EditorProvider } from "@halo-dev/console-shared";
|
||||
import { utils, type EditorProvider } from "@halo-dev/console-shared";
|
||||
import { useLocalStorage } from "@vueuse/core";
|
||||
import { useRouteQuery } from "@vueuse/router";
|
||||
import type { AxiosRequestConfig } from "axios";
|
||||
@@ -57,7 +56,6 @@ const uid = new ShortUniqueId();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
const { mutateAsync: postUpdateMutate } = usePostUpdateMutate();
|
||||
const { currentUserHasPermission } = usePermission();
|
||||
|
||||
// Editor providers
|
||||
const { editorProviders, fetchEditorProviders } = useEditorExtensionPoints();
|
||||
@@ -471,7 +469,7 @@ useSessionKeepAlive();
|
||||
|
||||
// Upload image
|
||||
async function handleUploadImage(file: File, options?: AxiosRequestConfig) {
|
||||
if (!currentUserHasPermission(["uc:attachments:manage"])) {
|
||||
if (!utils.permission.has(["uc:attachments:manage"])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user