From 6c23f9274297d1c463ecdf865bdf3e33e6046f82 Mon Sep 17 00:00:00 2001 From: Doug Waldron <737326+dougwaldron@users.noreply.github.com> Date: Wed, 6 Nov 2024 06:39:30 -0500 Subject: [PATCH] Update template app with recent changes (#127) * Simplify the Display Message constructor * Update JavaScript libraries * Fix primary button color * Fix menu bar for x-small screens * Consolidate maintenance item edit warning * Update navbar styles * Update table hover styles * Explicitly set the HTTPS port in production; see: - https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/6.0/middleware-ambiguous-https-ports-exception - https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-8.0#port-configuration-1 * Update Program.cs and associated builder files * Update NuGet packages * Fix Display Message unit tests --- Directory.Packages.props | 50 ++++---- src/AppServices/Permissions/Policies.cs | 14 +++ ...onPolicies.cs => AuthorizationHandlers.cs} | 14 +-- .../RegisterServices/Validators.cs | 8 +- src/WebApp/Models/DisplayMessage.cs | 2 +- src/WebApp/Pages/Account/Index.cshtml | 2 +- .../Admin/Maintenance/EntryTypes/Edit.cshtml | 12 +- .../Admin/Maintenance/Offices/Edit.cshtml | 12 +- .../_MaintenanceItemEditWarning.cshtml | 12 ++ .../Shared/Components/MainMenu/Default.cshtml | 12 +- src/WebApp/Pages/Shared/_AlertPartial.cshtml | 2 +- .../Shared/_ValidationScriptsPartial.cshtml | 4 +- .../AppConfiguration/DataPersistence.cs | 13 +- src/WebApp/Program.cs | 18 ++- src/WebApp/libman.json | 20 +-- src/WebApp/wwwroot/css/site.css | 117 +++++++++++------- src/WebApp/wwwroot/js/anchorInit.js | 4 +- src/WebApp/wwwroot/js/color-modes.js | 23 ++-- tests/WebAppTests/AccountPages/EditTests.cs | 3 +- .../DisplayMessages/DisplayMessageTests.cs | 2 +- .../MaintenancePages/Offices/AddTests.cs | 4 +- .../MaintenancePages/Offices/EditTests.cs | 4 +- tests/WebAppTests/UserPages/EditRolesTests.cs | 3 +- tests/WebAppTests/UserPages/EditTests.cs | 3 +- 24 files changed, 194 insertions(+), 164 deletions(-) rename src/AppServices/RegisterServices/{AuthorizationPolicies.cs => AuthorizationHandlers.cs} (56%) create mode 100644 src/WebApp/Pages/Admin/Maintenance/_MaintenanceItemEditWarning.cshtml diff --git a/Directory.Packages.props b/Directory.Packages.props index 881c205..0f31e32 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,38 +4,38 @@ - + - + - - - - - + + + + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + - + - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + @@ -43,18 +43,18 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + \ No newline at end of file diff --git a/src/AppServices/Permissions/Policies.cs b/src/AppServices/Permissions/Policies.cs index 3c2be95..a270815 100644 --- a/src/AppServices/Permissions/Policies.cs +++ b/src/AppServices/Permissions/Policies.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.DependencyInjection; using MyApp.AppServices.Permissions.Requirements; namespace MyApp.AppServices.Permissions; @@ -26,6 +27,19 @@ namespace MyApp.AppServices.Permissions; public static class Policies { + // These policies are for use in PageModel class attributes, e.g.: + // [Authorize(Policy = nameof(Policies.ActiveUser))] + + public static void AddAuthorizationPolicies(this IServiceCollection services) + { + services.AddAuthorizationBuilder() + .AddPolicy(nameof(ActiveUser), ActiveUser) + .AddPolicy(nameof(Manager), Manager) + .AddPolicy(nameof(SiteMaintainer), SiteMaintainer) + .AddPolicy(nameof(StaffUser), StaffUser) + .AddPolicy(nameof(UserAdministrator), UserAdministrator); + } + // Default policy builder private static AuthorizationPolicyBuilder ActiveUserPolicyBuilder => new AuthorizationPolicyBuilder() .RequireAuthenticatedUser().AddRequirements(new ActiveUserRequirement()); diff --git a/src/AppServices/RegisterServices/AuthorizationPolicies.cs b/src/AppServices/RegisterServices/AuthorizationHandlers.cs similarity index 56% rename from src/AppServices/RegisterServices/AuthorizationPolicies.cs rename to src/AppServices/RegisterServices/AuthorizationHandlers.cs index 60eee4c..a70bc44 100644 --- a/src/AppServices/RegisterServices/AuthorizationPolicies.cs +++ b/src/AppServices/RegisterServices/AuthorizationHandlers.cs @@ -9,19 +9,11 @@ namespace MyApp.AppServices.RegisterServices; [SuppressMessage("Major Code Smell", "S125:Sections of code should not be commented out")] -public static class AuthorizationPolicies +public static class AuthorizationHandlers { - public static void AddAuthorizationPolicies(this IServiceCollection services) + public static void AddAuthorizationHandlers(this IServiceCollection services) { - // These policies are for use in PageModel class attributes, e.g.: - // [Authorize(Policy = nameof(Policies.ActiveUser))] - - services.AddAuthorizationBuilder() - .AddPolicy(nameof(Policies.ActiveUser), Policies.ActiveUser) - .AddPolicy(nameof(Policies.Manager), Policies.Manager) - .AddPolicy(nameof(Policies.SiteMaintainer), Policies.SiteMaintainer) - .AddPolicy(nameof(Policies.StaffUser), Policies.StaffUser) - .AddPolicy(nameof(Policies.UserAdministrator), Policies.UserAdministrator); + services.AddAuthorizationPolicies(); // Resource/operation-based permission handlers, e.g.: // var canAssign = await authorization.Succeeded(User, entryView, WorkEntryOperation.EditWorkEntry); diff --git a/src/AppServices/RegisterServices/Validators.cs b/src/AppServices/RegisterServices/Validators.cs index 311fd23..c75bd03 100644 --- a/src/AppServices/RegisterServices/Validators.cs +++ b/src/AppServices/RegisterServices/Validators.cs @@ -5,9 +5,7 @@ namespace MyApp.AppServices.RegisterServices; public static class Validators { - public static void AddValidators(this IServiceCollection services) - { - // Add all validators - services.AddValidatorsFromAssemblyContaining(typeof(RegisterAppServices)); - } + // Add all validators + public static void AddValidators(this IServiceCollection services) => + services.AddValidatorsFromAssemblyContaining(typeof(Validators)); } diff --git a/src/WebApp/Models/DisplayMessage.cs b/src/WebApp/Models/DisplayMessage.cs index ecf0020..1b01c97 100644 --- a/src/WebApp/Models/DisplayMessage.cs +++ b/src/WebApp/Models/DisplayMessage.cs @@ -2,7 +2,7 @@ namespace MyApp.WebApp.Models; -public record DisplayMessage(DisplayMessage.AlertContext Context, string Message, List Details) +public record DisplayMessage(DisplayMessage.AlertContext Context, string Message, List? Details = null) { [JsonIgnore] public string AlertClass => Context switch diff --git a/src/WebApp/Pages/Account/Index.cshtml b/src/WebApp/Pages/Account/Index.cshtml index 2891299..73b95a3 100644 --- a/src/WebApp/Pages/Account/Index.cshtml +++ b/src/WebApp/Pages/Account/Index.cshtml @@ -32,7 +32,7 @@ { Edit Profile } -
+
diff --git a/src/WebApp/Pages/Admin/Maintenance/EntryTypes/Edit.cshtml b/src/WebApp/Pages/Admin/Maintenance/EntryTypes/Edit.cshtml index bcf7f5e..5d71168 100644 --- a/src/WebApp/Pages/Admin/Maintenance/EntryTypes/Edit.cshtml +++ b/src/WebApp/Pages/Admin/Maintenance/EntryTypes/Edit.cshtml @@ -7,17 +7,7 @@

Edit @EditModel.ThisOption.SingularName


- - +

@Model.OriginalName

diff --git a/src/WebApp/Pages/Admin/Maintenance/Offices/Edit.cshtml b/src/WebApp/Pages/Admin/Maintenance/Offices/Edit.cshtml index 8ed0b94..5f777d0 100644 --- a/src/WebApp/Pages/Admin/Maintenance/Offices/Edit.cshtml +++ b/src/WebApp/Pages/Admin/Maintenance/Offices/Edit.cshtml @@ -9,17 +9,7 @@

Edit @EditModel.ThisOption.SingularName


- - +

@Model.OriginalName

diff --git a/src/WebApp/Pages/Admin/Maintenance/_MaintenanceItemEditWarning.cshtml b/src/WebApp/Pages/Admin/Maintenance/_MaintenanceItemEditWarning.cshtml new file mode 100644 index 0000000..9b217e5 --- /dev/null +++ b/src/WebApp/Pages/Admin/Maintenance/_MaintenanceItemEditWarning.cshtml @@ -0,0 +1,12 @@ +@model MaintenanceOption + + diff --git a/src/WebApp/Pages/Shared/Components/MainMenu/Default.cshtml b/src/WebApp/Pages/Shared/Components/MainMenu/Default.cshtml index cac2ccb..ebdb602 100644 --- a/src/WebApp/Pages/Shared/Components/MainMenu/Default.cshtml +++ b/src/WebApp/Pages/Shared/Components/MainMenu/Default.cshtml @@ -4,7 +4,7 @@ }
-