bueno ya esta implemntado todo lo de permisos de forma recursiva
This commit is contained in:
@@ -5,21 +5,25 @@ using Modelo;
|
||||
namespace AlquilaFacil.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class LogsController: ControllerBase {
|
||||
public class LogsController : ControllerBase
|
||||
{
|
||||
|
||||
[HttpGet("/api/Logs")]
|
||||
public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, int pag=1) {
|
||||
public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, int pag = 1)
|
||||
{
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes");
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 7);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
if (pag<=0) return BadRequest(new { message = "no puede haber una pagina 0 o menor"});
|
||||
if (pag <= 0) return BadRequest(new { message = "no puede haber una pagina 0 o menor" });
|
||||
|
||||
pag-=1;
|
||||
pag -= 1;
|
||||
|
||||
var l = RepositorioLogs.Singleton.ObtenerLogsPaginado(pag);
|
||||
List<LogDto> ll = new();
|
||||
foreach (var i in l) {
|
||||
ll.Add(new LogDto{
|
||||
foreach (var i in l)
|
||||
{
|
||||
ll.Add(new LogDto
|
||||
{
|
||||
Fecha = i.Fecha,
|
||||
Accion = i.Accion,
|
||||
Dniusuario = i.Dniusuario,
|
||||
@@ -29,16 +33,19 @@ public class LogsController: ControllerBase {
|
||||
}
|
||||
|
||||
[HttpGet("/api/Logs/detalle")]
|
||||
public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, [FromQuery]DateTime fecha, [FromQuery]long idusuario) {
|
||||
public IActionResult ObtenerLogs([FromHeader(Name = "Auth")] string Auth, [FromQuery] DateTime fecha, [FromQuery] long idusuario)
|
||||
{
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes");
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 7);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
if (idusuario<=0) return BadRequest(new { message = "no puede haber un id 0 o menor"});
|
||||
if (idusuario <= 0) return BadRequest(new { message = "no puede haber un id 0 o menor" });
|
||||
|
||||
var l = RepositorioLogs.Singleton.ObtenerDetallesLogs(fecha, idusuario);
|
||||
List<LogDetalleDto> ll = new();
|
||||
foreach (var i in l) {
|
||||
ll.Add(new LogDetalleDto{
|
||||
foreach (var i in l)
|
||||
{
|
||||
ll.Add(new LogDetalleDto
|
||||
{
|
||||
Fecha = i.Fecha,
|
||||
Dniusuario = i.Dniusuario,
|
||||
NombreTabla = i.NombreTabla,
|
||||
@@ -51,12 +58,13 @@ public class LogsController: ControllerBase {
|
||||
}
|
||||
|
||||
[HttpGet("/api/Logs/cantPag")]
|
||||
public IActionResult cantidadPaginas([FromHeader(Name = "Auth")] string Auth){
|
||||
public IActionResult cantidadPaginas([FromHeader(Name = "Auth")] string Auth)
|
||||
{
|
||||
if (String.IsNullOrEmpty(Auth)) return Unauthorized();
|
||||
var validacion1 = RepositorioGrupos.Singleton.CheckGrupos(Auth, "Informes");
|
||||
var validacion1 = RepositorioPermisos.Singleton.CheckPermisos(Auth, 7);
|
||||
if (validacion1 == false) return Unauthorized();
|
||||
|
||||
int c = RepositorioLogs.Singleton.ObtenerCantidadPaginas();
|
||||
return Ok(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||
import BotonEsquina from "../Componentes/BotonEsquina.svelte";
|
||||
import ModalEditarPermiso from "../Componentes/ModalEditarPermiso.svelte";
|
||||
import Login from "./login.svelte";
|
||||
import { Modal } from "@sveltestrap/sveltestrap";
|
||||
import ModalLogs from "../Componentes/ModalLogs.svelte";
|
||||
|
||||
const token: string = sessionStorage.getItem("token") || "";
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ public class RepositorioPermisos : RepositorioBase<RepositorioPermisos>
|
||||
{
|
||||
public IQueryable<Grupo>? ListarPermisos(string email)
|
||||
{
|
||||
//WIP Aca tengo que modificar esto para que haga una busqueda de profundidad para los permisos
|
||||
var con = Context;
|
||||
Cliente? cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(c => c.Email == email);
|
||||
if (cli == null) return null;
|
||||
@@ -47,19 +46,26 @@ public class RepositorioPermisos : RepositorioBase<RepositorioPermisos>
|
||||
Cliente? cli = con.Clientes.FirstOrDefault(x => x.Token == token);
|
||||
if (cli == null || cli.Dni == 0) return false;
|
||||
|
||||
var permisos = con.Clientes
|
||||
var grupos = con.Clientes
|
||||
.Where(x => x.Dni == cli.Dni)
|
||||
.SelectMany(x => x.Idgrupos)
|
||||
.SelectMany(x => x.Idpermisos)
|
||||
.Distinct();
|
||||
.Include(x => x.Idpermisos)
|
||||
.Include(x => x.IdGrupoHijos)
|
||||
.ThenInclude(x => x.Idpermisos)
|
||||
.ToList();
|
||||
|
||||
Parallel.ForEach(permisos, (x, i) =>
|
||||
foreach (var grupo in grupos)
|
||||
{
|
||||
if (x.Id == idpermiso)
|
||||
var visitados = new HashSet<int>();
|
||||
var todosLosPermisos = new HashSet<Permiso>();
|
||||
grupo.ObtenerPermisos(todosLosPermisos, visitados);
|
||||
|
||||
if (todosLosPermisos.Any(p => p.Id == idpermiso))
|
||||
{
|
||||
tienePermiso = true;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return tienePermiso;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user