From 450b5b68456127fd6a9131ea21cfe834c7b7b20f Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 8 Apr 2022 14:23:04 +0100 Subject: [PATCH] route permission --- src/app/guards/auth.guard.ts | 58 +++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts index 688f6d22c..27f9e29b3 100644 --- a/src/app/guards/auth.guard.ts +++ b/src/app/guards/auth.guard.ts @@ -32,34 +32,58 @@ export class AuthGuard implements CanActivate { this.router.navigate(['/']); return false } else { - if(this.p.userPermission(this.p.permissionList.Chat.access) == true){ + if(this.p.userPermission(this.p.permissionList.Chat.access) == true) { this.authService.loginChat(); } const pathname = window.location.pathname - if(this.p.userPermission(this.p.permissionList.Agenda.access) && pathname.startsWith('/home/agenda')) { - return true; - } else if (this.p.userPermission(this.p.permissionList.Gabinete.access) && pathname.startsWith('/home/gabinete-digital')) { - return true; - } - else if(this.p.userPermission(this.p.permissionList.Chat.access) && pathname.startsWith('/home/chat')) { - return true; - } else if(this.p.userPermission(this.p.permissionList.Actions.access) && pathname.startsWith('/home/publications')) { - return true; - } else if ((this.p.userPermission([this.p.permissionList.Agenda.access]) || this.p.userPermission([this.p.permissionList.Gabinete.access])) && pathname.startsWith('/home/events')) { + if(this.p.userPermission(pathname.startsWith('/home/agenda'))) { + if(this.p.permissionList.Agenda.access) { + return true; + } else { + this.router.navigate(['/login']); + return false; + } + + } else if ( pathname.startsWith('/home/gabinete-digital')) { + + if(this.p.userPermission(this.p.permissionList.Gabinete.access)) { + return true; + } else { + this.router.navigate(['/login']); + return false; + } + } + else if(pathname.startsWith('/home/chat')) { + if(this.p.userPermission(this.p.permissionList.Gabinete.access)) { + return true; + } else { + this.router.navigate(['/login']); + return false; + } + } else if(pathname.startsWith('/home/publications')) { + if(this.p.userPermission(this.p.permissionList.Actions.access)) { + return true + } else { + this.router.navigate(['/login']); + return false + } + } else if (pathname.startsWith('/home/events')) { + if((this.p.userPermission([this.p.permissionList.Agenda.access]) || this.p.userPermission([this.p.permissionList.Gabinete.access]))) { + return true + } else { + this.router.navigate(['/login']); + return false + } } else if (pathname == '/') { return true - } - else if (this.RouteService.history.length >= 1) { - const pathName = this.RouteService.getLastRouteA() - this.router.navigate([pathName]); } else { - this.router.navigate(['/']); + this.router.navigate(['/login']); + return false } - return false; } }