mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Redirect and notify for perms guard, add frontend tests
This commit is contained in:
@@ -2,18 +2,34 @@ import {
|
||||
CanActivate,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
UrlTree,
|
||||
Router,
|
||||
} from '@angular/router'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PermissionsService } from '../services/permissions.service'
|
||||
import { ToastService } from '../services/toast.service'
|
||||
|
||||
@Injectable()
|
||||
export class PermissionsGuard implements CanActivate {
|
||||
constructor(private permissionsService: PermissionsService) {}
|
||||
constructor(
|
||||
private permissionsService: PermissionsService,
|
||||
private router: Router,
|
||||
private toastService: ToastService
|
||||
) {}
|
||||
|
||||
canActivate(
|
||||
route: ActivatedRouteSnapshot,
|
||||
state: RouterStateSnapshot
|
||||
): boolean {
|
||||
return this.permissionsService.currentUserCan(route.data.requiredPermission)
|
||||
): boolean | UrlTree {
|
||||
if (
|
||||
!this.permissionsService.currentUserCan(route.data.requiredPermission)
|
||||
) {
|
||||
this.toastService.showError(
|
||||
$localize`You don't have permissions to do that`
|
||||
)
|
||||
return this.router.parseUrl('/dashboard')
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user