Chore: Upgrade to Angular v18

Chore: Upgrade to Python 3.12
Chore: Upgrade to psycopg3
This commit is contained in:
2024-06-03 13:22:56 +05:30
parent 56c1be5e05
commit 010e9a84db
573 changed files with 5727 additions and 6528 deletions

View File

@ -1,34 +1,26 @@
import { Injectable } from '@angular/core';
import { Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { inject } from '@angular/core';
import { CanActivateFn } from '@angular/router';
import { Router } from '@angular/router';
import { ToasterService } from '../core/toaster.service';
import { AuthService } from './auth.service';
@Injectable({ providedIn: 'root' })
export class AuthGuard {
constructor(
private router: Router,
private authService: AuthService,
private toaster: ToasterService,
) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const { user } = this.authService;
const permission =
route.data['permission'] === undefined
? route.data['permission']
: route.data['permission'].replace(/ /g, '-').toLowerCase();
if (!user) {
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
return false;
}
if (permission !== undefined && !this.authService.allowed(permission)) {
this.toaster.show('Error', 'You do not have the permission to access this area.');
return false;
}
// logged in so return true
return true;
export const authGuard: CanActivateFn = (route, state) => {
const user = inject(AuthService).user;
const permission =
route.data['permission'] === undefined
? route.data['permission']
: route.data['permission'].replace(/ /g, '-').toLowerCase();
if (!user) {
// not logged in so redirect to login page with the return url
inject(Router).navigate(['/login'], { queryParams: { returnUrl: state.url } });
return false;
}
}
if (permission !== undefined && user.perms.indexOf(permission) === -1) {
inject(ToasterService).show('Danger', 'You do not have the permission to access this area.');
return false;
}
// logged in so return true
return true;
};