From 2e82c08fdece5631e77ddfbbb192acd14c8c29a0 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 11 Jan 2024 14:53:22 +0100 Subject: [PATCH] pulizia vecchie metodologie aggiunta user/ruoli --- MagMan.Data.Admin/RoleConfiguration.cs | 30 ----------- MagMan.Data.Admin/UserAdminConfiguration.cs | 55 --------------------- MagMan.Data.Admin/UserIdentityDbContext.cs | 15 +----- MagMan.Data.Admin/UserRoleConfiguration.cs | 55 --------------------- MagMan.UI/Program.cs | 1 - 5 files changed, 1 insertion(+), 155 deletions(-) delete mode 100644 MagMan.Data.Admin/RoleConfiguration.cs delete mode 100644 MagMan.Data.Admin/UserAdminConfiguration.cs delete mode 100644 MagMan.Data.Admin/UserRoleConfiguration.cs diff --git a/MagMan.Data.Admin/RoleConfiguration.cs b/MagMan.Data.Admin/RoleConfiguration.cs deleted file mode 100644 index ec41559..0000000 --- a/MagMan.Data.Admin/RoleConfiguration.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MagMan.Data.Admin -{ - public class RoleConfiguration : IEntityTypeConfiguration - { - #region Public Methods - - public void Configure(EntityTypeBuilder builder) - { - builder.HasData( - new IdentityRole { Name = "Undef", NormalizedName = "UNDEF" }, - //new IdentityRole { Name = "ExtUser", NormalizedName = "EXTUSER" }, - //new IdentityRole { Name = "ExtTransp", NormalizedName = "EXTTRANSP" }, - new IdentityRole { Name = "User", NormalizedName = "USER" }, - new IdentityRole { Name = "Admin", NormalizedName = "ADMIN" }, - new IdentityRole { Name = "SuperAdmin", NormalizedName = "SUPERADMIN" } - ); - } - - #endregion Public Methods - } -} diff --git a/MagMan.Data.Admin/UserAdminConfiguration.cs b/MagMan.Data.Admin/UserAdminConfiguration.cs deleted file mode 100644 index 608efea..0000000 --- a/MagMan.Data.Admin/UserAdminConfiguration.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MagMan.Data.Admin -{ - public class UserAdminConfiguration : IEntityTypeConfiguration - { - #region Public Methods - - public void Configure(EntityTypeBuilder builder) - { - // Default seeded users - builder.HasData( - // SuperAdmins - getNewUser("samuele.locatelli@egalware.com", "th1sIsTh3R1vrOfThNgt202401"), - getNewUser("emmanuele.sassi@egalware.com", "th1sIsTh3R1vrOfThNgt202402"), - getNewUser("luca.mazzoleni@egalware.com", "th1sIsTh3R1vrOfThNgt202403"), - // Admin egalware base - getNewUser("info@egalware.com", "th1sIsTh3R1vrOfThNgt202404") - ); - } - - #endregion Public Methods - - #region Protected Fields - - protected PasswordHasher hasher = new PasswordHasher(); - - #endregion Protected Fields - - #region Protected Methods - - protected IdentityUser getNewUser(string email, string passwd) - { - var newRec = new IdentityUser - { - UserName = email, - NormalizedUserName = email.ToUpper(), - Email = email, - NormalizedEmail = email.ToUpper(), - EmailConfirmed = true, - PasswordHash = hasher.HashPassword(null!, passwd), - }; - return newRec; - } - - #endregion Protected Methods - } -} \ No newline at end of file diff --git a/MagMan.Data.Admin/UserIdentityDbContext.cs b/MagMan.Data.Admin/UserIdentityDbContext.cs index 1b84898..b4685a7 100644 --- a/MagMan.Data.Admin/UserIdentityDbContext.cs +++ b/MagMan.Data.Admin/UserIdentityDbContext.cs @@ -60,24 +60,11 @@ namespace MagMan.Data.Admin { base.OnModelCreating(builder); - // nuova gestione in blocco come in GWMS e da https://stackoverflow.com/questions/34343599/how-to-seed-users-and-roles-with-code-first-migration-using-identity-asp-net-cor + // Gestione in blocco user/permessi di base (salvata con migrazione AddUserAndRoles) come in GWMS + https://stackoverflow.com/questions/34343599/how-to-seed-users-and-roles-with-code-first-migration-using-identity-asp-net-cor builder.Seed(); base.OnModelCreating(builder); - - // gestione come WDC: -#if false - - // aggiunta ruoli - builder.ApplyConfiguration(new RoleConfiguration()); - // aggiunta user admin base - builder.ApplyConfiguration(new UserAdminConfiguration()); - // aggiunta ruoli utente - builder.ApplyConfiguration(new UserRoleConfiguration()); - // Todo: aggiungere configurazione claims oltre ai roles... -#endif - } #endregion Protected Methods diff --git a/MagMan.Data.Admin/UserRoleConfiguration.cs b/MagMan.Data.Admin/UserRoleConfiguration.cs deleted file mode 100644 index 263f8c7..0000000 --- a/MagMan.Data.Admin/UserRoleConfiguration.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MagMan.Data.Admin -{ - public class UserRoleConfiguration : IEntityTypeConfiguration> - { - #region Public Methods - - public void Configure(EntityTypeBuilder> builder) - { - // Default seeded users - builder.HasData( - //SuperAdmin Samuele - seedUserRoles("f15d1e26-d995-4c46-86ca-6a67462424f5", "f66a9c0f-9f6b-4d9d-89d0-bde432a94882"), - //SuperAdmin Zaccaria - seedUserRoles("0e340d8e-13ae-4468-ac08-ad56b5f8beb0", "f66a9c0f-9f6b-4d9d-89d0-bde432a94882"), - //Admin Zaccaria 01 - seedUserRoles("36562ca7-5ede-4e04-8971-1acd9e4fb9e6", "4225aeef-4a9b-4629-bbb2-4f3ea6c93595"), - //CompAdmin Zaccaria 02 - seedUserRoles("d869584f-f439-4889-aade-b7497f1cb557", "fc7d40cd-35d6-45a1-89b6-ac4ffa6368c5") - - ); - -#if false - builder.HasData( - new IdentityRole { Name = "Undef", NormalizedName = "UNDEF" }, - //new IdentityRole { Name = "ExtUser", NormalizedName = "EXTUSER" }, - //new IdentityRole { Name = "ExtTransp", NormalizedName = "EXTTRANSP" }, - new IdentityRole { Name = "User", NormalizedName = "USER" }, - new IdentityRole { Name = "Admin", NormalizedName = "ADMIN" }, - new IdentityRole { Name = "SuperAdmin", NormalizedName = "SUPERADMIN" } - ); -#endif - } - protected IdentityUserRole seedUserRoles(string userID, string roleId) - { - var newRec = new IdentityUserRole() - { - UserId = userID, - RoleId = roleId - }; - - - return newRec; - } - #endregion Public Methods - } -} diff --git a/MagMan.UI/Program.cs b/MagMan.UI/Program.cs index 87c4514..d61cafb 100644 --- a/MagMan.UI/Program.cs +++ b/MagMan.UI/Program.cs @@ -68,7 +68,6 @@ builder.Services.AddHealthChecksUI(s => { s.AddHealthCheckEndpoint("MagMan_Services", "health"); s.SetEvaluationTimeInSeconds(60); - //s.SetEvaluationTimeInSeconds(60); s.SetMinimumSecondsBetweenFailureNotifications(120); s.SetApiMaxActiveRequests(5); s.SetHeaderText("MagMan Health Check Status");