Merge branch 'release/FixOldUserManFunc'

This commit is contained in:
Samuele Locatelli
2021-10-21 19:42:19 +02:00
11 changed files with 95 additions and 634 deletions
+2
View File
@@ -365,6 +365,7 @@ namespace GWMS.Data.Controllers
return dbResult;
}
#if false
public List<UserModel> GetUsersFilt(UserLevel UsrLvl, int PlantId, int SupplierId, int TransporterId)
{
List<UserModel> dbResult = new List<UserModel>();
@@ -379,6 +380,7 @@ namespace GWMS.Data.Controllers
}
return dbResult;
}
#endif
public List<WeekPlanModel> GetWeekPlan()
{
+2
View File
@@ -18,6 +18,7 @@ namespace GWMS.Data
/// <param name="modelBuilder"></param>
public static void Seed(this ModelBuilder modelBuilder)
{
#if false
// inizializzazione dei valori di default x USER
modelBuilder.Entity<UserModel>().HasData(
new UserModel { UserId = 1, AuthKey = "th1sIsTh3R1vrOfThNgt98", Livello = UserLevel.SuperAdmin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "samuele.locatelli", Email = "samuele@steamware.net", Firstname = "Samuele", Lastname = "Locatelli" },
@@ -34,6 +35,7 @@ namespace GWMS.Data
new UserModel { UserId = 12, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 3, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz05.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Baganzola" },
new UserModel { UserId = 13, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 4, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz08.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Pilastrello" }
);
#endif
// inizializzazione dei valori di default x Plant
modelBuilder.Entity<PlantDetailModel>().HasData(
-223
View File
@@ -1,223 +0,0 @@
@using GWMS.UI.Components
@using GWMS.Data.DatabaseModels
@using System.Security.Claims
@using Microsoft.AspNetCore.Components.Authorization
@using GWMS.UI.Data
@using GWMS.Data.DTO
@using Microsoft.Extensions.Configuration
@inject MessageService AppMService
@inject GWMSDataService DataService
@inject IConfiguration Configuration
<div class="card">
<div class="card-header bg-info text-light">
<b>Modifica</b>
</div>
<div class="card-body small p-1">
<EditForm Model="@_currItem">
<DataAnnotationsValidator />
<div class="row">
<div class="col-9 col-lg-10">
<div class="row mb-2">
<div class="col-3">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-puzzle-piece"></i></span>
</div>
<InputText @bind-Value="_currItem.UserName" class="form-control" title="User Name" />
</div>
</div>
<div class="col-3">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<InputText @bind-Value="_currItem.Lastname" class="form-control" title="Cognome" />
</div>
</div>
<div class="col-3">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text"><i class="far fa-user"></i></span>
</div>
<InputText @bind-Value="_currItem.Firstname" class="form-control" title="Nome" />
</div>
</div>
<div class="col-2">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">
<i class="fas fa-user-shield"></i>
</span>
</div>
<select @bind="_currItem.Livello" class="form-control">
@foreach (var itemVal in Enum.GetValues(typeof(GWMS.Data.UserLevel)))
{
<option>@itemVal</option>
}
</select>
</div>
</div>
<div class="col-1">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="switchAtt" title="attivo" @bind="_currItem.IsActive">
<label class="custom-control-label" for="switchAtt">Att</label>
</div>
</div>
</div>
<div class="row">
<div class="col-3">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-at"></i></span>
</div>
<InputText @bind-Value="_currItem.Email" class="form-control" title="Email" />
</div>
</div>
<div class="col-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-gas-pump" aria-hidden="true"></span>
</span>
</div>
<select @bind="_currItem.MaskPlantId" class="form-control form-control-sm">
<option value="0">--- Tutti ---</option>
@if (PlantsList != null)
{
foreach (var item in PlantsList)
{
<option value="@item.PlantId">@item.PlantCode | @item.PlantDesc</option>
}
}
</select>
</div>
</div>
<div class="col-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-industry" aria-hidden="true"></span>
</span>
</div>
<select @bind="_currItem.MaskSupplierId" class="form-control form-control-sm">
<option value="0">--- Tutti ---</option>
@if (SuppliersList != null)
{
foreach (var item in SuppliersList)
{
<option value="@item.SupplierId">@item.SupplierCode | @item.SupplierDesc</option>
}
}
</select>
</div>
</div>
<div class="col-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-truck-moving" aria-hidden="true"></span>
</span>
</div>
<select @bind="_currItem.MaskTranspId" class="form-control form-control-sm" title="Trasportatore">
<option value="0">--- Tutti ---</option>
@if (TransportersList != null)
{
foreach (var item in TransportersList)
{
<option value="@item.TransporterId">@item.TransporterCode | @item.TransporterDesc</option>
}
}
</select>
</div>
</div>
</div>
</div>
<div class="col-3 col-lg-2">
<div class="mb-2">
<button type="button" class="btn btn-sm btn-outline-success btn-block" value="Save" @onclick="saveUpdate">Save <i class="far fa-save"></i></button>
</div>
<div>
<button type="button" class="btn btn-sm btn-outline-warning btn-block" value="Cancel" @onclick="cancelUpdate">Cancel <i class="fas fa-ban"></i></button>
</div>
</div>
</div>
</EditForm>
</div>
</div>
@code {
private List<PlantDTO> PlantsList;
private List<SupplierModel> SuppliersList;
private List<TransporterModel> TransportersList;
protected UserModel _currItem = new UserModel();
protected int _supplierId { get; set; } = 0;
[Parameter]
public UserModel currItem
{
get
{
return _currItem = null;
}
set
{
_currItem = value;
}
}
[Parameter]
public EventCallback<int> DataReset { get; set; }
[Parameter]
public EventCallback<int> DataUpdated { get; set; }
[Parameter]
public int SupplierId
{
get
{
return _supplierId;
}
set
{
_supplierId = value;
// condiziono visualizzazione...
var pUpd = Task.Run(async () => await ReloadAllData());
pUpd.Wait();
}
}
private async Task saveUpdate()
{
if (_currItem != null)
{
DataService.UserUpdate(_currItem);
await DataUpdated.InvokeAsync(1);
}
else
{
Console.WriteLine("User null!");
}
}
private async Task cancelUpdate()
{
await DataReset.InvokeAsync(0);
}
protected override async Task OnInitializedAsync()
{
await ReloadAllData();
}
protected async Task ReloadAllData()
{
PlantsList = await DataService.PlantsGetAll();
SuppliersList = await DataService.SuppliersGetAll();
TransportersList = await DataService.TransportersGetAll();
}
}
+74 -8
View File
@@ -17,6 +17,7 @@ using GWMS.Data.DatabaseModels;
using static GWMS.Data.IobObjects;
using System.Globalization;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Identity;
namespace GWMS.UI.Data
{
@@ -28,6 +29,7 @@ namespace GWMS.UI.Data
private static ILogger<GWMSDataService> _logger;
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
private readonly IEmailSender _emailSender;
private readonly UserManager<IdentityUser> _userManager;
private readonly IDistributedCache distributedCache;
private readonly IMemoryCache memoryCache;
@@ -58,11 +60,12 @@ namespace GWMS.UI.Data
#region Public Constructors
public GWMSDataService(IConfiguration configuration, ILogger<GWMSDataService> logger, IMemoryCache memoryCache, IDistributedCache distributedCache, IEmailSender emailSender)
public GWMSDataService(IConfiguration configuration, ILogger<GWMSDataService> logger, IMemoryCache memoryCache, IDistributedCache distributedCache, IEmailSender emailSender, UserManager<IdentityUser> userManager)
{
_logger = logger;
_configuration = configuration;
_emailSender = emailSender;
_userManager = userManager;
// conf cache
this.memoryCache = memoryCache;
this.distributedCache = distributedCache;
@@ -233,6 +236,15 @@ namespace GWMS.UI.Data
// effettuo inserimento ordini!
dbController.OrderInsert(NewOrders);
// recupero elenco users associati al FORNITORE....
var rawUserList = UserDataGetFilt("").Result;
var supplList = rawUserList
.Where(x => x.Roles.Contains("ExtUser"))
.ToList();
var transpList = rawUserList
.Where(x => x.Roles.Contains("ExtTransp"))
.ToList();
// recupero NUOVI ordini x plant...
foreach (var plant in currPlantData)
{
@@ -258,14 +270,21 @@ namespace GWMS.UI.Data
sb.AppendLine($"Quantità ordinata: {item.OrderQty}");
emailBody = sb.ToString().Replace(Environment.NewLine, "<br/>");
System.Security.Claims.Claim suppClaim = new System.Security.Claims.Claim("SupplierId", $"{item.SupplierId}");
// recupero elenco users associati al FORNITORE....
var userList = dbController.GetUsersFilt(UserLevel.ND, 0, item.SupplierId, 0);
foreach (var user in userList)
var userListSupp = supplList
.Where(x => x.Claims.Where(c => c.Type == "SupplierId" && c.Value == $"{item.SupplierId}").Count() > 0)
.ToList();
foreach (var user in userListSupp)
{
// invio email di notifica nuovi ordini inseriti
emailDest = user.Email;
emailDest = user.Identity.Email;
//emailDest = user.Email;
// invio!
await _emailSender.SendEmailAsync(emailDest, emailSubj, emailBody);
_logger.LogInformation($"Email sento to SUPPLIER {emailDest}!");
}
// TRASPORTATORI!
@@ -283,14 +302,18 @@ namespace GWMS.UI.Data
sb.AppendLine($"Note: {item.OrderDesc}");
emailBody = sb.ToString().Replace(Environment.NewLine, "<br/>");
// recupero elenco users associati al FORNITORE....
userList = dbController.GetUsersFilt(UserLevel.ND, 0, 0, item.TransporterId);
foreach (var user in userList)
// recupero elenco users associati al TRASPORTATORE....
var userListTransp = transpList
.Where(x => x.Claims.Where(c => c.Type == "TransporterId" && c.Value == $"{item.TransporterId}").Count() > 0)
.ToList();
foreach (var user in userListTransp)
{
// invio email di notifica nuovi ordini inseriti
emailDest = user.Email;
emailDest = user.Identity.Email;
//emailDest = user.Email;
// invio!
await _emailSender.SendEmailAsync(emailDest, emailSubj, emailBody);
_logger.LogInformation($"Email sento to TRANSPORTER {emailDest}!");
}
}
}
@@ -869,6 +892,48 @@ namespace GWMS.UI.Data
return await Task.FromResult(dbResult);
}
public async Task<List<UserData>> UserDataGetFilt(string searchVal)
{
// Collezione utenti
List<IdentityUser> RawList = new List<IdentityUser>();
List<UserData> UsersList = new List<UserData>();
// recupero utenti da obj _userManager
var allData = _userManager.Users.ToList();
if (!string.IsNullOrEmpty(searchVal))
{
RawList = allData.Where(x => x.NormalizedEmail.Contains(searchVal.ToUpper()) || x.NormalizedUserName.Contains(searchVal.ToUpper())).ToList();
}
else
{
RawList = allData;
}
var user = RawList.Select(x => new IdentityUser
{
Id = x.Id,
UserName = x.UserName,
Email = x.Email,
PhoneNumber = x.PhoneNumber,
PasswordHash = "*****",
EmailConfirmed = x.EmailConfirmed
}).ToList();
foreach (var item in user)
{
var UserRoles = await _userManager.GetRolesAsync(item);
var UserClaims = await _userManager.GetClaimsAsync(item);
var newItem = new UserData()
{
Identity = item,
Roles = UserRoles.ToList(),
Claims = UserClaims.ToList()
};
UsersList.Add(newItem);
}
return await Task.FromResult(UsersList);
}
#if false
public async Task<List<UserModel>> UsersGetFilt(UserLevel UsrLvl, int PlantId, int SupplierId, int TransporterId)
{
List<UserModel> dbResult = new List<UserModel>();
@@ -893,6 +958,7 @@ namespace GWMS.UI.Data
{
}
}
#endif
public async void WeekPlanDelete(WeekPlanModel currItem)
{
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>1.0.2110.2116</Version>
<Version>1.0.2110.2119</Version>
<UserSecretsId>95c9f021-52d1-4390-a670-5810b7b777b0</UserSecretsId>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
+13
View File
@@ -136,6 +136,9 @@ namespace GWMS.UI.Pages
[Inject]
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; }
[Inject]
protected GWMSDataService DataService { get; set; }
[Inject]
protected IJSRuntime JSRuntime { get; set; }
@@ -464,6 +467,15 @@ namespace GWMS.UI.Pages
{
// clear any error messages
strError = "";
var rawData = await DataService.UserDataGetFilt(searchVal);
UsersList = rawData
.Skip(numRecord * (currPage - 1)).Take(numRecord)
.ToList();
#if false
// Collection to hold users
UsersList = new List<UserData>();
// get users from _UserManager
@@ -499,6 +511,7 @@ namespace GWMS.UI.Pages
};
UsersList.Add(newItem);
}
#endif
}
public async void OnSeachUpdated()
-147
View File
@@ -1,147 +0,0 @@
@page "/UserManager"
@using Blazorise.Components
@using GWMS.UI.Components
<div class="card">
<div class="card-header table-primary h3">
<div class="row">
<div class="col-3 h3">
Elenco Utenti
</div>
<div class="col-9 text-right">
<div class="d-flex justify-content-between">
<div class="p-2">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<i class="fas fa-user-shield"></i>
</span>
</div>
<select @bind="@SelLevel" class="form-control form-control-sm">
@foreach (var itemVal in Enum.GetValues(typeof(GWMS.Data.UserLevel)))
{
<option>@itemVal</option>
}
</select>
</div>
</div>
<div class="p-2">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-gas-pump" aria-hidden="true"></span>
</span>
</div>
<select @bind="@SelPlantId" class="form-control form-control-sm">
<option value="0">--- Tutti ---</option>
@if (PlantsList != null)
{
foreach (var item in PlantsList)
{
<option value="@item.PlantId">@item.PlantCode | @item.PlantDesc</option>
}
}
</select>
</div>
</div>
<div class="p-2">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-industry" aria-hidden="true"></span>
</span>
</div>
<select @bind="@SelSupplierId" class="form-control form-control-sm">
<option value="0">--- Tutti ---</option>
@if (SuppliersList != null)
{
foreach (var item in SuppliersList)
{
<option value="@item.SupplierId">@item.SupplierCode | @item.SupplierDesc</option>
}
}
</select>
</div>
</div>
<div class="p-2">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-truck-moving" aria-hidden="true"></span>
</span>
</div>
<select @bind="@SelTransporterId" class="form-control form-control-sm" title="Trasportatore">
<option value="0">--- Tutti ---</option>
@if (TransportersList != null)
{
foreach (var item in TransportersList)
{
<option value="@item.TransporterId">@item.TransporterCode | @item.TransporterDesc</option>
}
}
</select>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card-body p-1">
@if (currRecord != null)
{
<UserEditor currItem="@currRecord" DataReset="ResetData" DataUpdated="UpdateData"></UserEditor>
}
@if (ListRecords == null)
{
<LoadingData></LoadingData>
}
else if (totalCount == 0)
{
<div class="alert alert-warning text-center display-4">Nessun record trovato</div>
}
else
{
<div class="row">
<div class="col-12">
<table class="table table-sm table-striped">
<thead>
<tr>
<th></th>
<th>UserName</th>
<th>Cognome</th>
<th>Nome</th>
<th>Email</th>
<th>Att</th>
<th class="text-right">Livello</th>
<th class="text-right">Mask Impianto</th>
<th class="text-right">Mask Fornitore</th>
<th class="text-right">Mask Trasportatore</th>
</tr>
</thead>
<tbody>
@foreach (var record in ListRecords)
{
<tr class="@checkSelect(@record.UserId)">
<td class="text-nowrap"><button class="btn btn-sm btn-info" @onclick="() => Edit(record)"><span class="oi oi-pencil"></span></button></td>
<td>@record.UserName</td>
<td>@record.Lastname</td>
<td>@record.Firstname</td>
<td>@record.Email</td>
<td><input type="checkbox" checked="@record.IsActive"></td>
<td class="text-right">@record.Livello</td>
<td class="text-right">@record.MaskPlantId</td>
<td class="text-right">@record.MaskSupplierId</td>
<td class="text-right">@record.MaskTranspId</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
</div>
<div class="card-footer p-1">
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
</div>
</div>
-252
View File
@@ -1,252 +0,0 @@
using GWMS.Data;
using GWMS.Data.DatabaseModels;
using GWMS.Data.DTO;
using GWMS.UI.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace GWMS.UI.Pages
{
[Authorize(Roles = "SuperAdmin, Admin, User")]
public partial class UserManager : ComponentBase, IDisposable
{
#region Private Fields
private UserModel currRecord = null;
private List<UserModel> ListRecords;
private List<PlantDTO> PlantsList;
private List<UserModel> SearchRecords;
private List<SupplierModel> SuppliersList;
private List<TransporterModel> TransportersList;
#endregion Private Fields
#region Private Properties
private int _currPage { get; set; } = 1;
private int _numRecord { get; set; } = 10;
private UserLevel _selLevel { get; set; } = UserLevel.ND;
private int _selPlantId { get; set; } = 0;
private int _selSuppId { get; set; } = 0;
private int _selTraspId { get; set; } = 0;
private int currPage
{
get => _currPage;
set
{
if (_currPage != value)
{
_currPage = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private bool isLoading { get; set; } = false;
private int numRecord
{
get => _numRecord;
set
{
if (_numRecord != value)
{
_numRecord = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private UserLevel SelLevel
{
get => _selLevel;
set
{
if (_selLevel != value)
{
_selLevel = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private int SelPlantId
{
get => _selPlantId;
set
{
if (_selPlantId != value)
{
_selPlantId = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private int SelSupplierId
{
get => _selSuppId;
set
{
if (_selSuppId != value)
{
_selSuppId = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private int SelTransporterId
{
get => _selTraspId;
set
{
if (_selTraspId != value)
{
_selTraspId = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
#endregion Private Properties
#region Protected Properties
[Inject]
protected MessageService AppMService { get; set; }
[Inject]
protected GWMSDataService DataService { get; set; }
[Inject]
protected IJSRuntime JSRuntime { get; set; }
[Inject]
protected NavigationManager NavManager { get; set; }
protected int totalCount
{
get
{
int answ = 0;
if (SearchRecords != null)
{
answ = SearchRecords.Count;
}
return answ;
}
}
#endregion Protected Properties
#region Private Methods
private async Task ReloadData()
{
isLoading = true;
SearchRecords = await DataService.UsersGetFilt(SelLevel, SelPlantId, SelSupplierId, SelTransporterId);
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
isLoading = false;
}
#endregion Private Methods
#region Protected Methods
protected void Edit(UserModel selRecord)
{
currRecord = selRecord;
}
protected void ForceReload(int newNum)
{
numRecord = newNum;
}
protected void ForceReloadPage(int newNum)
{
currPage = newNum;
}
protected override async Task OnInitializedAsync()
{
AppMService.ShowSearch = true;
AppMService.PageName = "Utenti";
AppMService.PageIcon = "fas fa-users pr-2";
AppMService.EA_SearchUpdated += OnSeachUpdated;
await ReloadAllData();
}
protected async Task ReloadAllData()
{
PlantsList = await DataService.PlantsGetAll();
SuppliersList = await DataService.SuppliersGetAll();
TransportersList = await DataService.TransportersGetAll();
await ReloadData();
}
protected void ResetData()
{
DataService.rollBackEdit(currRecord);
currRecord = null;
}
protected void Select(UserModel selRecord)
{
// applico filtro da selezione
currRecord = selRecord;
}
protected async Task UpdateData()
{
currRecord = null;
await ReloadData();
}
#endregion Protected Methods
#region Public Methods
public string checkSelect(int UserId)
{
string answ = "";
if (currRecord != null)
{
try
{
answ = (currRecord.UserId == UserId) ? "table-info" : "";
}
catch
{ }
}
return answ;
}
public void Dispose()
{
AppMService.EA_SearchUpdated -= OnSeachUpdated;
}
public async void OnSeachUpdated()
{
await UpdateData();
StateHasChanged();
}
#endregion Public Methods
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>GWMS - Gas Warehouse Management System</i>
<h4>Versione: 1.0.2110.2116</h4>
<h4>Versione: 1.0.2110.2119</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
1.0.2110.2116
1.0.2110.2119
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.0.2110.2116</version>
<version>1.0.2110.2119</version>
<url>http://nexus.steamware.net/repository/SWS/GWMS/stable/0/GWMS.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/GWMS/stable/0/ChangeLog.html</changelog>
<mandatory>false</mandatory>