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;
|
namespace AlquilaFacil.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class LogsController: ControllerBase {
|
public class LogsController : ControllerBase
|
||||||
|
{
|
||||||
|
|
||||||
[HttpGet("/api/Logs")]
|
[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();
|
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 (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);
|
var l = RepositorioLogs.Singleton.ObtenerLogsPaginado(pag);
|
||||||
List<LogDto> ll = new();
|
List<LogDto> ll = new();
|
||||||
foreach (var i in l) {
|
foreach (var i in l)
|
||||||
ll.Add(new LogDto{
|
{
|
||||||
|
ll.Add(new LogDto
|
||||||
|
{
|
||||||
Fecha = i.Fecha,
|
Fecha = i.Fecha,
|
||||||
Accion = i.Accion,
|
Accion = i.Accion,
|
||||||
Dniusuario = i.Dniusuario,
|
Dniusuario = i.Dniusuario,
|
||||||
@@ -29,16 +33,19 @@ public class LogsController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("/api/Logs/detalle")]
|
[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();
|
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 (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);
|
var l = RepositorioLogs.Singleton.ObtenerDetallesLogs(fecha, idusuario);
|
||||||
List<LogDetalleDto> ll = new();
|
List<LogDetalleDto> ll = new();
|
||||||
foreach (var i in l) {
|
foreach (var i in l)
|
||||||
ll.Add(new LogDetalleDto{
|
{
|
||||||
|
ll.Add(new LogDetalleDto
|
||||||
|
{
|
||||||
Fecha = i.Fecha,
|
Fecha = i.Fecha,
|
||||||
Dniusuario = i.Dniusuario,
|
Dniusuario = i.Dniusuario,
|
||||||
NombreTabla = i.NombreTabla,
|
NombreTabla = i.NombreTabla,
|
||||||
@@ -51,12 +58,13 @@ public class LogsController: ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("/api/Logs/cantPag")]
|
[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();
|
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 (validacion1 == false) return Unauthorized();
|
||||||
|
|
||||||
int c = RepositorioLogs.Singleton.ObtenerCantidadPaginas();
|
int c = RepositorioLogs.Singleton.ObtenerCantidadPaginas();
|
||||||
return Ok(c);
|
return Ok(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
|
||||||
import BotonEsquina from "../Componentes/BotonEsquina.svelte";
|
import BotonEsquina from "../Componentes/BotonEsquina.svelte";
|
||||||
import ModalEditarPermiso from "../Componentes/ModalEditarPermiso.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") || "";
|
const token: string = sessionStorage.getItem("token") || "";
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ public class RepositorioPermisos : RepositorioBase<RepositorioPermisos>
|
|||||||
{
|
{
|
||||||
public IQueryable<Grupo>? ListarPermisos(string email)
|
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;
|
var con = Context;
|
||||||
Cliente? cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(c => c.Email == email);
|
Cliente? cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(c => c.Email == email);
|
||||||
if (cli == null) return null;
|
if (cli == null) return null;
|
||||||
@@ -47,19 +46,26 @@ public class RepositorioPermisos : RepositorioBase<RepositorioPermisos>
|
|||||||
Cliente? cli = con.Clientes.FirstOrDefault(x => x.Token == token);
|
Cliente? cli = con.Clientes.FirstOrDefault(x => x.Token == token);
|
||||||
if (cli == null || cli.Dni == 0) return false;
|
if (cli == null || cli.Dni == 0) return false;
|
||||||
|
|
||||||
var permisos = con.Clientes
|
var grupos = con.Clientes
|
||||||
.Where(x => x.Dni == cli.Dni)
|
.Where(x => x.Dni == cli.Dni)
|
||||||
.SelectMany(x => x.Idgrupos)
|
.SelectMany(x => x.Idgrupos)
|
||||||
.SelectMany(x => x.Idpermisos)
|
.Include(x => x.Idpermisos)
|
||||||
.Distinct();
|
.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;
|
tienePermiso = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return tienePermiso;
|
return tienePermiso;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user