Update gestione admin utenti

This commit is contained in:
Samuele Locatelli
2024-01-31 13:02:39 +01:00
parent 731e41b89c
commit c00de7d839
6 changed files with 372 additions and 66 deletions
+71 -2
View File
@@ -32,6 +32,75 @@
</div> *@
</div>
</div>
<div class="card-body">Content</div>
<div class="card-footer">Footer</div>
<div class="card-body">
<table class="table table-sm table-striped table-responsive-md">
<thead>
<tr>
<th></th>
<th>Id</th>
<th>User / Email</th>
<th>Ruolo</th>
<th>Permessi</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var user in UsersList)
{
<tr>
<td>
@if (!ShowPopup)
{
<button class="btn btn-sm btn-primary" @onclick="(() => EditUser(user.Identity))" title="Edit">
<i class="fas fa-pen"></i>
</button>
}
else
{
<button class="btn btn-sm btn-secondary disabled" title="Edit">
<i class="fas fa-pen"></i>
</button>
}
</td>
<td>@user.Identity.Id.Substring(0, 8)...</td>
<td>
@if (user.Identity.EmailConfirmed)
{
<span class="badge badge-pill badge-success" title="Email validata"><span class="oi oi-check" aria-hidden="true"></span></span>
}
else
{
<span class="badge badge-pill badge-danger" title="Email NON ancora validata!"><span class="oi oi-check" aria-hidden="true"></span></span>
}
&nbsp;@user.Identity.Email
</td>
<td>
@ShowRoles(user.Roles)
</td>
<td>
@ShowClaims(user.Claims)
</td>
<td>
@if (!ShowPopup)
{
<button class="btn btn-sm btn-danger" @onclick="(() => DeleteUser(user.Identity))" title="Delete">
<i class="fas fa-trash"></i>
</button>
}
else
{
<button class="btn btn-sm btn-secondary disabled" title="Delete">
<i class="fas fa-trash"></i>
</button>
}
</td>
</tr>
}
</tbody>
</table>
</div>
<div class="card-footer">
<EgwCoreLib.Razor.DataPager PageSize="@numRecord" currPage="@currPage" numRecordChanged="SetNumRec" numPageChanged="SetPage" totalCount="@totalCount" showLoading="@isLoading"></EgwCoreLib.Razor.DataPager>
</div>
</div>
+297 -60
View File
@@ -1,13 +1,228 @@
using MagMan.Core.Services;
using MagMan.Data.Admin;
using MagMan.Data.Admin.Services;
using MagMan.Data.Tenant.DbModels;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Identity;
using Microsoft.Data.SqlClient;
using Microsoft.JSInterop;
namespace MagMan.UI.Components
{
public partial class UserMan:IDisposable
public partial class UserMan : IDisposable
{
#region Public Methods
public List<string> ConvertClaim(List<System.Security.Claims.Claim> ClaimList)
{
List<string> answ = new List<string>();
#if false
var pUpd = Task.Run(async () =>
{
await refreshLists();
});
pUpd.Wait();
// ciclo sui claims
foreach (var claim in ClaimList)
{
string claimStr = claim.ToString();
// verifico che in OGNI claim ci siaun valore ammissibile...
if (claimStr.Contains(":"))
{
// splitto chiave/valore
var splitClaim = claimStr.Split(':');
switch (splitClaim[0])
{
case "PlantId":
if (plantList != null)
{
var plantRec = plantList
.Where(x => x.PlantId.ToString() == splitClaim[1].Trim())
.FirstOrDefault();
if (plantRec != null)
{
answ.Add($"{splitClaim[0]}: {plantRec.PlantDesc}");
}
else
{
answ.Add($"{claim}");
}
}
break;
case "SupplierId":
if (suppList != null)
{
var plantRec = suppList
.Where(x => x.SupplierId.ToString() == splitClaim[1].Trim())
.FirstOrDefault();
if (plantRec != null)
{
answ.Add($"{splitClaim[0]}: {plantRec.SupplierDesc}");
}
else
{
answ.Add($"{claim}");
}
}
break;
case "TransporterId":
if (transpList != null)
{
var plantRec = transpList
.Where(x => x.TransporterId.ToString() == splitClaim[1].Trim())
.FirstOrDefault();
if (plantRec != null)
{
answ.Add($"{splitClaim[0]}: {plantRec.TransporterDesc}");
}
else
{
answ.Add($"{claim}");
}
}
break;
case "None":
default:
break;
}
}
}
#endif
return answ;
}
public void Dispose()
{
AppMService.EA_SearchUpdated -= AppMService_EA_SearchUpdated;
}
/// <summary>
/// Recupera elenco utenti
/// </summary>
public async Task GetUsers()
{
// clear any error messages
strError = "";
UsersAll = await MTService.UserDataGetFilt(currSearch);
// filtro visualizzazione x tipo SE richeisto
if (FiltUserRole != "0")
{
UsersAll = UsersAll.Where(x => x.Roles.Contains(FiltUserRole)).ToList();
}
totalCount = UsersAll.Count;
UsersList = UsersAll
.Skip(numRecord * (currPage - 1)).Take(numRecord)
.ToList();
}
public string ShowClaims(List<System.Security.Claims.Claim> ClaimList)
{
//string answ = string.Join(",", ClaimList);
string answ = string.Join(",", ConvertClaim(ClaimList));
return answ;
}
public string ShowRoles(List<string> RoleList)
{
string answ = string.Join(",", RoleList);
return answ;
}
#endregion Public Methods
#region Protected Properties
[Inject]
protected MessageService AppMService { get; set; } = null!;
[Inject]
protected MTAdminService MTService { get; set; } = null!;
protected int totalCount { get; set; } = 0;
#endregion Protected Properties
#region Protected Methods
protected void DoSelect(UserData? selItem)
{
#if false
if (selItem != null)
{
ProjDbId = selItem.ProjDbId;
}
else
{
ProjDbId = 0;
}
E_ProjSel.InvokeAsync(selItem);
#endif
}
protected override void OnInitialized()
{
currSearch = "";
AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated;
}
protected void SetNumRec(int newNum)
{
numRecord = newNum;
currPage = 1;
InvokeAsync(ReloadData);
}
protected void SetPage(int newNum)
{
currPage = newNum;
DoSelect(null);
InvokeAsync(ReloadData);
}
#endregion Protected Methods
#region Private Fields
private string currSearch = "";
/// <summary>
/// Elenco ROLES da mostrare in dropdown durante editing (1 solo? usare DB?!?)
/// </summary>
private List<string> RolesList = new List<string>() { "Undef", "User", "Admin", "SuperAdmin" };
// To enable showing the Popup
private bool ShowPopup = false;
// To hold any possible errors
private string strError = "";
/// <summary>
/// Collezione utenti (totale)
/// </summary>
private List<UserData> UsersAll = new List<UserData>();
/// <summary>
/// Collezione utenti
/// </summary>
private List<UserData> UsersList = new List<UserData>();
#endregion Private Fields
#region Private Properties
private string _filtUserRole { get; set; } = "0";
private int currPage { get; set; } = 1;
/// <summary>
/// Gestione filtraggio dati
/// </summary>
@@ -28,82 +243,104 @@ namespace MagMan.UI.Components
}
}
/// <summary>
/// Elenco ROLES da mostrare in dropdown durante editing (1 solo? usare DB?!?)
/// </summary>
private List<string> RolesList = new List<string>() { "Undef", "User", "Admin", "SuperAdmin" };
private string _filtUserRole { get; set; } = "0";
private int currPage { get; set; } = 1;
private bool isLoading { get; set; } = false;
private int numRecord { get; set; } = 10;
private async Task ReloadData()
{
isLoading = true;
await GetUsers();
isLoading = false;
}
// To enable showing the Popup
private bool ShowPopup = false;
// To hold any possible errors
private string strError = "";
#endregion Private Properties
/// <summary>
/// Collezione utenti (totale)
/// </summary>
private List<UserData> UsersAll = new List<UserData>();
#region Private Methods
/// <summary>
/// Collezione utenti
/// </summary>
private List<UserData> UsersList = new List<UserData>();
[Inject]
protected MTAdminService MTService { get; set; } = null!;
[Inject]
protected MessageService AppMService { get; set; } = null!;
private async void AppMService_EA_SearchUpdated()
{
currSearch = AppMService.SearchVal;
await ReloadData();
}
protected override void OnInitialized()
private async Task DeleteUser(IdentityUser _IdentityUser)
{
currSearch = "";
AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated;
}
#if false
// Close the Popup
ShowPopup = false;
public void Dispose()
{
AppMService.EA_SearchUpdated -= AppMService_EA_SearchUpdated;
}
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare l'utente selezionato??"))
return;
private string currSearch = "";
/// <summary>
/// Recupera elenco utenti
/// </summary>
public async Task GetUsers()
{
// clear any error messages
strError = "";
UsersAll = await MTService.UserDataGetFilt(currSearch);
// filtro visualizzazione x tipo SE richeisto
if (FiltUserRole != "0")
// Get the user
var user = await _UserManager.FindByIdAsync(_IdentityUser.Id);
if (user != null)
{
UsersAll = UsersAll.Where(x => x.Roles.Contains(FiltUserRole)).ToList();
// Delete the user
await _UserManager.DeleteAsync(user);
}
UsersList = UsersAll
.Skip(numRecord * (currPage - 1)).Take(numRecord)
.ToList();
#endif
// Refresh Users
await GetUsers();
}
private void EditUser(IdentityUser _IdentityUser)
{
#if false
// selezione come current user
objUser = _IdentityUser;
var pUpd = Task.Run(async () =>
{
// Get the user
var user = await _UserManager.FindByIdAsync(objUser.Id);
if (user != null)
{
// salvo role
var UserRoles = await _UserManager.GetRolesAsync(user);
if (UserRoles != null)
{
CurrentUserRole = UserRoles.FirstOrDefault();
}
else
{
CurrentUserRole = UNDEF_ROLE;
}
// salvo claim
var UserClaims = await _UserManager.GetClaimsAsync(user);
if (UserClaims != null && UserClaims.Count > 0)
{
var CurrentUserClaim = UserClaims.FirstOrDefault();
CurrentUserClaimType = CurrentUserClaim.Type;
CurrentUserClaimVal = CurrentUserClaim.Value;
}
else
{
CurrentUserClaimType = STD_CLAIM;
CurrentUserClaimVal = "0";
}
string baseUrl = Configuration["BaseUrl"];
string baseAppPath = Configuration["BaseAppPath"];
string redirPage = Configuration["QrRedirPage"];
if (!string.IsNullOrEmpty(baseAppPath))
{
if (baseUrl.EndsWith("/"))
{
baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
}
baseUrl = $"{baseUrl}{baseAppPath}";
}
qrCodeVal = $"{baseUrl}Identity/Account/LogIn?uid={user.Id}&uem={user.Email}&pag={redirPage}";
}
});
pUpd.Wait();
// Open the Popup
ShowPopup = true;
#endif
}
private async Task ReloadData()
{
isLoading = true;
await GetUsers();
isLoading = false;
}
#endregion Private Methods
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.2401.3112</Version>
<Version>1.0.2401.3113</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>MagMan - Wood Warehouse Management System</i>
<h4>Versione: 1.0.2401.3112</h4>
<h4>Versione: 1.0.2401.3113</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
1.0.2401.3112
1.0.2401.3113
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.0.2401.3112</version>
<version>1.0.2401.3113</version>
<url>http://nexus.steamware.net/repository/SWS/MagMan/stable/0/MagMan.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/MagMan/stable/0/ChangeLog.html</changelog>
<mandatory>false</mandatory>