修复bug
This commit is contained in:
@@ -37,11 +37,13 @@ describe('admin router access metadata', () => {
|
||||
expect(route?.meta.permission).toBe('platform:download:list')
|
||||
})
|
||||
|
||||
it('protects enterprise reviews with the backend review menu permission', () => {
|
||||
it('redirects the removed enterprise review route to the protected customer list', () => {
|
||||
const route = router.getRoutes().find((item) => item.name === 'enterprise-reviews')
|
||||
|
||||
expect(route?.path).toBe('/customers/reviews')
|
||||
expect(route?.meta.permission).toBe('platform:customer:review')
|
||||
expect(route?.redirect).toBe('/customers')
|
||||
expect(route?.meta.permission).toBe('platform:customer:list')
|
||||
expect(route?.meta.permissionAnyOf).toContain('platform:customer:review')
|
||||
})
|
||||
|
||||
it('keeps forbidden inside the authenticated layout without a business permission', () => {
|
||||
|
||||
@@ -60,12 +60,18 @@ router.beforeEach((to) => {
|
||||
|
||||
const access = useAccessPreviewStore()
|
||||
if (auth.isAuthenticated) access.initializeAfterLogin()
|
||||
const alternativePermissions = to.meta.permissionAnyOf ?? []
|
||||
const requiresRoutePermission = Boolean(to.meta.permission || alternativePermissions.length)
|
||||
const hasRoutePermission = !requiresRoutePermission || Boolean(
|
||||
(to.meta.permission && access.can(to.meta.permission))
|
||||
|| alternativePermissions.some((permission) => access.can(permission)),
|
||||
)
|
||||
const decision = decideRouteAccess({
|
||||
requiresAuth: to.meta.requiresAuth,
|
||||
isAuthenticated: auth.isAuthenticated,
|
||||
fullPath: to.fullPath,
|
||||
permission: to.meta.permission,
|
||||
hasPermission: to.meta.permission ? access.can(to.meta.permission) : true,
|
||||
permission: to.meta.permission ?? alternativePermissions[0],
|
||||
hasPermission: hasRoutePermission,
|
||||
})
|
||||
|
||||
if (decision.type === 'login') {
|
||||
|
||||
Vendored
+1
@@ -7,5 +7,6 @@ declare module 'vue-router' {
|
||||
showPageHeading?: boolean
|
||||
requiresAuth?: boolean
|
||||
permission?: string
|
||||
permissionAnyOf?: string[]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user