From 71fc5a81d4c64b391a6cd112616c91ead16dd468 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 16 Apr 2025 17:44:34 +0200 Subject: [PATCH] SPEC: - fix gestione permessi x nagMan + check buttons --- MP-SPEC.sln | 6 + MP.Data/Controllers/MpIocController.cs | 6 +- MP.Data/Controllers/MpSpecController.cs | 14 +- .../{LinkMenuJQM.cs => LinkMenuModel.cs} | 10 +- MP.Data/DbModels/WipSetupKitModel.cs | 4 +- MP.Data/MP.Data.csproj | 1 + MP.Data/MoonProContext.cs | 2 +- MP.Data/MoonPro_STATSContext.cs | 4 +- MP.Data/Services/ListSelectDataSrv.cs | 16 +- MP.Data/Services/MessageService.cs | 147 +++++++++--------- MP.Data/Services/SharedMemService.cs | 8 +- MP.SPEC/Components/CmpTop.razor | 2 - MP.SPEC/Components/CmpTop.razor.cs | 31 +++- MP.SPEC/Components/Reparti/ListReparti.razor | 2 +- .../Components/Reparti/ListReparti.razor.cs | 17 ++ MP.SPEC/Data/MpDataService.cs | 2 +- MP.SPEC/Data/MsgServiceSpec.cs | 43 ++++- MP.SPEC/MP.SPEC.csproj | 3 +- MP.SPEC/Pages/ForceReset.razor | 65 ++++---- MP.SPEC/Pages/Index.razor | 12 +- MP.SPEC/Pages/Index.razor.cs | 37 ++--- MP.SPEC/Program.cs | 2 + MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- MP.SPEC/Shared/NavMenu.razor | 18 +-- MP.SPEC/Shared/NavMenu.razor.cs | 17 +- MP.SPEC/appsettings.Production.json | 1 + MP.SPEC/appsettings.json | 1 + 29 files changed, 291 insertions(+), 186 deletions(-) rename MP.Data/DbModels/{LinkMenuJQM.cs => LinkMenuModel.cs} (75%) diff --git a/MP-SPEC.sln b/MP-SPEC.sln index f1a6e497..372702e5 100644 --- a/MP-SPEC.sln +++ b/MP-SPEC.sln @@ -16,6 +16,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.Core", "MP.Core\MP.Core. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.TaskMan", "MP.TaskMan\MP.TaskMan.csproj", "{1887A0C0-679E-4535-90D4-60DAA428D019}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MP.AppAuth", "MP.AppAuth\MP.AppAuth.csproj", "{5D73F0E2-7D1E-09BA-DB9D-EEC7A88766EE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -38,6 +40,10 @@ Global {1887A0C0-679E-4535-90D4-60DAA428D019}.Debug|Any CPU.Build.0 = Debug|Any CPU {1887A0C0-679E-4535-90D4-60DAA428D019}.Release|Any CPU.ActiveCfg = Release|Any CPU {1887A0C0-679E-4535-90D4-60DAA428D019}.Release|Any CPU.Build.0 = Release|Any CPU + {5D73F0E2-7D1E-09BA-DB9D-EEC7A88766EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D73F0E2-7D1E-09BA-DB9D-EEC7A88766EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D73F0E2-7D1E-09BA-DB9D-EEC7A88766EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D73F0E2-7D1E-09BA-DB9D-EEC7A88766EE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MP.Data/Controllers/MpIocController.cs b/MP.Data/Controllers/MpIocController.cs index 08a2e66e..fb314801 100644 --- a/MP.Data/Controllers/MpIocController.cs +++ b/MP.Data/Controllers/MpIocController.cs @@ -178,16 +178,16 @@ namespace MP.Data.Controllers } - public List ListLinkFilt(string tipoLink) + public List ListLinkFilt(string tipoLink) { - List dbResult = new List(); + List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) { dbResult = dbCtx .DbSetLinkMenu .Where(x => x.TipoLink == tipoLink) .AsNoTracking() - .OrderBy(x => x.ordine) + .OrderBy(x => x.Ordine) .ToList(); } return dbResult; diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index fb467053..1e3a8bf4 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -659,7 +659,7 @@ namespace MP.Data.Controllers /// Elenco valori link (x home e navMenu laterale) /// /// - public List ElencoLink() + public List ElencoLink() { return ListLinkFilt("SpecLink"); } @@ -1166,15 +1166,15 @@ namespace MP.Data.Controllers /// /// /// - public List ListLinkAll() + public List ListLinkAll() { - List dbResult = new List(); + List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) { dbResult = dbCtx .DbSetLinkMenu .AsNoTracking() - .OrderBy(x => x.ordine) + .OrderBy(x => x.Ordine) .ToList(); } return dbResult; @@ -1185,16 +1185,16 @@ namespace MP.Data.Controllers /// /// /// - public List ListLinkFilt(string tipoLink) + public List ListLinkFilt(string tipoLink) { - List dbResult = new List(); + List dbResult = new List(); using (var dbCtx = new MoonProContext(_configuration)) { dbResult = dbCtx .DbSetLinkMenu .Where(x => x.TipoLink == tipoLink) .AsNoTracking() - .OrderBy(x => x.ordine) + .OrderBy(x => x.Ordine) .ToList(); } return dbResult; diff --git a/MP.Data/DbModels/LinkMenuJQM.cs b/MP.Data/DbModels/LinkMenuModel.cs similarity index 75% rename from MP.Data/DbModels/LinkMenuJQM.cs rename to MP.Data/DbModels/LinkMenuModel.cs index 190aefa5..7199ba71 100644 --- a/MP.Data/DbModels/LinkMenuJQM.cs +++ b/MP.Data/DbModels/LinkMenuModel.cs @@ -11,7 +11,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace MP.Data.DbModels { [Table("LinkMenuJQM")] - public partial class LinkMenu + public partial class LinkMenuModel { #region Public Properties @@ -21,7 +21,8 @@ namespace MP.Data.DbModels [MaxLength(50)] public string TipoLink { get; set; } = ""; - public int ordine { get; set; } = 0; + [Column("Ordine")] + public int Ordine { get; set; } = 0; [MaxLength(50)] public string Testo { get; set; } = ""; @@ -29,8 +30,11 @@ namespace MP.Data.DbModels [MaxLength(50)] public string NavigateUrl { get; set; } = ""; + [MaxLength(50), Column("icona")] + public string Icona { get; set; } = ""; + [MaxLength(50)] - public string icona { get; set; } = ""; + public string Ruolo { get; set; } = ""; #endregion Public Properties diff --git a/MP.Data/DbModels/WipSetupKitModel.cs b/MP.Data/DbModels/WipSetupKitModel.cs index 23bda074..8f7d3cf3 100644 --- a/MP.Data/DbModels/WipSetupKitModel.cs +++ b/MP.Data/DbModels/WipSetupKitModel.cs @@ -26,7 +26,7 @@ namespace MP.Data.DbModels public string KeyFilt { get; set; } = "-"; /// - /// Cod esterno ordine (KeyRif ordine ERP) + /// Cod esterno Ordine (KeyRif Ordine ERP) /// [MaxLength(50)] public string CodOrd { get; set; } = ""; @@ -48,7 +48,7 @@ namespace MP.Data.DbModels public string DescArt { get; set; } = ""; /// - /// Quantità articoli dell'ordine + /// Quantità articoli dell'Ordine /// public int Qta { get; set; } = 0; diff --git a/MP.Data/MP.Data.csproj b/MP.Data/MP.Data.csproj index 3ed60f6e..657533b0 100644 --- a/MP.Data/MP.Data.csproj +++ b/MP.Data/MP.Data.csproj @@ -51,6 +51,7 @@ + diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index 13bbab60..a7e01fcf 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -48,7 +48,7 @@ namespace MP.Data public virtual DbSet DbSetAnagTags { get; set; } public virtual DbSet DbSetArticoli { get; set; } public virtual DbSet DbSetConfig { get; set; } - public virtual DbSet DbSetLinkMenu { get; set; } + public virtual DbSet DbSetLinkMenu { get; set; } public virtual DbSet DbSetListValues { get; set; } public virtual DbSet DbSetMacchine { get; set; } public virtual DbSet DbSetMSE { get; set; } diff --git a/MP.Data/MoonPro_STATSContext.cs b/MP.Data/MoonPro_STATSContext.cs index fad0fc99..453fe4e2 100644 --- a/MP.Data/MoonPro_STATSContext.cs +++ b/MP.Data/MoonPro_STATSContext.cs @@ -393,12 +393,12 @@ namespace MP.Data entity.Property(e => e.KeyRichiesta) .IsRequired() .HasMaxLength(50) - .HasComment("Chiave: ordine esterno o KIT"); + .HasComment("Chiave: Ordine esterno o KIT"); entity.Property(e => e.KeyRichiestaParent) .IsRequired() .HasDefaultValueSql("('')") - .HasComment("Chiave: ordine esterno o KIT"); + .HasComment("Chiave: Ordine esterno o KIT"); entity.Property(e => e.PzPallet).HasDefaultValueSql("((1))"); diff --git a/MP.Data/Services/ListSelectDataSrv.cs b/MP.Data/Services/ListSelectDataSrv.cs index 2c73b604..6c8c41d6 100644 --- a/MP.Data/Services/ListSelectDataSrv.cs +++ b/MP.Data/Services/ListSelectDataSrv.cs @@ -163,18 +163,18 @@ namespace MP.Data.Services /// Elenco link JQM (totale) /// /// - public async Task> ListLinkAll() + public async Task> ListLinkAll() { string source = "DB"; Stopwatch sw = new Stopwatch(); sw.Start(); - List? result = new List(); + List? result = new List(); // cerco in redis... string currKey = $"{redisBaseKey}:Menu:ALL"; RedisValue rawData = await redisDb.StringGetAsync(currKey); if (rawData.HasValue) { - result = JsonConvert.DeserializeObject>($"{rawData}"); + result = JsonConvert.DeserializeObject>($"{rawData}"); source = "REDIS"; } else @@ -186,7 +186,7 @@ namespace MP.Data.Services } if (result == null) { - result = new List(); + result = new List(); } sw.Stop(); Log.Debug($"ListLinkAll | tipoLink: * | {source} | {sw.Elapsed.TotalMilliseconds}ms"); @@ -198,19 +198,19 @@ namespace MP.Data.Services /// /// /// - public async Task> ListLinkFilt(string tipoLink) + public async Task> ListLinkFilt(string tipoLink) { string source = "DB"; Stopwatch sw = new Stopwatch(); sw.Start(); - List? result = new List(); + List? result = new List(); // cerco in redis... string currKey = $"{redisBaseKey}:Menu:{tipoLink}"; RedisValue rawData = await redisDb.StringGetAsync(currKey); //if (!string.IsNullOrEmpty($"{rawData}")) if (rawData.HasValue) { - result = JsonConvert.DeserializeObject>($"{rawData}"); + result = JsonConvert.DeserializeObject>($"{rawData}"); source = "REDIS"; } else @@ -222,7 +222,7 @@ namespace MP.Data.Services } if (result == null) { - result = new List(); + result = new List(); } sw.Stop(); Log.Debug($"ListLinkFilt | tipoLink: {tipoLink} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); diff --git a/MP.Data/Services/MessageService.cs b/MP.Data/Services/MessageService.cs index 70a616cd..7d1a7aae 100644 --- a/MP.Data/Services/MessageService.cs +++ b/MP.Data/Services/MessageService.cs @@ -1,8 +1,10 @@ using Blazored.LocalStorage; using Blazored.SessionStorage; using EgwCoreLib.Utils; +using Microsoft.AspNetCore.Components; using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal; using Microsoft.Extensions.Configuration; +using MP.AppAuth.Services; using MP.Data.Controllers; using MP.Data.DbModels; using MP.Data.DTO; @@ -28,54 +30,6 @@ namespace MP.Data.Services #endregion Public Fields - #region Protected Fields - - protected const string KeyDevIp4 = "DevIpv4"; - - protected const string KeyDevSec = "DevSec"; - - protected const string KeyMacDict = "MachineDict"; - - protected static IConfiguration _configuration = null!; - - /// - /// Oggetto per connessione a REDIS - /// - protected ConnectionMultiplexer redisConn = null!; - - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - protected IDatabase redisDb = null!; - - #endregion Protected Fields - - #region Private Fields - - private AnagOperatoriModel? _rigaOper; - - /// - /// Durata cache lunga IN SECONDI - /// - private int cacheTtlLong = 60 * 5; - - /// - /// Durata cache breve IN SECONDI - /// - private int cacheTtlShort = 60 * 1; - - private string lastIdxMacc = ""; - - private DateTime lastUserUpd = DateTime.Now; - - private Logger Log = LogManager.GetCurrentClassLogger(); - - private string redisBaseKey = "MP:TAB:User"; - - private Random rnd = new Random(); - - #endregion Private Fields - #region Public Constructors public MessageService(IConfiguration configuration, ILocalStorageService genLocalStorage, ISessionStorageService sessStore, TabDataService tdService, SharedMemService smServ) @@ -149,6 +103,11 @@ namespace MP.Data.Services public DateTime dtLastAction { get; set; } = DateTime.Now; public DateTime dtLastSave { get; set; } = DateTime.Now; + /// + /// Semaforo x indicare fasi di reload attive e così non effettuare alcune operazioni... + /// + public bool IsReloading { get; set; } = false; + public string LastIdxMacchina { get @@ -225,6 +184,11 @@ namespace MP.Data.Services } } + /// + /// Diritti utente (solo Funzione/Ruolo) + /// + public List UserRight { get; set; } = new List(); + /// /// Dizionario totale preferenze utente /// @@ -254,23 +218,6 @@ namespace MP.Data.Services #endregion Public Properties - #region Protected Properties - - protected int expDays { get; set; } = 0; - protected ILocalStorageService localStorage { get; set; } = null!; - protected ISessionStorageService sessionStore { get; set; } = null!; - protected SharedMemService SMService { get; set; } = null!; - protected TabDataService TDService { get; set; } = null!; - - #endregion Protected Properties - - #region Private Properties - - private List? userListMachine { get; set; } = null; - private Dictionary UserPrefs { get; set; } = new Dictionary(); - - #endregion Private Properties - #region Public Methods public async Task ClearLocalStor() @@ -411,11 +358,6 @@ namespace MP.Data.Services return answ; } - /// - /// Semaforo x indicare fasi di reload attive e così non effettuare alcune operazioni... - /// - public bool IsReloading { get; set; } = false; - /// /// Restituisce il record OperatoreDTO da localstorage /// @@ -708,6 +650,71 @@ namespace MP.Data.Services #endregion Public Methods + #region Protected Fields + + protected const string KeyDevIp4 = "DevIpv4"; + + protected const string KeyDevSec = "DevSec"; + + protected const string KeyMacDict = "MachineDict"; + + protected static IConfiguration _configuration = null!; + + /// + /// Oggetto per connessione a REDIS + /// + protected ConnectionMultiplexer redisConn = null!; + + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + protected IDatabase redisDb = null!; + + #endregion Protected Fields + + #region Protected Properties + + protected int expDays { get; set; } = 0; + protected ILocalStorageService localStorage { get; set; } = null!; + protected ISessionStorageService sessionStore { get; set; } = null!; + protected SharedMemService SMService { get; set; } = null!; + protected TabDataService TDService { get; set; } = null!; + + #endregion Protected Properties + + #region Private Fields + + private AnagOperatoriModel? _rigaOper; + + /// + /// Durata cache lunga IN SECONDI + /// + private int cacheTtlLong = 60 * 5; + + /// + /// Durata cache breve IN SECONDI + /// + private int cacheTtlShort = 60 * 1; + + private string lastIdxMacc = ""; + + private DateTime lastUserUpd = DateTime.Now; + + private Logger Log = LogManager.GetCurrentClassLogger(); + + private string redisBaseKey = "MP:TAB:User"; + + private Random rnd = new Random(); + + #endregion Private Fields + + #region Private Properties + + private List? userListMachine { get; set; } = null; + private Dictionary UserPrefs { get; set; } = new Dictionary(); + + #endregion Private Properties + #region Private Methods private string machineMse(string idxMacc) diff --git a/MP.Data/Services/SharedMemService.cs b/MP.Data/Services/SharedMemService.cs index 6b7b432f..0438584b 100644 --- a/MP.Data/Services/SharedMemService.cs +++ b/MP.Data/Services/SharedMemService.cs @@ -64,7 +64,7 @@ namespace MP.Data.Services /// /// Dizionario Menu /// - public Dictionary> DictMenu { get; set; } = new Dictionary>(); + public Dictionary> DictMenu { get; set; } = new Dictionary>(); /// /// Dizionario Stati (codice, record completo) @@ -110,7 +110,7 @@ namespace MP.Data.Services #region Private Properties - private List AllMenuData { get; set; } = new List(); + private List AllMenuData { get; set; } = new List(); #endregion Private Properties @@ -123,7 +123,7 @@ namespace MP.Data.Services { DictMacchine = new Dictionary(); DictMacchMulti = new Dictionary(); - DictMenu = new Dictionary>(); + DictMenu = new Dictionary>(); DbConfig = new List(); DictConfig = new Dictionary(); DictEventi = new Dictionary(); @@ -254,7 +254,7 @@ namespace MP.Data.Services /// /// Effettua setup memorie menu recuperando dati dal DB + popolando dizionario x livelli /// - public void SetupMenu(List AllData) + public void SetupMenu(List AllData) { // svuoto i valori in essere DictMenu.Clear(); diff --git a/MP.SPEC/Components/CmpTop.razor b/MP.SPEC/Components/CmpTop.razor index 7eb87b12..7d7009c8 100644 --- a/MP.SPEC/Components/CmpTop.razor +++ b/MP.SPEC/Components/CmpTop.razor @@ -3,8 +3,6 @@ @using System.Security.Claims @using Microsoft.AspNetCore.Components.Authorization -@inject AuthenticationStateProvider AuthenticationStateProvider -@inject MsgServiceSpec MService
diff --git a/MP.SPEC/Components/CmpTop.razor.cs b/MP.SPEC/Components/CmpTop.razor.cs index ab236b90..74cd7038 100644 --- a/MP.SPEC/Components/CmpTop.razor.cs +++ b/MP.SPEC/Components/CmpTop.razor.cs @@ -1,7 +1,10 @@ +using Amazon.Runtime.Internal.Endpoints.StandardLibrary; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.JSInterop; +using MP.AppAuth.Services; using MP.SPEC.Data; +using System; namespace MP.SPEC.Components { @@ -14,6 +17,7 @@ namespace MP.SPEC.Components await Task.Delay(1); await MDService.FlushRedisCache(); await Task.Delay(1); + await ForceReload(); // rimando a pagina corrente NavManager.NavigateTo(NavManager.Uri, true); } @@ -28,6 +32,10 @@ namespace MP.SPEC.Components [Inject] protected MpDataService MDService { get; set; } = null!; + [Inject] + protected AuthenticationStateProvider AuthStateProv { get; set; } = null!; + [Inject] + protected MsgServiceSpec MService { get; set; } = null!; #endregion Protected Properties @@ -35,7 +43,7 @@ namespace MP.SPEC.Components protected override async Task OnInitializedAsync() { - await forceReload(); + await ForceReload(); } #endregion Protected Methods @@ -50,19 +58,36 @@ namespace MP.SPEC.Components [Inject] private NavigationManager NavManager { get; set; } = null!; + [Inject] + private MsgServiceSpec MsgServ { get; set; } = null!; + [Inject] + protected AppAuthService AAService { get; set; } = null!; #endregion Private Properties #region Private Methods - private async Task forceReload() + private async Task ForceReload() { - var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + var authState = await AuthStateProv.GetAuthenticationStateAsync(); var user = authState.User; if (user.Identity != null && user.Identity.IsAuthenticated) { userName = $"{user.Identity.Name}"; + // salvo username in msgService + var userData = userName.Split(@"\"); + if (userData.Length > 1) + { + MsgServ.DomainName = userData[0]; + MsgServ.UserName = userData[1]; + // recupero diritti e salvo... + var UserRightList = await AAService.DirittiGetByUser(MsgServ.UserName); + if (UserRightList != null) + { + MsgServ.UserRight = UserRightList.Select(x => x.Funzione).ToList(); + } + } } else { diff --git a/MP.SPEC/Components/Reparti/ListReparti.razor b/MP.SPEC/Components/Reparti/ListReparti.razor index c9a1962f..05f03dfe 100644 --- a/MP.SPEC/Components/Reparti/ListReparti.razor +++ b/MP.SPEC/Components/Reparti/ListReparti.razor @@ -5,7 +5,7 @@

Elenco Reparti

- @if (SelRecord == null) + @if (SelRecord == null && IsSuperAdmin) { } diff --git a/MP.SPEC/Components/Reparti/ListReparti.razor.cs b/MP.SPEC/Components/Reparti/ListReparti.razor.cs index f50be82b..0b85388b 100644 --- a/MP.SPEC/Components/Reparti/ListReparti.razor.cs +++ b/MP.SPEC/Components/Reparti/ListReparti.razor.cs @@ -4,6 +4,7 @@ using Microsoft.JSInterop; using MP.Core.DTO; using MP.Data.DbModels; using MP.SPEC.Data; +using MP.AppAuth.Services; namespace MP.SPEC.Components.Reparti { @@ -29,9 +30,16 @@ namespace MP.SPEC.Components.Reparti [Inject] protected MpDataService MDService { get; set; } = null!; + [Inject] + protected MsgServiceSpec MsgService { get; set; } = null!; #endregion Protected Properties + protected bool IsSuperAdmin + { + get => HasRole(AppAuthService.RoleSuperAdmin); + } + #region Protected Methods protected override void OnInitialized() @@ -41,6 +49,15 @@ namespace MP.SPEC.Components.Reparti numRecord = 10; } + /// + /// Verifica ruolo utente + /// + /// + /// + protected bool HasRole(string Ruolo) + { + return MsgService.HasRole(Ruolo); + } protected override void OnParametersSet() { isLoading = true; diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 33f21645..9519e703 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -788,7 +788,7 @@ namespace MP.SPEC.Data return result; } - public Task> ElencoLink() + public Task> ElencoLink() { return Task.FromResult(dbController.ElencoLink()); } diff --git a/MP.SPEC/Data/MsgServiceSpec.cs b/MP.SPEC/Data/MsgServiceSpec.cs index d4d314e3..559804e1 100644 --- a/MP.SPEC/Data/MsgServiceSpec.cs +++ b/MP.SPEC/Data/MsgServiceSpec.cs @@ -1,4 +1,6 @@ -namespace MP.SPEC.Data +using MP.AppAuth.Models; + +namespace MP.SPEC.Data { public class MsgServiceSpec { @@ -9,12 +11,18 @@ #endregion Public Events #region Public Properties + + /// + /// Dominio utente + /// + public string DomainName { get; set; } = ""; + public string newBCMsg { get => _newBCMsg; set { - if(_newBCMsg != value) + if (_newBCMsg != value) { _newBCMsg = value; reportMsg(); @@ -22,6 +30,33 @@ } } + /// + /// Username utente + /// + public string UserName { get; set; } = ""; + + /// + /// Diritti utente (solo Funzione/Ruolo) + /// + public List UserRight { get; set; } = new List(); + + /// + /// Verifica ruolo utente + /// + /// + /// + public bool HasRole(string Ruolo) + { + bool answ = false; + if (UserRight != null && UserRight.Count > 0) + { + answ = UserRight + .Where(x => x.Equals(Ruolo, StringComparison.InvariantCultureIgnoreCase)) + .Count() > 0; + } + return answ; + } + #endregion Public Properties #region Protected Methods @@ -36,10 +71,6 @@ #endregion Protected Methods - #region Private Fields - - #endregion Private Fields - #region Private Properties private string _newBCMsg { get; set; } = ""; diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index d71fcd4b..c0036644 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2504.1612 + 6.16.2504.1617 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en @@ -52,6 +52,7 @@ + diff --git a/MP.SPEC/Pages/ForceReset.razor b/MP.SPEC/Pages/ForceReset.razor index 2b51deed..3d209938 100644 --- a/MP.SPEC/Pages/ForceReset.razor +++ b/MP.SPEC/Pages/ForceReset.razor @@ -1,4 +1,5 @@ @page "/force-reset" +@using MP.AppAuth.Services @using MP.SPEC.Data
@@ -25,6 +26,10 @@ protected MsgServiceSpec MsgServ { get; set; } = null!; [Inject] protected MpDataService MDService { get; set; } = null!; + [Inject] + protected AuthenticationStateProvider AuthStateProv { get; set; } = null!; + [Inject] + protected AppAuthService AAService { get; set; } = null!; private int currVal = 0; private int nextVal = 0; @@ -42,37 +47,12 @@ nextVal = 10; await InvokeAsync(StateHasChanged); await Task.Delay(bDelay); - // title = "Clearing Local Browser Data"; - // currVal = 10; - // nextVal = 30;loca - // await InvokeAsync(StateHasChanged); - // await MsgServ.ClearLocalStor(); - // await Task.Delay(bDelay); - // title = "Clearing Session Browser Data"; - // currVal = 30; - // nextVal = 50; - // await InvokeAsync(StateHasChanged); - // await MsgServ.ClearSessionStor(); - // await Task.Delay(bDelay); - // title = "Final Cache cleanup..."; - // currVal = 50; - // nextVal = 80; - // MsgServ.RigaOper = null; - // MsgServ.LastIdxMacchina = ""; - // await InvokeAsync(StateHasChanged); - // await Task.Delay(2 * bDelay); - // // attendo - // title = "Reload!"; - // currVal = 80; - // nextVal = 100; - // await InvokeAsync(StateHasChanged); - // // rimando alla home... - // await Task.Delay(bDelay); - // NavMan.NavigateTo("Index", true); - - - await Task.Delay(bDelay); - await MDService.FlushRedisCache(); + title = "UserDataReload..."; + currVal = 50; + nextVal = 80; + await ForceReload(); + await InvokeAsync(StateHasChanged); + await Task.Delay(2 * bDelay); title = "Reload!"; currVal = 80; nextVal = 100; @@ -81,4 +61,27 @@ // rimando a pagina corrente NavMan.NavigateTo("Index", true); } + + private async Task ForceReload() + { + var authState = await AuthStateProv.GetAuthenticationStateAsync(); + var user = authState.User; + if (user.Identity != null && user.Identity.IsAuthenticated) + { + string userName = $"{user.Identity.Name}"; + // salvo username in msgService + var userData = userName.Split(@"\"); + if (userData.Length > 1) + { + MsgServ.DomainName = userData[0]; + MsgServ.UserName = userData[1]; + // recupero diritti e salvo... + var UserRightList = await AAService.DirittiGetByUser(MsgServ.UserName); + if (UserRightList != null) + { + MsgServ.UserRight = UserRightList.Select(x => x.Funzione).ToList(); + } + } + } + } } diff --git a/MP.SPEC/Pages/Index.razor b/MP.SPEC/Pages/Index.razor index 363048ba..eebb6da4 100644 --- a/MP.SPEC/Pages/Index.razor +++ b/MP.SPEC/Pages/Index.razor @@ -34,13 +34,15 @@ } else { - foreach (var item in ElencoLink) { - - - @item.Testo - + @if (string.IsNullOrEmpty(item.Ruolo) || HasRole(item.Ruolo)) + { + + + @item.Testo + + } } }
diff --git a/MP.SPEC/Pages/Index.razor.cs b/MP.SPEC/Pages/Index.razor.cs index f37b343c..8d46c426 100644 --- a/MP.SPEC/Pages/Index.razor.cs +++ b/MP.SPEC/Pages/Index.razor.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Components; +using MP.AppAuth.Models; using MP.Data.DbModels; using MP.SPEC.Data; @@ -8,7 +9,7 @@ namespace MP.SPEC.Pages { #region Public Properties - public List? ElencoLink { get; set; } + public List? ElencoLink { get; set; } #endregion Public Properties @@ -18,28 +19,26 @@ namespace MP.SPEC.Pages protected MpDataService MDService { get; set; } = null!; [Inject] - protected MsgServiceSpec MessageService { get; set; } = null!; + protected MsgServiceSpec MsgService { get; set; } = null!; #endregion Protected Properties #region Protected Methods + /// + /// Verifica ruolo utente + /// + /// + /// + protected bool HasRole(string Ruolo) + { + return MsgService.HasRole(Ruolo); + } + protected override async Task OnInitializedAsync() { - // nascondo ricerca - // recupero elenco JQM + // recupero elenco link ElencoLink = await MDService.ElencoLink(); -#if false - configData = await MDService.ConfigGetAll(); - if (configData != null) - { - var currRec = configData.FirstOrDefault(x => x.Chiave == "AZIENDA"); - if (currRec != null) - { - currAzienda = currRec.Valore; - } - } -#endif currAzienda = await MDService.ConfigTryGetAsync("AZIENDA"); await Task.Delay(1); } @@ -51,13 +50,5 @@ namespace MP.SPEC.Pages private string currAzienda = ""; #endregion Private Fields - - #region Private Properties - -#if false - private List? configData { get; set; } = null; -#endif - - #endregion Private Properties } } \ No newline at end of file diff --git a/MP.SPEC/Program.cs b/MP.SPEC/Program.cs index 75ca897f..68c34e0d 100644 --- a/MP.SPEC/Program.cs +++ b/MP.SPEC/Program.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.FileProviders; +using MP.AppAuth.Services; using MP.Data.Services; using MP.SPEC.Components; using MP.SPEC.Data; @@ -59,6 +60,7 @@ builder.Services.AddSingleton(redisMultiplexer); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddBlazoredLocalStorage(); builder.Services.AddBlazoredSessionStorage(); diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 3dc58f2f..bb81bb2b 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2504.1612

+

Versione: 6.16.2504.1617


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 22950480..02219081 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2504.1612 +6.16.2504.1617 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index 6925b306..2bd31486 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2504.1612 + 6.16.2504.1617 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false diff --git a/MP.SPEC/Shared/NavMenu.razor b/MP.SPEC/Shared/NavMenu.razor index 6532febf..e089c51b 100644 --- a/MP.SPEC/Shared/NavMenu.razor +++ b/MP.SPEC/Shared/NavMenu.razor @@ -22,7 +22,7 @@
- - diff --git a/MP.SPEC/Shared/NavMenu.razor.cs b/MP.SPEC/Shared/NavMenu.razor.cs index 3a3bb51c..21486132 100644 --- a/MP.SPEC/Shared/NavMenu.razor.cs +++ b/MP.SPEC/Shared/NavMenu.razor.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Components; +using MP.SPEC.Data; namespace MP.SPEC.Shared { @@ -9,19 +10,33 @@ namespace MP.SPEC.Shared [Parameter] public EventCallback EC_compressUpdated { get; set; } - public List? ElencoLink { get; set; } + public List? ElencoLink { get; set; } #endregion Public Properties #region Protected Properties protected string hideText { get => showText ? "" : "invisible"; } + + [Inject] + protected MsgServiceSpec MsgService { get; set; } = null!; + protected bool showText { get; set; } = true; #endregion Protected Properties #region Protected Methods + /// + /// Verifica ruolo utente + /// + /// + /// + protected bool HasRole(string Ruolo) + { + return MsgService.HasRole(Ruolo); + } + protected override async Task OnInitializedAsync() { // recupero elenco JQM diff --git a/MP.SPEC/appsettings.Production.json b/MP.SPEC/appsettings.Production.json index 1980ac8c..cb1c2ec1 100644 --- a/MP.SPEC/appsettings.Production.json +++ b/MP.SPEC/appsettings.Production.json @@ -12,6 +12,7 @@ "MP.All": "Server=localhost\\SQLEXPRESS;Database=MoonPro; User ID=steamware;Password=viadante16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", "MP.Data": "Server=localhost\\SQLEXPRESS;Database=MoonPro; User ID=steamware;Password=viadante16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", "MP.Flux": "Server=localhost\\SQLEXPRESS;Database=MoonPro_FluxData; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", + "MP.Land": "Server=localhost\\SQLEXPRESS;Database=MoonPro; User ID=steamware;Password=viadante16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", "MP.Inve": "Server=localhost\\SQLEXPRESS;Database=MoonPro_MAG; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", "Redis": "localhost:6379,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false", "RedisAdmin": "localhost:6379,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true", diff --git a/MP.SPEC/appsettings.json b/MP.SPEC/appsettings.json index f37378f6..b4ad12d7 100644 --- a/MP.SPEC/appsettings.json +++ b/MP.SPEC/appsettings.json @@ -52,6 +52,7 @@ "MP.Data": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", "MP.Flux": "Server=SQL2016DEV;Database=MoonPro_FluxData; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", "MP.Inve": "Server=SQL2016DEV;Database=MoonPro_MAG; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", + "MP.Land": "Server=SQL2016DEV;Database=MoonPro; User ID=sa;Password=keyhammer16; integrated security=False; MultipleActiveResultSets=True; App=MP.SPEC;", "Redis": "localhost:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true", "RedisAdmin": "localhost:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true", "mdbConnString": "mongodb://W2019-MONGODB:27017"