mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-16 00:19:32 -06:00
Enhancement: consolidate management lists into document attributes section (#12045)
This commit is contained in:
@@ -96,4 +96,52 @@ describe('PermissionsGuard', () => {
|
||||
expect(canActivate).toHaveProperty('root') // returns UrlTree
|
||||
expect(toastSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should activate when any required permission is granted', () => {
|
||||
jest
|
||||
.spyOn(permissionsService, 'currentUserCan')
|
||||
.mockImplementation((action, type) => {
|
||||
return type === PermissionType.Tag
|
||||
})
|
||||
|
||||
const canActivate = guard.canActivate(
|
||||
{
|
||||
data: {
|
||||
requiredPermissionAny: [
|
||||
{ action: PermissionAction.View, type: PermissionType.Tag },
|
||||
{
|
||||
action: PermissionAction.View,
|
||||
type: PermissionType.DocumentType,
|
||||
},
|
||||
],
|
||||
},
|
||||
} as any,
|
||||
routerState.snapshot
|
||||
)
|
||||
|
||||
expect(canActivate).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should not activate when no required permission is granted', () => {
|
||||
jest
|
||||
.spyOn(permissionsService, 'currentUserCan')
|
||||
.mockImplementation(() => false)
|
||||
|
||||
const canActivate = guard.canActivate(
|
||||
{
|
||||
data: {
|
||||
requiredPermissionAny: [
|
||||
{ action: PermissionAction.View, type: PermissionType.Tag },
|
||||
{
|
||||
action: PermissionAction.View,
|
||||
type: PermissionType.DocumentType,
|
||||
},
|
||||
],
|
||||
},
|
||||
} as any,
|
||||
routerState.snapshot
|
||||
)
|
||||
|
||||
expect(canActivate).toHaveProperty('root')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -20,12 +20,20 @@ export class PermissionsGuard {
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot
|
||||
): boolean | UrlTree {
|
||||
const requiredPermissionAny: { action: any; type: any }[] =
|
||||
route.data.requiredPermissionAny
|
||||
|
||||
if (
|
||||
(route.data.requireAdmin && !this.permissionsService.isAdmin()) ||
|
||||
(route.data.requiredPermission &&
|
||||
!this.permissionsService.currentUserCan(
|
||||
route.data.requiredPermission.action,
|
||||
route.data.requiredPermission.type
|
||||
)) ||
|
||||
(Array.isArray(requiredPermissionAny) &&
|
||||
requiredPermissionAny.length > 0 &&
|
||||
!requiredPermissionAny.some((p) =>
|
||||
this.permissionsService.currentUserCan(p.action, p.type)
|
||||
))
|
||||
) {
|
||||
// Check if tour is running 1 = TourState.ON
|
||||
|
||||
Reference in New Issue
Block a user