feat(admin): add MediaView, MediaPickerModal, MediaFinderField, unify MailImagePicker, and rebuild boardwalk dist
This commit is contained in:
@@ -7,6 +7,7 @@ import type { AdminProfile } from '../api/types'
|
||||
import { setListStateOwner } from './listState'
|
||||
import { applyProfilePreferences } from './usePreferences'
|
||||
import { setNavigation } from './useNavigation'
|
||||
import { setMediaAccess } from './useMediaAccess'
|
||||
import { setSettings } from './useSettings'
|
||||
|
||||
const user = ref<AdminProfile | null>(null)
|
||||
@@ -128,6 +129,7 @@ export async function logout(router?: Pick<Router, 'replace'>): Promise<void> {
|
||||
clearUser()
|
||||
setNavigation([])
|
||||
setSettings([])
|
||||
setMediaAccess({ canView: false, canManage: false })
|
||||
}
|
||||
if (router) {
|
||||
await router.replace({ name: 'login' }).catch(() => undefined)
|
||||
|
||||
34
admin/src/state/useMediaAccess.ts
Normal file
34
admin/src/state/useMediaAccess.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// Media Library access state, server-filtered like navigation and settings.
|
||||
// The rail shows "Media" only when the signed-in admin holds media.view_media
|
||||
// or media.manage_media (verified against GET /media/items?per_page=1).
|
||||
import { readonly, ref } from 'vue'
|
||||
import { api } from '../api/client'
|
||||
|
||||
const canView = ref(false)
|
||||
const canManage = ref(false)
|
||||
|
||||
export const hasMedia = readonly(canView)
|
||||
export const canManageMedia = readonly(canManage)
|
||||
|
||||
export async function loadMediaAccess(): Promise<boolean> {
|
||||
const { data, response } = await api.GET('/media/items', {
|
||||
params: { query: { per_page: 1 } },
|
||||
})
|
||||
if (response.ok && data) {
|
||||
canView.value = true
|
||||
canManage.value = data.meta.can_manage === true
|
||||
return true
|
||||
}
|
||||
canView.value = false
|
||||
canManage.value = false
|
||||
return false
|
||||
}
|
||||
|
||||
export function setMediaAccess(access: { canView: boolean; canManage?: boolean }): void {
|
||||
canView.value = access.canView
|
||||
canManage.value = access.canManage === true
|
||||
}
|
||||
|
||||
export function useMediaAccess() {
|
||||
return { hasMedia, canManageMedia, loadMediaAccess, setMediaAccess }
|
||||
}
|
||||
Reference in New Issue
Block a user