paperless-ngx/src-ui/src/app/guards/permissions.guard.ts
shamoon 3241ac7dc2 Upgrade to Angular 16
update ngx-file-drop
Update ng-bootstrap, ng-select, cookie-service and ui-tour
Update setup-jest.ts
bump typescript to 5.1.6

bump ngx-color and tslib
2023-07-01 19:59:24 -07:00

43 lines
1.1 KiB
TypeScript

import {
ActivatedRouteSnapshot,
RouterStateSnapshot,
UrlTree,
Router,
} from '@angular/router'
import { Injectable } from '@angular/core'
import { PermissionsService } from '../services/permissions.service'
import { ToastService } from '../services/toast.service'
import { TourService } from 'ngx-ui-tour-ng-bootstrap'
@Injectable()
export class PermissionsGuard {
constructor(
private permissionsService: PermissionsService,
private router: Router,
private toastService: ToastService,
private tourService: TourService
) {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): boolean | UrlTree {
if (
!this.permissionsService.currentUserCan(
route.data.requiredPermission.action,
route.data.requiredPermission.type
)
) {
// Check if tour is running 1 = TourState.ON
if (this.tourService.getStatus() !== 1) {
this.toastService.showError(
$localize`You don't have permissions to do that`
)
}
return this.router.parseUrl('/dashboard')
} else {
return true
}
}
}