Fix gestione elenco company x utente

This commit is contained in:
Samuele Locatelli
2023-05-31 14:37:41 +02:00
parent a5ba37a2f9
commit d43338f467
7 changed files with 179 additions and 387 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>WebDoorCreator - Egalware</i>
<h4>Version: 0.9.2305.3111</h4>
<h4>Version: 0.9.2305.3114</h4>
<br /> Release note:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
0.9.2305.3111
0.9.2305.3114
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>0.9.2305.3111</version>
<version>0.9.2305.3114</version>
<url>http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/WDC/stable/ChangeLog.html</changelog>
<mandatory>false</mandatory>
@@ -8,23 +8,35 @@ namespace WebDoorCreator.UI.Components.Filters
{
public partial class OrderFilter
{
private List<ListValuesModel>? ListValuesAll = null;
#region Public Properties
[Parameter]
public OrderSelectFilter actFilter { get; set; } = new OrderSelectFilter();
public CompanyModel? compToShow { get; set; } = null;
public EventCallback<List<string>> E_UserClaims { get; set; }
public EventCallback<int> E_UserCurrCompany { get; set; }
public EventCallback<string> E_UserId { get; set; }
public EventCallback<string> E_UserRole { get; set; }
[Parameter]
public EventCallback<OrderSelectFilter> FilterUpdated { get; set; }
public List<CompanyModel> listCompanies { get; set; } = new List<CompanyModel>();
public async void OnNewUserCurrComp()
public List<string> listRecord { get; set; } = new List<string>();
public List<string>? userClaimsList
{
await InvokeAsync(() =>
get
{
StateHasChanged();
});
return WDCUService.userClaims;
}
set
{
WDCUService.userClaims = value;
reportChangeClaimsList();
}
}
public int userCurrCompany
{
get
@@ -40,16 +52,105 @@ namespace WebDoorCreator.UI.Components.Filters
}
}
}
public EventCallback<int> E_UserCurrCompany { get; set; }
private void reportChangeCompany()
public string userId
{
E_UserCurrCompany.InvokeAsync(userCurrCompany);
get
{
return WDCUService.userId;
}
set
{
WDCUService.userId = value;
reportUserId();
}
}
public string userRole
{
get
{
return WDCUService.userRole;
}
set
{
WDCUService.userRole = value;
reportChangeRole();
}
}
#endregion Public Properties
#region Public Methods
public async void OnNewUserCurrComp()
{
await InvokeAsync(() =>
{
StateHasChanged();
});
}
#endregion Public Methods
#region Protected Properties
protected bool isMenuShow { get; set; } = false;
protected List<CompanyModel> listCompanies
{
get => WDCUService.UserCompaniesList;
set => WDCUService.UserCompaniesList = value;
}
[Inject]
protected UserManDataService UDService { get; set; } = null!;
protected List<System.Security.Claims.Claim>? userClaims { get; set; } = null;
[Inject]
protected WDCUserService WDCUService { get; set; } = null!;
[Inject]
protected WebDoorCreatorService WDService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected async Task closeMenu()
{
await Task.Delay(1);
isMenuShow = false;
}
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
WDCUService.EA_UserCurrCompany += OnNewUserCurrComp;
}
protected override async Task OnParametersSetAsync()
{
ListValuesAll = await WDService.ListValuesGetAll("All", "OrderStep");
}
protected async Task showMenu()
{
await Task.Delay(1);
isMenuShow = true;
}
#endregion Protected Methods
#region Private Fields
private List<ListValuesModel>? ListValuesAll = null;
#endregion Private Fields
#region Private Properties
private DateTime dateFrom
{
get => actFilter.DateFrom;
@@ -98,149 +199,35 @@ namespace WebDoorCreator.UI.Components.Filters
}
}
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
WDCUService.EA_UserCurrCompany += OnNewUserCurrComp;
await ReloadData();
}
#endregion Private Properties
public List<string> listRecord { get; set; } = new List<string>();
public string userId
{
get
{
return WDCUService.userId;
}
set
{
WDCUService.userId = value;
reportUserId();
}
}
private void reportUserId()
{
E_UserId.InvokeAsync(userId);
}
public EventCallback<string> E_UserId { get; set; }
public EventCallback<string> E_UserRole { get; set; }
public string userRole
{
get
{
return WDCUService.userRole;
}
set
{
WDCUService.userRole = value;
reportChangeRole();
}
}
private void reportChangeRole()
{
E_UserRole.InvokeAsync(userRole);
}
protected List<System.Security.Claims.Claim>? userClaims { get; set; } = null;
protected async Task ReloadData()
{
// reset preliminare
listRecord = new List<string>();
//if (!NavManager.Uri.Contains("UserAdmin"))
//{
if (!string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(userRole))
{
var obj = await WDCUService.UserDataGetByName(userId);
if (obj != null)
{
userClaims = obj.Claims.ToList();
if (userClaims != null)
{
if (obj.Roles.Contains("SuperAdmin"))
{
listCompanies = await WDService.CompanyGetByKey(0);
}
else
{
foreach (var item in obj.Claims.ToList())
{
List<CompanyModel> rawComp = await WDService.CompanyGetByKey(int.Parse(item.Value));
if (rawComp != null)
{
CompanyModel comp2Add = rawComp?.FirstOrDefault()!;
listCompanies.Add(comp2Add);
}
}
}
}
// fix role
if (obj.Roles != null)
{
var rawRole = obj.Roles.FirstOrDefault();
userRole = !string.IsNullOrEmpty(rawRole) ? rawRole : "Undef";
}
}
//fixSelCompany();
userClaimsList = listRecord;
}
//}
}
#region Private Methods
protected bool isMenuShow { get; set; } = false;
protected async Task showMenu()
{
await Task.Delay(1);
isMenuShow = true;
}
protected async Task closeMenu()
{
await Task.Delay(1);
isMenuShow = false;
}
protected void fixSelCompany()
{
// cerco tra le company disponibili quella salvata nel service...
var selComp = listCompanies
.Where(x => x.CompanyId == userCurrCompany)
.FirstOrDefault();
if (selComp != null)
{
// seleziono
compToShow = selComp;
}
else
{
// seleziono la prima
//compToShow = "*";
}
userCurrCompany = compToShow.CompanyId;
}
private void reportChangeClaimsList()
{
E_UserClaims.InvokeAsync(userClaimsList);
}
public EventCallback<List<string>> E_UserClaims { get; set; }
public List<string>? userClaimsList
{
get
{
return WDCUService.userClaims;
}
set
{
WDCUService.userClaims = value;
reportChangeClaimsList();
}
}
protected override async Task OnParametersSetAsync()
{
ListValuesAll = await WDService.ListValuesGetAll("All", "OrderStep");
//await ReloadData();
}
private void ReportChange()
{
FilterUpdated.InvokeAsync(actFilter);
}
private void reportChangeClaimsList()
{
E_UserClaims.InvokeAsync(userClaimsList);
}
private void reportChangeCompany()
{
E_UserCurrCompany.InvokeAsync(userCurrCompany);
}
private void reportChangeRole()
{
E_UserRole.InvokeAsync(userRole);
}
private void reportUserId()
{
E_UserId.InvokeAsync(userId);
}
#endregion Private Methods
}
}
@@ -21,9 +21,6 @@ namespace WebDoorCreator.UI.Components.Gen
public EventCallback<string> E_UserRole { get; set; }
public EventCallback<Dictionary<string, Dictionary<string, string>>> E_VocLemmas { get; set; }
public List<CompanyModel> listCompanies { get; set; } = new List<CompanyModel>();
protected List<System.Security.Claims.Claim>? userClaims { get; set; } = null;
public List<string> listRecord { get; set; } = new List<string>();
public Dictionary<string, Dictionary<string, string>>? listVocLemmas
@@ -38,6 +35,7 @@ namespace WebDoorCreator.UI.Components.Gen
reportVocLemmas();
}
}
[Inject]
public NavigationManager NavManager { get; set; } = default!;
@@ -157,6 +155,17 @@ namespace WebDoorCreator.UI.Components.Gen
[Inject]
protected AuthenticationStateProvider ASProvider { get; set; } = null!;
protected List<CompanyModel> listCompanies
{
get => WDCUService.UserCompaniesList;
set => WDCUService.UserCompaniesList = value;
}
[Inject]
protected UserManDataService UMService { get; set; } = null!;
protected List<System.Security.Claims.Claim>? userClaims { get; set; } = null;
protected string userLang
{
get => WDCUService.currLanguage ?? "EN";
@@ -168,8 +177,6 @@ namespace WebDoorCreator.UI.Components.Gen
[Inject]
protected WDCUserService WDCUService { get; set; } = null!;
[Inject]
protected UserManDataService UMService { get; set; } = null!;
[Inject]
protected WDCVocabularyService WDCVService { get; set; } = null!;
@@ -206,7 +213,6 @@ namespace WebDoorCreator.UI.Components.Gen
WDCUService.EA_UserClaims += OnNewUserClaims;
WDCUService.EA_UserCurrCompany += OnNewUserCurrComp;
WDCUService.EA_UserId += OnNewUserId;
//WDCVService.EA_VocabularyLemmas += OnNewVocLemma;
}
protected override async Task OnParametersSetAsync()
@@ -233,44 +239,41 @@ namespace WebDoorCreator.UI.Components.Gen
{
// reset preliminare
listRecord = new List<string>();
//if (!NavManager.Uri.Contains("UserAdmin"))
//{
if (!string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(userRole))
if (!string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(userRole))
{
var obj = await UMService.UserDataGetByName(userId);
if (obj != null)
{
var obj = await UMService.UserDataGetByName(userId);
if (obj != null)
userClaims = obj.Claims.ToList();
if (userClaims != null)
{
userClaims = obj.Claims.ToList();
if (userClaims != null)
if (obj.Roles.Contains("SuperAdmin"))
{
if (obj.Roles.Contains("SuperAdmin"))
listCompanies = await WDCService.CompanyGetByKey(0);
}
else
{
foreach (var item in obj.Claims.ToList())
{
listCompanies = await WDCService.CompanyGetByKey(0);
}
else
{
foreach (var item in obj.Claims.ToList())
List<CompanyModel> rawComp = await WDCService.CompanyGetByKey(int.Parse(item.Value));
if (rawComp != null)
{
List<CompanyModel> rawComp = await WDCService.CompanyGetByKey(int.Parse(item.Value));
if (rawComp != null)
{
CompanyModel comp2Add = rawComp?.FirstOrDefault()!;
listCompanies.Add(comp2Add);
}
CompanyModel comp2Add = rawComp?.FirstOrDefault()!;
listCompanies.Add(comp2Add);
}
}
}
// fix role
if (obj.Roles != null)
{
var rawRole = obj.Roles.FirstOrDefault();
userRole = !string.IsNullOrEmpty(rawRole) ? rawRole : "Undef";
}
}
fixSelCompany();
userClaimsList = listRecord;
// fix role
if (obj.Roles != null)
{
var rawRole = obj.Roles.FirstOrDefault();
userRole = !string.IsNullOrEmpty(rawRole) ? rawRole : "Undef";
}
}
//}
fixSelCompany();
userClaimsList = listRecord;
}
}
#endregion Protected Methods
+4 -202
View File
@@ -2,6 +2,7 @@
using Newtonsoft.Json;
using NLog;
using StackExchange.Redis;
using WebDoorCreator.Data.DbModels;
namespace WebDoorCreator.UI.Data
{
@@ -101,6 +102,9 @@ namespace WebDoorCreator.UI.Data
}
}
public List<CompanyModel> UserCompaniesList { get; set; } = new List<CompanyModel>();
public Dictionary<string, string> UserPref { get; set; } = new Dictionary<string, string>();
public string userRole
@@ -354,208 +358,6 @@ namespace WebDoorCreator.UI.Data
#endregion Protected Methods
#if false
/// <summary>
/// Dati utente CLAIMS da REDIS o DB
/// </summary>
/// <returns></returns>
protected async Task<List<Claim>> UserClaimsById(IdentityUser UserIdent)
{
string source = "DB";
List<Claim> dataResult = new List<Claim>();
// cerco da cache
string currKey = $"{Constants.rKeyUsersData}:Claims:{UserIdent.Id}";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<Claim>>(rawData, new ClaimConverter());
if (tempResult != null)
{
dataResult = tempResult;
}
}
else
{
var rawResult = await _userManager.GetClaimsAsync(UserIdent);
dataResult = rawResult.ToList();
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
if (dataResult == null)
{
dataResult = new List<Claim>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"UserClaimsById | {source} in: {ts.TotalMilliseconds} ms");
return dataResult;
}
/// <summary>
/// Dati utente IDENTITY da REDIS o DB da UID
/// </summary>
/// <returns></returns>
protected async Task<IdentityUser> UserIdentityById(string UserId)
{
string source = "DB";
IdentityUser dataResult = new IdentityUser();
// cerco da cache
string currKey = $"{Constants.rKeyUsersData}:Identity:{UserId}";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<IdentityUser>(rawData);
if (tempResult != null)
{
dataResult = tempResult;
}
}
else
{
dataResult = await _userManager.FindByIdAsync(UserId);
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
if (dataResult == null)
{
dataResult = new IdentityUser();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"UserIdentityById | {source} in: {ts.TotalMilliseconds} ms");
return dataResult;
}
/// <summary>
/// Dati utente IDENTITY da REDIS o DB per NAME
/// </summary>
/// <returns></returns>
protected async Task<IdentityUser> UserIdentityByName(string uName)
{
string source = "DB";
IdentityUser dataResult = new IdentityUser();
// cerco da cache
string currKey = $"{Constants.rKeyUsersData}:UN:{uName}";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<IdentityUser>(rawData);
if (tempResult != null)
{
dataResult = tempResult;
}
}
else
{
dataResult = await _userManager.FindByNameAsync(uName);
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
if (dataResult == null)
{
dataResult = new IdentityUser();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"UserIdentityByName | {source} in: {ts.TotalMilliseconds} ms");
return dataResult;
}
/// <summary>
/// Dati utente IDENTITY in modalità SEARCH da REDIS o DB
/// </summary>
/// <returns></returns>
protected async Task<List<IdentityUser>> UserIdentityBySearch(string searchVal)
{
string source = "DB";
List<IdentityUser> dataResult = new List<IdentityUser>();
// cerco da cache
string currKey = $"{Constants.rKeyUsersDataSearch}:{searchVal}";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<IdentityUser>>(rawData);
if (tempResult != null)
{
dataResult = tempResult;
}
}
else
{
var allData = await UserDataGetAll();
if (!string.IsNullOrEmpty(searchVal))
{
dataResult = allData
.Where(x => x.NormalizedEmail.Contains(searchVal.ToUpper()) || x.NormalizedUserName.Contains(searchVal.ToUpper())).ToList();
}
else
{
dataResult = allData;
}
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
if (dataResult == null)
{
dataResult = new List<IdentityUser>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"UserIdentityBySearch | {source} in: {ts.TotalMilliseconds} ms");
return dataResult;
}
/// <summary>
/// Dati utente ROLES da REDIS o DB
/// </summary>
/// <returns></returns>
protected async Task<List<string>> UserRolesById(IdentityUser UserIdent)
{
string source = "DB";
List<string> dataResult = new List<string>();
// cerco da cache
string currKey = $"{Constants.rKeyUsersData}:Roles:{UserIdent.Id}";
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string? rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty(rawData))
{
source = "REDIS";
var tempResult = JsonConvert.DeserializeObject<List<string>>(rawData);
if (tempResult != null)
{
dataResult = tempResult;
}
}
else
{
var rawResult = await _userManager.GetRolesAsync(UserIdent);
dataResult = rawResult.ToList();
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
await redisDb.StringSetAsync(currKey, rawData, LongCache);
}
if (dataResult == null)
{
dataResult = new List<string>();
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"UserRolesById | {source} in: {ts.TotalMilliseconds} ms");
return dataResult;
}
#endif
#region Private Fields
private static JsonSerializerSettings? JSSettings;
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>0.9.2305.3111</Version>
<Version>0.9.2305.3114</Version>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608</UserSecretsId>
</PropertyGroup>