From 370c8e85b4a904ce2174c16fdb0b795fb238db0a Mon Sep 17 00:00:00 2001 From: Sergio Date: Wed, 25 Mar 2026 08:00:59 +0100 Subject: [PATCH] cambios para multi url y generica --- .../Layout/ConfiguracionLayout.razor | 32 +- .../Components/Layout/DenegadoLayout.razor | 46 +++ .../Components/Layout/LoginLayout.razor | 34 +- .../Components/Layout/MainLayout.razor | 55 ++-- .../ConfiguracionPages/Enumeraciones.razor | 7 + .../EnumeracionesTabs/UrlsPermitidas.razor | 301 ++++++++++++++++++ .../Pages/Login/ClaveGenerada.razor | 2 +- .../Components/Pages/Login/Denegado.razor | 26 +- .../Components/Pages/Login/Login.razor | 13 +- .../Components/Pages/Login/NuevoAcceso.razor | 2 +- HerramientaCASA/UtilidadesCASA.cs | 26 ++ HerramientaCASA/appsettings.json | 12 +- bdHerramientaCACOA/db/urlspermitidas.cs | 13 + .../dbcontext/herramientascacoaContext.cs | 13 + bdHerramientaCACOA/efpt.config.json | 12 +- 15 files changed, 499 insertions(+), 95 deletions(-) create mode 100644 HerramientaCASA/Components/Layout/DenegadoLayout.razor create mode 100644 HerramientaCASA/Components/Pages/ConfiguracionPages/EnumeracionesTabs/UrlsPermitidas.razor create mode 100644 bdHerramientaCACOA/db/urlspermitidas.cs diff --git a/HerramientaCASA/Components/Layout/ConfiguracionLayout.razor b/HerramientaCASA/Components/Layout/ConfiguracionLayout.razor index 1932289..ad2c827 100644 --- a/HerramientaCASA/Components/Layout/ConfiguracionLayout.razor +++ b/HerramientaCASA/Components/Layout/ConfiguracionLayout.razor @@ -9,6 +9,7 @@ @inject UserState userState @inject IJSRuntime JS @using bdHerramientaCACOA.db +@inject UserState UserState @@ -46,7 +47,7 @@ @* *@ - + @@ -108,8 +109,8 @@ - @code { - +@code { + // protected override async Task OnInitializedAsync() // { @@ -148,28 +149,17 @@ bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false); urlAnterior = await JS.InvokeAsync("eval", "document.referrer"); - string urlColegio = bd.enumeraciones.First(x => x.Codigo.Contains("CW.URLCOLEGIO")).ValorAlfabetico1; - - if (!string.IsNullOrEmpty(urlAnterior)) + if (!UserState.PuedeAcceder) { rutaActual = Navigation.ToBaseRelativePath(Navigation.Uri); - - if (rutaActual != "Denegado") + if (!UtilidadesCASA.UrlPermitida(urlAnterior, bd)) { - if (urlColegio != null && !urlAnterior.Contains(urlColegio)) - { - Navigation.NavigateTo("/Denegado", true); - } + Navigation.NavigateTo("/Denegado", true); + } + else if (userState.idUser == 0) + { + Navigation.NavigateTo("/", true); } - } - else - { - Navigation.NavigateTo("/Denegado", true); - } - - if (userState.idUser == 0) - { - Navigation.NavigateTo("/", true); } StateHasChanged(); } diff --git a/HerramientaCASA/Components/Layout/DenegadoLayout.razor b/HerramientaCASA/Components/Layout/DenegadoLayout.razor new file mode 100644 index 0000000..2360f3a --- /dev/null +++ b/HerramientaCASA/Components/Layout/DenegadoLayout.razor @@ -0,0 +1,46 @@ +@inherits LayoutComponentBase +@using BlazorBootstrap; +@using HerramientaCASA.Model +@using Microsoft.AspNetCore.Components.Web +@inject UserState UserState +@inject IHttpContextAccessor HttpContextAccessor +@inject NavigationManager Navigation +@inject IJSRuntime JS +@using bdHerramientaCACOA.db + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ @Body +
+
+ + +@code{ + +} + + diff --git a/HerramientaCASA/Components/Layout/LoginLayout.razor b/HerramientaCASA/Components/Layout/LoginLayout.razor index eb639e9..3d64eb7 100644 --- a/HerramientaCASA/Components/Layout/LoginLayout.razor +++ b/HerramientaCASA/Components/Layout/LoginLayout.razor @@ -7,7 +7,7 @@ @inject NavigationManager Navigation @inject IJSRuntime JS @using bdHerramientaCACOA.db - +@inject UserState UserState @@ -53,32 +53,14 @@ { if (firstRender) { + urlAnterior = await JS.InvokeAsync("eval", "document.referrer"); - bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false); - string urlColegio = bd.enumeraciones.First(x => x.Codigo.Contains("CW.URLCOLEGIO")).ValorAlfabetico1; - - if (!string.IsNullOrEmpty(urlAnterior)) - { - - rutaActual = Navigation.ToBaseRelativePath(Navigation.Uri); - - - if (rutaActual != "Denegado") - { - if (urlColegio != null && !urlAnterior.Contains(urlColegio)) - { - Navigation.NavigateTo("/Denegado", true); - } - } - - } - else - { - if (urlColegio != null) - { - Navigation.NavigateTo("/Denegado", true); - } - } + //urlAnterior = "https://www.cacoa.es"; + bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false); + if (!UtilidadesCASA.UrlPermitida(urlAnterior,bd)) + { + Navigation.NavigateTo("/Denegado", true); + } StateHasChanged(); } } diff --git a/HerramientaCASA/Components/Layout/MainLayout.razor b/HerramientaCASA/Components/Layout/MainLayout.razor index 3ca9120..7b74d7f 100644 --- a/HerramientaCASA/Components/Layout/MainLayout.razor +++ b/HerramientaCASA/Components/Layout/MainLayout.razor @@ -9,6 +9,7 @@ @inject UserState userState @inject IJSRuntime JS @using bdHerramientaCACOA.db +@inject UserState UserState @@ -47,9 +48,12 @@ - - - + @if (nombreColegio != "CACOA") + { + + + + } + + +
+ +
+
+
diff --git a/HerramientaCASA/Components/Pages/ConfiguracionPages/EnumeracionesTabs/UrlsPermitidas.razor b/HerramientaCASA/Components/Pages/ConfiguracionPages/EnumeracionesTabs/UrlsPermitidas.razor new file mode 100644 index 0000000..0f720f1 --- /dev/null +++ b/HerramientaCASA/Components/Pages/ConfiguracionPages/EnumeracionesTabs/UrlsPermitidas.razor @@ -0,0 +1,301 @@ +@inject NavigationManager Navigation +@layout ConfiguracionLayout +@using BlazorBootstrap +@using System.Globalization +@using bdHerramientaCACOA.db + + + + + +
+ ¿Estás seguro que desea eliminarlo? +
+
+ + + + +
+ + + + + +
+
+ + +
+
@GetExternalValidationMessage(nameof(descripcionItem))
+
+ +
+
+ + +
+
+ +
+ + + + +
+
+ + + +
+ +
+ Estas son las urls que pueden redireccionar a la web, si no aparece aqui devuelve un acceso denegado + +
+ + + + + @context.descripcion + + + + @context.url + + +
+ + + + + + +
+
+
+
+
+ +@code { + + public List listadoUrls { get; set; } = new List(); + + [SupplyParameterFromForm] + private urlspermitidas itemSeleccionado { get; set; } = new bdHerramientaCACOA.db.urlspermitidas(); + + private string tituloPopup = ""; + private Modal popupGestionDatos = default!; + private Modal popupConfirmarBorrado = default!; + + private bool nuevoElemento; + + private string descripcionItem = ""; + private string urlItem = ""; + + List mensajes = new List(); + + private EditContext? editContext; + private ValidationMessageStore? messageStore; + public tsHerramientasCACOA bd; + + + protected override async Task OnInitializedAsync() + { + bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false); + + editContext = new EditContext(itemSeleccionado); + messageStore = new ValidationMessageStore(editContext); + + listadoUrls = bd.urlspermitidas.ToList(); + } + + + private async Task abrirPopupGestionDatos(bdHerramientaCACOA.db.urlspermitidas objeto, bool esNuevo) + { + itemSeleccionado = objeto; + + if (esNuevo) + { + nuevoElemento = true; + descripcionItem = ""; + urlItem = ""; + } + else + { + nuevoElemento = false; + descripcionItem = objeto.descripcion; + urlItem = objeto.url; + } + + if (!nuevoElemento) + { + tituloPopup = "Modificar Url"; + } + else + { + tituloPopup = "Nueva Url"; + } + + await popupGestionDatos.ShowAsync(); + } + private async Task cerrarPopupGestionDatos() + { + await popupGestionDatos.HideAsync(); + } + + private void ValidarYActualizar(ChangeEventArgs e, string fieldName) + { + var value = e.Value?.ToString(); + var field = new FieldIdentifier(itemSeleccionado, fieldName); + + switch (fieldName) + { + case nameof(descripcionItem): + if (!string.IsNullOrEmpty(value)) + { + + descripcionItem = value; + } + else + { + descripcionItem = ""; + } + break; + } + + messageStore?.Clear(field); + if (fieldName == nameof(descripcionItem) && descripcionItem == "") + { + messageStore?.Add(field, "La descripción no puede estar vacía."); + } + + editContext?.NotifyValidationStateChanged(); + } + + private void ValidarTodo() + { + ValidarYActualizar(new ChangeEventArgs { Value = descripcionItem }, nameof(descripcionItem)); + } + + private string GetExternalValidationMessage(string fieldName) + { + var field = new FieldIdentifier(itemSeleccionado, fieldName); + return messageStore?[field].FirstOrDefault() ?? string.Empty; + } + + private async Task GestionarDatos(string accion) + { + var urlExistente = bd.urlspermitidas.Where(x => x.idUrlsPermitidas == itemSeleccionado.idUrlsPermitidas).FirstOrDefault(); + switch (accion) + { + case "update": + urlExistente.descripcion = descripcionItem; + urlExistente.url = urlItem; + bd.urlspermitidas.Update(urlExistente); + + await cerrarPopupGestionDatos(); + + mensajes.Add(new ToastMessage + { + Type = ToastType.Primary, + Message = $"Actualizado correctamente.", + }); + + break; + + case "create": + itemSeleccionado.descripcion = descripcionItem; + itemSeleccionado.url = urlItem; + bd.urlspermitidas.Add(itemSeleccionado); + await cerrarPopupGestionDatos(); + mensajes.Add(new ToastMessage + { + Type = ToastType.Primary, + Message = $"Guardado correctamente.", + }); + break; + + case "delete": + bd.urlspermitidas.Remove(urlExistente); + await cerrarPopupConfirmarBorrado(); + mensajes.Add(new ToastMessage + { + Type = ToastType.Primary, + Message = $"Eliminado correctamente.", + }); + break; + } + bd.SaveChanges(); + listadoUrls = bd.urlspermitidas.ToList(); + await InvokeAsync(StateHasChanged); + } + + + private async Task BorrarItem() + { + await GestionarDatos("delete"); + } + //////// PopUp eliminar registro + private async Task abrirPopupConfirmarBorrado(bdHerramientaCACOA.db.urlspermitidas objeto) + { + itemSeleccionado = objeto; + await popupConfirmarBorrado.ShowAsync(); + } + private async Task cerrarPopupConfirmarBorrado() + { + await popupConfirmarBorrado.HideAsync(); + } + + // GUARDAR + private async Task guardarFormulario() + { + try + { + ValidarTodo(); + + if (!editContext!.GetValidationMessages().Any()) + { + string accion = nuevoElemento ? "create" : "update"; + await GestionarDatos(accion); + } + else + { + mensajes.Add(new ToastMessage + { + Type = ToastType.Warning, + Message = $"Debe rellenar los campos obligatorios.", + }); + } + + } + catch (Exception) + { + mensajes.Add(new ToastMessage + { + Type = ToastType.Danger, + Message = $"Error al guardar.", + }); + } + + } + + private void MostrarErrores() + { + messageStore?.Clear(); + foreach (var field in new[] { nameof(descripcionItem)}) + { + ValidarYActualizar(new ChangeEventArgs { Value = typeof(enumeraciones).GetProperty(field)?.GetValue(itemSeleccionado) }, field); + } + } +} \ No newline at end of file diff --git a/HerramientaCASA/Components/Pages/Login/ClaveGenerada.razor b/HerramientaCASA/Components/Pages/Login/ClaveGenerada.razor index 0acabed..33ee49b 100644 --- a/HerramientaCASA/Components/Pages/Login/ClaveGenerada.razor +++ b/HerramientaCASA/Components/Pages/Login/ClaveGenerada.razor @@ -12,7 +12,7 @@
- +

Clave Generada correctamente


Se ha generado su clave para utilizar la herramienta.Guarde su clave y contraseña en un lugar seguro. NO PUEDE RECUPERARSE

diff --git a/HerramientaCASA/Components/Pages/Login/Denegado.razor b/HerramientaCASA/Components/Pages/Login/Denegado.razor index e1f0ca0..f0cd884 100644 --- a/HerramientaCASA/Components/Pages/Login/Denegado.razor +++ b/HerramientaCASA/Components/Pages/Login/Denegado.razor @@ -3,18 +3,38 @@ @using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage @inject ProtectedLocalStorage ProtectedLocalStore @rendermode InteractiveServer -@layout LoginLayout @inject IHttpContextAccessor HttpContextAccessor @inject NavigationManager Navigation @inject UserState UserState +@layout DenegadoLayout - + + + + + + + + + + + + + + + + + + + + +
@* *@ - +

Acceso Denegado


diff --git a/HerramientaCASA/Components/Pages/Login/Login.razor b/HerramientaCASA/Components/Pages/Login/Login.razor index 941a17a..5857c59 100644 --- a/HerramientaCASA/Components/Pages/Login/Login.razor +++ b/HerramientaCASA/Components/Pages/Login/Login.razor @@ -17,9 +17,12 @@
-
- -
+ @if(nombreColegio!="CACOA") + { +
+ +
+ }

Acceso a la Herramienta

@@ -75,13 +78,13 @@ string rutaActual = ""; private byte[] logoColegioArray = []; - + private string nombreColegio = ""; protected override async Task OnInitializedAsync() { bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false); - + nombreColegio = bd.enumeraciones.First(x => x.Codigo == "CW.NOMBRECOLEGIO").ValorAlfabetico1; logoColegioArray = bd.ficheros.Where(x => x.NombreFichero == "LogoColegio").Select(x => x.Fichero).First(); await ProtectedLocalStore.SetAsync("idUsuario", 0); diff --git a/HerramientaCASA/Components/Pages/Login/NuevoAcceso.razor b/HerramientaCASA/Components/Pages/Login/NuevoAcceso.razor index 125293b..26bb5f4 100644 --- a/HerramientaCASA/Components/Pages/Login/NuevoAcceso.razor +++ b/HerramientaCASA/Components/Pages/Login/NuevoAcceso.razor @@ -12,7 +12,7 @@
- +

Crear Clave de acceso


Se va a generar una clave de acceso para acceder a la herramienta, tenga en cuenta que como no se almacena ningún dato de caracter personal le recomendamos que guarde la clave y contraseña para poder utilizarla.

diff --git a/HerramientaCASA/UtilidadesCASA.cs b/HerramientaCASA/UtilidadesCASA.cs index 3b1d1bc..0ab757f 100644 --- a/HerramientaCASA/UtilidadesCASA.cs +++ b/HerramientaCASA/UtilidadesCASA.cs @@ -12,6 +12,7 @@ using HerramientaCASA.ViewModel; using IbanNet; using Microsoft.AspNetCore.Components; using System.Text; +using tsUtilidades; using static bdHerramientaCACOA.CASA; using static HerramientaCASA.Components.Pages.ConfiguracionPages.ConvenioColectivo; @@ -19,6 +20,30 @@ namespace HerramientaCASA { public class UtilidadesCASA { + internal static List ListaUrls=new List(); + + public static void CargarListaUrls(tsHerramientasCACOA bd) { + List urlspermitidas=bd.urlspermitidas.ToList(); + foreach (var urls in urlspermitidas) { + ListaUrls.Add(urls.url); + } + } + public static bool UrlPermitida(String url, tsHerramientasCACOA bd) { + if (UtilidadesCASA.ListaUrls.Count==0) + { + UtilidadesCASA.CargarListaUrls(bd); + } + if (url == null && ListaUrls.Count > 0) + { + return false; + } + else if(ListaUrls.Count == 0) { + return true; + } + + return ListaUrls.Any(s => url.Contains(s)); + } + public static int crearObjeto(tsHerramientasCACOA bd, TiposSimulaciones tipoSimulacion, string jsonObjeto, string descripcion, string nombreFichero, int idUsuario) { int idtipoFichero = bd.enumeraciones.First(x => x.Codigo == "TIPFIC.JSON").idEnumeracion; @@ -144,6 +169,7 @@ namespace HerramientaCASA } + public static void actualizarFactorCorrecion(tsHerramientasCACOA bd, factorescorreccion factorCorrecc, factorescorreccion facturaEdit) { try diff --git a/HerramientaCASA/appsettings.json b/HerramientaCASA/appsettings.json index 3f6ca2f..ef33833 100644 --- a/HerramientaCASA/appsettings.json +++ b/HerramientaCASA/appsettings.json @@ -6,13 +6,17 @@ } }, "ConnectionStrings": { - //"WriteConnection": "Server=localhost;Port=22222;Database=herramientascacoa;User Id=cacoa;Password=cacoa2018-;", - //"ReadOnlyConnection": "Server=localhost;Port=22222;Database=herramientascacoa;User Id=cacoa;Password=cacoa2018-;" + "WriteConnection": "Server=localhost;Port=22222;Database=herramientascoaaragon;User Id=cacoa;Password=cacoa2018-;", + "ReadOnlyConnection": "Server=localhost;Port=22222;Database=herramientascoaaragon;User Id=cacoa;Password=cacoa2018-;" // CONEXIÓN CACOA //"WriteConnection": "Server=77.229.174.85;Port=22222;Database=herramientascacoa;User Id=cacoa;Password=cacoa2018-;", //"ReadOnlyConnection": "Server=77.229.174.85;Port=22222;Database=herramientascacoa;User Id=cacoa;Password=cacoa2018-;" + // CONEXIÓN Herramienta Cacoa Generica + //"WriteConnection": "Server=77.229.174.85;Port=22222;Database=herramientascacoagenerica;User Id=cacoa;Password=cacoa2018-;", + //"ReadOnlyConnection": "Server=77.229.174.85;Port=22222;Database=herramientascacoagenerica;User Id=cacoa;Password=cacoa2018-;", + // CONEXIÓN COACYLE //"WriteConnection": "Server=77.229.174.85;Port=22222;Database=herramientascoacyle;User Id=cacoa;Password=cacoa2018-;", //"ReadOnlyConnection": "Server=77.229.174.85;Port=22222;Database=herramientascoacyle;User Id=cacoa;Password=cacoa2018-;" @@ -30,8 +34,8 @@ //"ReadOnlyConnection": "Server=77.229.174.85;Port=22222;Database=herramientascoarioja;User Id=cacoa;Password=cacoa2018-;", // CONEXIÓN COAAragon - "WriteConnection": "Server=77.229.174.85;Port=22222;Database=herramientascoaaragon;User Id=cacoa;Password=cacoa2018-;", - "ReadOnlyConnection": "Server=77.229.174.85;Port=22222;Database=herramientascoaaragon;User Id=cacoa;Password=cacoa2018-;" + //"WriteConnection": "Server=77.229.174.85;Port=22222;Database=herramientascoaaragon;User Id=cacoa;Password=cacoa2018-;", + //"ReadOnlyConnection": "Server=77.229.174.85;Port=22222;Database=herramientascoaaragon;User Id=cacoa;Password=cacoa2018-;" //?? //"WriteConnection": "Server=localhost;Port=22222;Database=herramientascoacyle;User Id=cacoa;Password=cacoa2018-;", diff --git a/bdHerramientaCACOA/db/urlspermitidas.cs b/bdHerramientaCACOA/db/urlspermitidas.cs new file mode 100644 index 0000000..ed45db3 --- /dev/null +++ b/bdHerramientaCACOA/db/urlspermitidas.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace bdHerramientaCACOA.db; + +public partial class urlspermitidas +{ + public int idUrlsPermitidas { get; set; } + + public string? descripcion { get; set; } + + public string url { get; set; } = null!; +} diff --git a/bdHerramientaCACOA/dbcontext/herramientascacoaContext.cs b/bdHerramientaCACOA/dbcontext/herramientascacoaContext.cs index 87d3d64..f000c98 100644 --- a/bdHerramientaCACOA/dbcontext/herramientascacoaContext.cs +++ b/bdHerramientaCACOA/dbcontext/herramientascacoaContext.cs @@ -52,6 +52,8 @@ public partial class herramientascacoaContext : DbContext public virtual DbSet tipoproyectos { get; set; } + public virtual DbSet urlspermitidas { get; set; } + public virtual DbSet usuarios { get; set; } public virtual DbSet v_tipoproyecto_documentacion { get; set; } @@ -238,6 +240,8 @@ public partial class herramientascacoaContext : DbContext entity.HasIndex(e => e.idTipo, "IX_FK_fichero_tipo"); + entity.HasIndex(e => e.NombreFichero, "NombreFichero"); + entity.HasIndex(e => e.idFichero, "idFichero").IsUnique(); entity.Property(e => e.idFichero).HasColumnType("int(11)"); @@ -397,6 +401,15 @@ public partial class herramientascacoaContext : DbContext .HasConstraintName("FK_tipoproyectos_enumeraciones"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.idUrlsPermitidas).HasName("PRIMARY"); + + entity.Property(e => e.idUrlsPermitidas).HasColumnType("int(11)"); + entity.Property(e => e.descripcion).HasMaxLength(45); + entity.Property(e => e.url).HasMaxLength(250); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.idUsuario).HasName("PRIMARY"); diff --git a/bdHerramientaCACOA/efpt.config.json b/bdHerramientaCACOA/efpt.config.json index 2ddb13a..69c27c7 100644 --- a/bdHerramientaCACOA/efpt.config.json +++ b/bdHerramientaCACOA/efpt.config.json @@ -4,15 +4,18 @@ "ContextNamespace": null, "FilterSchemas": false, "IncludeConnectionString": false, - "MinimumProductVersion": "2.6.1080", + "IrregularWords": null, + "MinimumProductVersion": "2.6.1382", "ModelNamespace": null, "OutputContextPath": "dbcontext", "OutputPath": "db", + "PluralRules": null, "PreserveCasingWithRegex": true, "ProjectRootNamespace": "bdHerramientaCACOA", "Schemas": null, "SelectedHandlebarsLanguage": 2, "SelectedToBeGenerated": 0, + "SingularRules": null, "T4TemplatePath": null, "Tables": [ { @@ -95,6 +98,10 @@ "Name": "tipoproyectos", "ObjectType": 0 }, + { + "Name": "urlspermitidas", + "ObjectType": 0 + }, { "Name": "usuarios", "ObjectType": 0 @@ -130,5 +137,6 @@ "UseSchemaNamespaces": false, "UseSpatial": false, "UseT4": true, - "UseT4Split": false + "UseT4Split": false, + "UseTypedTvpParameters": true } \ No newline at end of file