Fix Roles x UserAdmin

This commit is contained in:
Samuele Locatelli
2023-05-30 19:54:19 +02:00
parent dbbe25027a
commit 067ebdcc84
7 changed files with 29 additions and 210 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>WebDoorCreator - Egalware</i>
<h4>Version: 0.9.2305.3018</h4>
<h4>Version: 0.9.2305.3019</h4>
<br /> Release note:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
0.9.2305.3018
0.9.2305.3019
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>0.9.2305.3018</version>
<version>0.9.2305.3019</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>
@@ -196,7 +196,7 @@ namespace WebDoorCreator.UI.Components.Gen
compToShow = listCompanies?.FirstOrDefault()!;
}
userCurrCompany = compToShow.CompanyId;
}
}
protected override async Task OnInitializedAsync()
{
@@ -231,58 +231,12 @@ namespace WebDoorCreator.UI.Components.Gen
{
// reset preliminare
listRecord = new List<string>();
//listCompanies = new List<CompanyModel>();
if (!NavManager.Uri.Contains("UserAdmin"))
{
if (!string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(userRole))
{
// FARE!!! rivedere con await WDCUsrServ.UserDataGetById(userId);
var user = await _userManager.FindByNameAsync(userId);
#if false
var user = await _userManager.FindByNameAsync(userId);
var roleList = await _userManager.GetRolesAsync(user);
if (roleList != null)
{
var role = roleList.FirstOrDefault();
if (role != null)
{
userRole = role;
}
}
var claimsList = await _userManager.GetClaimsAsync(user);
if (claimsList != null)
{
if (userRole == "SuperAdmin")
{
listCompanies = await WDCService.CompanyGetByKey(0);
}
else
{
if (claimsList.Count > 1)
{
foreach (var item in claimsList)
{
listRecord.Add(item.Value);
var rawList = await WDCService.CompanyGetByKey(int.Parse(item.Value));
CompanyModel firstComp = rawList.FirstOrDefault() ?? new CompanyModel();
listCompanies.Add(firstComp);
}
}
else if (claimsList.Count == 1)
{
var currClaim = claimsList.FirstOrDefault();
if (currClaim != null)
{
listRecord.Add(currClaim.Value);
listCompanies = await WDCService.CompanyGetByKey(int.Parse(currClaim.Value));
}
compToShow = listCompanies?.FirstOrDefault()!;
}
}
}
#endif
var obj = await WDCUService.UserDataGetById(user.Id);
if (obj != null)
{
@@ -305,7 +259,13 @@ namespace WebDoorCreator.UI.Components.Gen
}
}
}
}
}
// fix role
if (obj.Roles != null)
{
var rawRole = obj.Roles.FirstOrDefault();
userRole = !string.IsNullOrEmpty(rawRole) ? rawRole : "Undef";
}
}
fixSelCompany();
userClaimsList = listRecord;
+5 -26
View File
@@ -36,32 +36,11 @@
<Authorized>
<span class="input-group-text"><i class="fas fa-user-tag"></i></span>
<select class="form-select" @bind="@CurrentUserRole">
@if (@context.User.IsInRole("SuperAdmin"))
@foreach (var option in RolesList)
{
@foreach (var option in RolesList)
{
<option value="@option">
@option
</option>
}
}
else if (@context.User.IsInRole("Admin"))
{
@foreach (var option in RolesList.Where(x => x != "SuperAdmin"))
{
<option value="@option">
@option
</option>
}
}
else if (@context.User.IsInRole("CompAdmin"))
{
@foreach (var option in RolesList.Where(x => x != "SuperAdmin" && x != "Admin"))
{
<option value="@option">
@option
</option>
}
<option value="@option">
@option
</option>
}
</select>
</Authorized>
@@ -239,7 +218,7 @@ else
}
else
{
<td>*******</td>
<td>*******</td>
}
</Authorized>
</AuthorizeView>
+12 -132
View File
@@ -32,12 +32,6 @@ namespace WebDoorCreator.UI.Pages
{
List<string> answ = new List<string>();
var pUpd = Task.Run(async () =>
{
await refreshLists();
});
pUpd.Wait();
// ciclo sui claims
foreach (var claim in ClaimList)
{
@@ -66,42 +60,6 @@ namespace WebDoorCreator.UI.Pages
}
break;
#if false
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;
#endif
case "None":
default:
break;
@@ -114,9 +72,6 @@ namespace WebDoorCreator.UI.Pages
public void Dispose()
{
#if false
AppMService.EA_SearchUpdated -= OnSeachUpdated;
#endif
}
/// <summary>
@@ -240,19 +195,17 @@ namespace WebDoorCreator.UI.Pages
}
protected IdentityUser currUser { get; set; } = new IdentityUser();
string currUserRole { get; set; } = "";
string currUserRole
{
get => WDCUService.userRole;
}
protected override async Task OnInitializedAsync()
{
searchVal = "";
//await Task.Delay(50);
//currUser = await _UserManager.FindByEmailAsync(WDCUService.userId);
CurrentUserClaimType = WDCUsrServ.userCurrComp.ToString();
// lettura dati
await ReloadData();
#if false
await CheckSuperAdmin();
#endif
}
protected void resetSearch()
@@ -310,10 +263,6 @@ namespace WebDoorCreator.UI.Pages
private string _filtUserRole { get; set; } = "0";
private int _numRecord { get; set; } = 10;
private string _searchVal { get; set; } = "";
#if false
[Inject]
protected MessageService AppMService { get; set; } = null!;
#endif
[CascadingParameter]
private Task<AuthenticationState> authenticationStateTask { get; set; } = null!;
@@ -438,46 +387,6 @@ namespace WebDoorCreator.UI.Pages
ShowPopup = true;
}
private async Task CheckSuperAdmin()
{
// se non ci fosse --> creo samuele come superadmin
string superUser = "samuele@steamware.net";
string superPwd = "viaDante16!";
var user = await _UserManager.FindByEmailAsync(superUser);
if (user == null)
{
// Insert new user
var NewUser =
new IdentityUser
{
UserName = superUser,
Email = superUser,
EmailConfirmed = true
};
var CreateResult = await _UserManager.CreateAsync(NewUser, superPwd);
if (CreateResult.Succeeded)
{
user = await _UserManager.FindByEmailAsync(superUser);
}
}
// verifico ruoli...
if (user != null)
{
// Gestione salvataggio ruoli... SE VARIATO...
var UserRoles = await _UserManager.GetRolesAsync(user);
if (UserRoles != null && UserRoles.Count > 0)
{
var oldRole = UserRoles.Where(x => x == ADMIN_ROLE).FirstOrDefault();
if (oldRole == null)
{
// aggiungo a ruolo admin
await _UserManager.AddToRoleAsync(user, ADMIN_ROLE);
}
}
}
}
private async Task ClosePopup()
{
// Close the Popup
@@ -616,28 +525,6 @@ namespace WebDoorCreator.UI.Pages
}
break;
#if false
case "SupplierId":
// elenco plant --> to dictionary!
var suppList = await WDCService.SuppliersGetAll();
if (suppList != null)
{
ClaimValList = suppList
.ToDictionary(x => $"{x.SupplierId}", x => x.SupplierDesc);
}
break;
case "TransporterId":
// elenco plant --> to dictionary!
var transpList = await WDCService.TransportersGetAll();
if (transpList != null)
{
ClaimValList = transpList
.ToDictionary(x => $"{x.TransporterId}", x => x.TransporterDesc);
}
break;
#endif
case "None":
default:
break;
@@ -646,21 +533,22 @@ namespace WebDoorCreator.UI.Pages
private async Task refreshLists()
{
// effettuo refresh valori cache Company/...
// effettuo refresh valori cache Company...
if (CompanyList == null || CompanyList.Count == 0)
{
CompanyList = await WDCService.CompanyGetByKey(0);
}
#if false
if (suppList == null)
// sistemo elenco ruoli dato livello utente...
RolesList = new List<string>() { "Undef", "User", "CompUser", "CompAdmin" };
if (currUserRole == "SuperAdmin")
{
suppList = await WDCService.SuppliersGetAll();
RolesList.Add("Admin");
RolesList.Add("SuperAdmin");
}
if (transpList == null)
else if (currUserRole == "Admin")
{
transpList = await WDCService.TransportersGetAll();
RolesList.Add("Admin");
}
#endif
}
private async Task ReloadData()
@@ -668,14 +556,6 @@ namespace WebDoorCreator.UI.Pages
isLoading = true;
await refreshLists();
await GetUsers();
#if false
var currUser = await _UserManager.FindByIdAsync(WDCUService.userId);
var listRolesTemp = await _UserManager.GetRolesAsync(currUser);
if (listRolesTemp != null)
{
currUserRole = listRolesTemp.FirstOrDefault()!;
}
#endif
isLoading = false;
}
+1 -1
View File
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>0.9.2305.3018</Version>
<Version>0.9.2305.3019</Version>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608</UserSecretsId>
</PropertyGroup>