-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from udistrital/develop
feat: Implementación de roles y permisos
- Loading branch information
Showing
18 changed files
with
198 additions
and
628 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router'; | ||
|
||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class AuthGuard implements CanActivate { | ||
|
||
constructor( | ||
|
||
) { } | ||
|
||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | ||
const menuInfo = localStorage.getItem('menu'); | ||
const menuPermisos = menuInfo ? JSON.parse(atob(menuInfo)) : null; | ||
const fullUrl = window.location.href; | ||
const url = new URL(fullUrl); | ||
const path = url.pathname; | ||
|
||
// Obtener parámetros de la ruta | ||
const params = route.params; | ||
|
||
if (menuPermisos != null) { | ||
// Pasar tanto la URL como los parámetros a la función de verificación | ||
if (checkUrlExists(menuPermisos, path, params)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { | ||
return this.canActivate(route, state); | ||
} | ||
} | ||
|
||
// Recorrer el menú para verificar si la URL y los parámetros existen | ||
function checkUrlExists(menuItems: any, targetUrl: string, params: any) { | ||
return menuItems.some((item: any) => { | ||
// Verificar la URL y los parámetros | ||
if (item.Url === targetUrl && checkParams(item.Params, params)) { | ||
return true; | ||
} | ||
if (item.Opciones && item.Opciones.length > 0) { | ||
return checkUrlExists(item.Opciones, targetUrl, params); | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
// Verificar los parámetros de la ruta | ||
function checkParams(expectedParams: any, actualParams: any): boolean { | ||
if (!expectedParams) { | ||
return true; // No se requieren parámetros específicos | ||
} | ||
for (let key in expectedParams) { | ||
if (expectedParams[key] !== actualParams[key]) { | ||
return false; // Un parámetro no coincide | ||
} | ||
} | ||
return true; // Todos los parámetros coinciden | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
src/app/modules/gestion-roles/form-roles/form-roles.component.html
This file was deleted.
Oops, something went wrong.
78 changes: 0 additions & 78 deletions
78
src/app/modules/gestion-roles/form-roles/form-roles.component.scss
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/app/modules/gestion-roles/form-roles/form-roles.component.spec.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.