From c1a27baedd11c44ac22bf1f59e43362b3f8a408f Mon Sep 17 00:00:00 2001 From: fede Date: Thu, 17 Apr 2025 13:24:07 -0300 Subject: [PATCH] =?UTF-8?q?avansando=20m=C3=A1s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DtoBuilder/GrupoyPermisoDtoBuilder.cs | 44 +++ Aspnet/Controllers/GruposController.cs | 26 +- Aspnet/Controllers/PermisoController.cs | 1 + Aspnet/bin/Debug/net8.0/settings.json | 5 +- Aspnet/settings.json | 5 +- Entidades/Alquilafacilcontext.cs | 14 +- Entidades/Dto/GrupoYPermisoDto.cs | 1 + Front/src/App.svelte | 276 +++++++++--------- .../Componentes/NavBarAutocompletable.svelte | 2 +- Front/src/Componentes/NavBarLogin.svelte | 77 ++--- Front/src/paginas/AdminGrupos.svelte | 101 ++++++- Front/src/paginas/VerLogs.svelte | 108 ++++--- Front/src/types.d.ts | 33 ++- Modelo/RepositorioGrupos.cs | 31 +- Modelo/RepositorioPermisos.cs | 15 +- 15 files changed, 477 insertions(+), 262 deletions(-) create mode 100644 Aspnet/Builder/DtoBuilder/GrupoyPermisoDtoBuilder.cs diff --git a/Aspnet/Builder/DtoBuilder/GrupoyPermisoDtoBuilder.cs b/Aspnet/Builder/DtoBuilder/GrupoyPermisoDtoBuilder.cs new file mode 100644 index 0000000..a7e3df4 --- /dev/null +++ b/Aspnet/Builder/DtoBuilder/GrupoyPermisoDtoBuilder.cs @@ -0,0 +1,44 @@ +using Entidades.Dto; + +namespace AlquilaFacil.Builder; +public class GrupoDtoBuilder : Builder +{ + public GrupoDtoBuilder ConNombre(string nombre) + { + data.Nombre = nombre; + return this; + } + + public GrupoDtoBuilder ConIdGrupo(int id) + { + data.idgrupo = id; + return this; + } + + public GrupoDtoBuilder ConGruposIncluidos(HashSet grupos) + { + data.GruposIncluidos = grupos; + return this; + } + + public GrupoDtoBuilder ConPermisos(List permisos) + { + data.Permisos = permisos; + return this; + } +} + +public class PermisoDtoBuilder : Builder +{ + public PermisoDtoBuilder ConId(int id) + { + data.Id = id; + return this; + } + + public PermisoDtoBuilder ConDescripcion(string descripcion) + { + data.Descripcion = descripcion; + return this; + } +} diff --git a/Aspnet/Controllers/GruposController.cs b/Aspnet/Controllers/GruposController.cs index 3208dea..5d12051 100644 --- a/Aspnet/Controllers/GruposController.cs +++ b/Aspnet/Controllers/GruposController.cs @@ -1,14 +1,36 @@ using Microsoft.AspNetCore.Mvc; using Modelo; +using AlquilaFacil.Builder; +using Entidades; + namespace AlquilaFacil.Controllers; [ApiController] public class GruposController : ControllerBase { - [HttpPost("api/admin/grupos")] + [HttpGet("api/admin/grupos")] public IActionResult ObtenerGrupos([FromHeader(Name = "Auth")] string Auth) - {//WIP + { + var ret = RepositorioPermisos.Singleton.CheckPermisos(Auth, 18); + if (ret == false) return BadRequest(new { message = "No tiene permiso para Gestionar grupos" }); + Cliente? cli = RepositorioUsuarios.Singleton.ObtenerClientePorToken(Auth); + if (cli == null) return BadRequest(new { message = "No hay un cliente por el token que enviaste" }); + var grupos = RepositorioGrupos.Singleton.ListarTodosLosGrupos() + .Select(g => new GrupoDtoBuilder() + .ConNombre(g.Nombre) + .ConIdGrupo(g.Id) + .ConGruposIncluidos(new HashSet(g.IdGrupoHijos + .Select(id => id.ToString() ?? ""))) + .ConPermisos(g.Idpermisos.Select(p => new PermisoDtoBuilder() + .ConId(p.Id) + .ConDescripcion(p.Descripcion) + .Build()) + .ToList()) + .Build()) + .ToList(); + + return Ok(grupos); } } diff --git a/Aspnet/Controllers/PermisoController.cs b/Aspnet/Controllers/PermisoController.cs index e502aa1..17cc326 100644 --- a/Aspnet/Controllers/PermisoController.cs +++ b/Aspnet/Controllers/PermisoController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Modelo; +using Entidades.Dto; namespace AlquilaFacil.Controllers; [ApiController] diff --git a/Aspnet/bin/Debug/net8.0/settings.json b/Aspnet/bin/Debug/net8.0/settings.json index ca7cba9..f44d236 100644 --- a/Aspnet/bin/Debug/net8.0/settings.json +++ b/Aspnet/bin/Debug/net8.0/settings.json @@ -1,4 +1,5 @@ { - "usr":"nwFNMLJcn5m0owbzeXMs", - "scrt":"Mf9HxTir5mIGwWSBtQXd6DRK2k00V0EyXk7QTu70" + "usr": "nwFNMLJcn5m0owbzeXMs", + "scrt": "Mf9HxTir5mIGwWSBtQXd6DRK2k00V0EyXk7QTu70", + "connectiondb": "Server=127.0.0.1;Port=3306;Database=AlquilaFacil;Uid=AlquilaFacil;Pwd=.n@9c2ve*0,b1ETv].Kipa/~pR~V;Connection Timeout=5;SslMode=none" } diff --git a/Aspnet/settings.json b/Aspnet/settings.json index ca7cba9..f44d236 100644 --- a/Aspnet/settings.json +++ b/Aspnet/settings.json @@ -1,4 +1,5 @@ { - "usr":"nwFNMLJcn5m0owbzeXMs", - "scrt":"Mf9HxTir5mIGwWSBtQXd6DRK2k00V0EyXk7QTu70" + "usr": "nwFNMLJcn5m0owbzeXMs", + "scrt": "Mf9HxTir5mIGwWSBtQXd6DRK2k00V0EyXk7QTu70", + "connectiondb": "Server=127.0.0.1;Port=3306;Database=AlquilaFacil;Uid=AlquilaFacil;Pwd=.n@9c2ve*0,b1ETv].Kipa/~pR~V;Connection Timeout=5;SslMode=none" } diff --git a/Entidades/Alquilafacilcontext.cs b/Entidades/Alquilafacilcontext.cs index 0d9ce17..ad46245 100644 --- a/Entidades/Alquilafacilcontext.cs +++ b/Entidades/Alquilafacilcontext.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.Text.Json; using Microsoft.EntityFrameworkCore; namespace Entidades; @@ -53,9 +54,16 @@ public partial class AlquilaFacilContext : DbContext public virtual DbSet Ventas { get; set; } + private class context + { + public string connectiondb { get; set; } = ""; + } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) -#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263. - => optionsBuilder.UseMySQL("Server=127.0.0.1;Port=3306;Database=AlquilaFacil;Uid=AlquilaFacil;Pwd=.n@9c2ve*0,b1ETv].Kipa/~pR~V;Connection Timeout=5;SslMode=none"); + { + context connection = JsonSerializer.Deserialize(File.ReadAllText("settings.json")) ?? new(); + optionsBuilder.UseMySQL(connection.connectiondb); + } protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/Entidades/Dto/GrupoYPermisoDto.cs b/Entidades/Dto/GrupoYPermisoDto.cs index 4017198..2764cca 100644 --- a/Entidades/Dto/GrupoYPermisoDto.cs +++ b/Entidades/Dto/GrupoYPermisoDto.cs @@ -1,3 +1,4 @@ +namespace Entidades.Dto; public class GrupoDto { public int idgrupo { get; set; } diff --git a/Front/src/App.svelte b/Front/src/App.svelte index 59f47f0..9c4747f 100644 --- a/Front/src/App.svelte +++ b/Front/src/App.svelte @@ -1,170 +1,174 @@ - - - + + + + + - - - - - - - - + + + - - - - + + + + - - - - + + + + - - - - - - - - - + + + + - - - + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - + + + + - - - - + + + + - - - - + + + + - - - - - - - - - + + + + - - - - + + + + - - - - - - - - - - - - - + + + + - - - - - - - - - + + + + - - - - + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - diff --git a/Front/src/Componentes/NavBarAutocompletable.svelte b/Front/src/Componentes/NavBarAutocompletable.svelte index 5640120..8af1fb2 100644 --- a/Front/src/Componentes/NavBarAutocompletable.svelte +++ b/Front/src/Componentes/NavBarAutocompletable.svelte @@ -87,7 +87,7 @@ } - + AlquilaFacil
diff --git a/Front/src/Componentes/NavBarLogin.svelte b/Front/src/Componentes/NavBarLogin.svelte index 343e94c..665f4b9 100644 --- a/Front/src/Componentes/NavBarLogin.svelte +++ b/Front/src/Componentes/NavBarLogin.svelte @@ -1,38 +1,47 @@ - - - - AlquilaFacil - -
- -
- (isOpen = !isOpen)} /> - - - + + AlquilaFacil +
+ +
+ (isOpen = !isOpen)} /> + + +
diff --git a/Front/src/paginas/AdminGrupos.svelte b/Front/src/paginas/AdminGrupos.svelte index 8a651db..88b15a5 100644 --- a/Front/src/paginas/AdminGrupos.svelte +++ b/Front/src/paginas/AdminGrupos.svelte @@ -1,6 +1,103 @@ - -
+
+ {#if grupos.length == 0} +
+
+ Loading... +
+
+ {:else} + {#each grupos as grupo} +
+
+

+ +

+
+
+
+
+
Grupos Incluidos
+
    + {#if grupo.gruposIncluidos.length == 0} +
  • + No hay grupos incluidos +
  • + {:else} + {#each grupo.gruposIncluidos as grupoIncluido} +
  • + {grupoIncluido} +
  • + {/each} + {/if} +
+
+
+
Permisos
+
    + {#if grupo.permisos.length == 0} +
  • + No hay grupos incluidos +
  • + {:else} + {#each grupo.permisos as permiso} +
  • + {permiso.descripcion} +
  • + {/each} + {/if} +
+
+
+
+
+ +
+
+
+
+
+ {/each} + {/if} +
diff --git a/Front/src/paginas/VerLogs.svelte b/Front/src/paginas/VerLogs.svelte index 532e78f..2e8bfd3 100644 --- a/Front/src/paginas/VerLogs.svelte +++ b/Front/src/paginas/VerLogs.svelte @@ -9,25 +9,25 @@ import PaginacionStepper from "../Componentes/PaginacionStepper.svelte"; let Logs: LogDto[] = $state([]); - let pagina:number = $state(1); - let token:string = sessionStorage.getItem("token")||""; - let modaldata:string = $state(""); - let showmodal:boolean =$state(false); - let ll:LogDto|any = $state({}); - let cantpag:number = $state(0); + let pagina: number = $state(1); + let token: string = sessionStorage.getItem("token") || ""; + let modaldata: string = $state(""); + let showmodal: boolean = $state(false); + let ll: LogDto | any = $state({}); + let cantpag: number = $state(0); - onMount(()=>{ + onMount(() => { obtenerLogs(); obtenerPaginas(); }); async function obtenerPaginas() { - try{ - const r = await fetch($urlG+"/api/Logs/cantPag", { + try { + const r = await fetch($urlG + "/api/Logs/cantPag", { method: "GET", headers: { - "Auth": token, - } + Auth: token, + }, }); let data = await r.json(); if (r.ok) { @@ -41,12 +41,12 @@ } async function obtenerLogs() { - try{ - const r = await fetch($urlG+"/api/Logs?pag="+pagina, { + try { + const r = await fetch($urlG + "/api/Logs?pag=" + pagina, { method: "GET", headers: { - "Auth": token, - } + Auth: token, + }, }); let data = await r.json(); if (r.ok) { @@ -63,49 +63,65 @@ ll = l; showmodal = true; } - function queryPag(a:number) { + function queryPag(a: number) { pagina = a; obtenerLogs(); } - + {#if modaldata} - !!(modaldata = "")}/> + !!(modaldata = "")} /> {/if} {#if showmodal} - !!(showmodal=!showmodal)} log={ll}/> + !!(showmodal = !showmodal)} log={ll} /> {/if}
- - - - - - - - - - - - {#each Logs as l} - - - - - - - {/each} - -
FechaId UsuarioAccion
{l.fecha}{l.dniusuario}{l.accion} - -
-
- + +
+ + + + + + + + + + + {#each Logs as l} + + + + + + + {/each} + +
FechaId UsuarioAccion
{l.fecha}{l.dniusuario}{l.accion} + +
+
+ +
diff --git a/Front/src/types.d.ts b/Front/src/types.d.ts index bc113a5..eb2e59d 100644 --- a/Front/src/types.d.ts +++ b/Front/src/types.d.ts @@ -24,7 +24,7 @@ export type PropiedadVentaDto = { export type AdminParametrosBusqueda = { cantidadhabitaciones: number=0, - tipopropiedad: number=0, + tipopropiedad: number=0, servicios: string="", pag: number=1 } @@ -77,7 +77,7 @@ export type MensajeDto = { mensaje: string, fecha: Date, propiedad: string, - + } export type GaranteDto = { @@ -187,9 +187,9 @@ export type LogDto = { export type LogDetalleDto = { fecha:Date, dniusuario:number, - nombreTabla:string, - columna:string, - valorAnterior:string, + nombreTabla:string, + columna:string, + valorAnterior:string, valorNuevo:string } @@ -208,14 +208,25 @@ export type setVenta = { } export type PatchPropiedad = { - id:number, + id:number, ubicacion:string, - canthabitaciones:number, - piso:number, - letra:string, - email:string, + canthabitaciones:number, + piso:number, + letra:string, + email:string, tipo:number, servicios: string[], monto:number, iddivisa:number -} \ No newline at end of file +} + +export type GrupoDto = { + idgrupo:number, + nombre:string, + gruposIncluidos:string[], + permisos:PermisoDto[] +} +export type PermisoDto = { + id:number, + descripcion:string +} diff --git a/Modelo/RepositorioGrupos.cs b/Modelo/RepositorioGrupos.cs index 2f5a476..795762f 100644 --- a/Modelo/RepositorioGrupos.cs +++ b/Modelo/RepositorioGrupos.cs @@ -3,29 +3,40 @@ using Entidades.Admin; using Microsoft.EntityFrameworkCore; namespace Modelo; -public class RepositorioGrupos: RepositorioBase { +public class RepositorioGrupos : RepositorioBase +{ - public IQueryable ListarPermisosDeGrupo(string grupo) { + public IQueryable ListarTodosLosGrupos() + { var con = Context; - return con.Grupos.Where(x=>x.Nombre == grupo).SelectMany(x => x.Idpermisos); + var grupos = con.Grupos.Include(x => x.IdGrupoHijos).ThenInclude(x => x.Idpermisos).Include(x => x.Idpermisos); + return grupos; + } + public IQueryable ListarPermisosDeGrupo(string grupo) + { + var con = Context; //WIP Revisar esto + return con.Grupos.Where(x => x.Nombre == grupo).SelectMany(x => x.Idpermisos); } - public IQueryable ObtenerGruposPorDni(long Dni) { + public IQueryable ObtenerGruposPorDni(long Dni) + { var con = Context; - var grupos = con.Clientes.Where(x=>x.Dni == Dni).SelectMany(x=>x.Idgrupos) - .Select(x=> new GrupoAdmin{ + var grupos = con.Clientes.Where(x => x.Dni == Dni).SelectMany(x => x.Idgrupos) + .Select(x => new GrupoAdmin + { Id = x.Id, Descripcion = x.Nombre, }); return grupos; } - public bool CheckGrupos(string token, string grupo){ + public bool CheckGrupos(string token, string grupo) + { var con = Context; - Cliente? cli = con.Clientes.Include(x=>x.Idgrupos).FirstOrDefault(x=>x.Token == token); + Cliente? cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(x => x.Token == token); if (cli == null) return false; - Grupo? gru = con.Grupos.FirstOrDefault(x=>x.Nombre == grupo); + Grupo? gru = con.Grupos.FirstOrDefault(x => x.Nombre == grupo); if (gru == null) return false; if (cli.Idgrupos.Contains(gru)) return true; @@ -33,4 +44,4 @@ public class RepositorioGrupos: RepositorioBase { return false; } -} \ No newline at end of file +} diff --git a/Modelo/RepositorioPermisos.cs b/Modelo/RepositorioPermisos.cs index bb0ffa8..1ac508a 100644 --- a/Modelo/RepositorioPermisos.cs +++ b/Modelo/RepositorioPermisos.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; namespace Modelo; public class RepositorioPermisos : RepositorioBase { - public object? ListarPermisos(string email) + public IQueryable? ListarPermisos(string email) { var con = Context; Cliente? cli = con.Clientes.Include(x => x.Idgrupos).FirstOrDefault(c => c.Email == email); @@ -21,31 +21,20 @@ public class RepositorioPermisos : RepositorioBase public bool CheckPermisos(string token, int idpermiso) { - // Aca tengo que modificar esto para que haga una busqueda de profundidad para los permisos + //WIP Aca tengo que modificar esto para que haga una busqueda de profundidad para los permisos // var con = Context; bool tienePermiso = false; - //checkeo que el token corresponda a un usuario Cliente? cli = con.Clientes.FirstOrDefault(x => x.Token == token); if (cli == null || cli.Dni == 0) return false; - // obtengo una lista de los permisos var permisos = con.Clientes .Where(x => x.Dni == cli.Dni) .SelectMany(x => x.Idgrupos) .SelectMany(x => x.Idpermisos) .Distinct(); - ///////////////////////////////////////////////////////////////// - //Esto esta comentado porque antes pasaba el string del path de la url, es una mala idea a muchos niveles - // abajo un comentario viejo mio - ///////////////////////////////////////////////////////////////// - //me inspiré y hice un regex pero si eliminaba los primeros 8(?) caracteres del string era lo mismo - //Match match = Regex.Match(path, @"^/accion/(\d+)$"); - //int.TryParse(match.Groups[1].Value, out int idpermiso); - ///////////////////////////////////////////////////////////////// - Parallel.ForEach(permisos, (x, i) => { if (x.Id == idpermiso)