From c57ba17deedd20723ea13a356995d0705584aee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Thu, 18 Jan 2024 11:57:56 +0100 Subject: [PATCH 01/43] Upgrading to .NET 8 and OC 1.8.2 --- .../Lombiq.HelpfulExtensions.Tests.UI.csproj | 2 +- ...ntentSetContentPickerFieldDisplayDriver.cs | 8 ++--- .../ContentSets/Indexes/ContentSetIndex.cs | 7 ++-- .../Extensions/ContentSets/Migrations.cs | 9 ++--- .../ContentSets/Services/ContentSetManager.cs | 5 ++- .../Extensions/ContentTypes/Migrations.cs | 15 ++++---- .../Handlers/AdditionalStylingPartHandler.cs | 6 ++-- .../Navigation/AdminMenu.cs | 4 +-- .../OrchardExportToRecipeConverter.cs | 4 ++- ...tSecurityPermissionAuthorizationHandler.cs | 9 +++-- .../SiteTexts/LocalizationMigrations.cs | 7 ++-- .../SiteTexts/SiteTextMigrations.cs | 7 ++-- .../Drivers/MvcConditionEvaluatorDriver.cs | 4 +-- .../Extensions/Widgets/Migrations.cs | 35 ++++++++++--------- .../Lombiq.HelpfulExtensions.csproj | 26 +++++++------- .../Views/MenuWidget.cshtml | 1 + 16 files changed, 76 insertions(+), 73 deletions(-) diff --git a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj index 47b85a28..e3366a44 100644 --- a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj +++ b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 $(DefaultItemExcludes);.git*;node_modules\** diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs index 644cfa03..19a6a7b8 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; @@ -41,17 +41,17 @@ public override IDisplayResult Display( var name = fieldDisplayContext.PartFieldDefinition.Name; if (field.ContentItem.Get(name) is not { } part) return null; - return Initialize(GetDisplayShapeType(fieldDisplayContext), model => + return Initialize(GetDisplayShapeType(fieldDisplayContext), async model => { model.PartFieldDefinition = fieldDisplayContext.PartFieldDefinition; - return model.InitializeAsync( + await model.InitializeAsync( _contentSetManager, _contentSetEventHandlers, T, part, new ContentTypePartDefinition( name, - _contentDefinitionManager.GetPartDefinition(nameof(ContentSetPart)), + await _contentDefinitionManager.GetPartDefinitionAsync(nameof(ContentSetPart)), new JObject()), isNew: false); }) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs index b03fe52b..7a89ff46 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Microsoft.Extensions.DependencyInjection; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; @@ -37,15 +37,14 @@ public ContentSetIndexProvider(IServiceProvider provider) => _provider = provider; public override void Describe(DescribeContext context) => - context.For().Map(contentItem => + context.For().Map(async contentItem => { if (!contentItem.Latest) return Enumerable.Empty(); using var scope = _provider.CreateScope(); var contentDefinitionManager = scope.ServiceProvider.GetRequiredService(); - return contentDefinitionManager - .GetTypeDefinition(contentItem.ContentType) + return (await contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType)) .Parts .Where(part => part.PartDefinition.Name == nameof(ContentSetPart)) .Select(part => new { Part = contentItem.Get(part.Name), part.Name }) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs index 1c8364a7..46c3a4c4 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs @@ -1,9 +1,10 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Indexes; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Indexes; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulLibraries.OrchardCore.Data; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; +using System.Threading.Tasks; using YesSql.Sql; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets; @@ -15,14 +16,14 @@ public class Migrations : DataMigration public Migrations(IContentDefinitionManager contentDefinitionManager) => _contentDefinitionManager = contentDefinitionManager; - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterPartDefinition(nameof(ContentSetPart), builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(ContentSetPart), builder => builder .Attachable() .Reusable() .WithDisplayName("Content Set")); - SchemaBuilder.CreateMapIndexTable(table => table + await SchemaBuilder.CreateMapIndexTableAsync(table => table .Column(nameof(ContentSetIndex.ContentItemId), column => column.WithCommonUniqueIdLength()) .Column(nameof(ContentSetIndex.PartName)) .Column(nameof(ContentSetIndex.IsPublished)) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs index 5145175d..226bfa21 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Indexes; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using OrchardCore.ContentManagement; @@ -58,8 +58,7 @@ await _contentManager.CloneAsync(original) is not { } content) part.Key = newKey; }); - var contentTypePartDefinition = _contentDefinitionManager - .GetTypeDefinition(content.ContentType) + var contentTypePartDefinition = (await _contentDefinitionManager.GetTypeDefinitionAsync(content.ContentType)) .Parts .Single(definition => definition.Name == fromPartName); diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs index e07f5708..946d2380 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs @@ -2,6 +2,7 @@ using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; +using System.Threading.Tasks; using static Lombiq.HelpfulExtensions.Extensions.ContentTypes.ContentTypes; namespace Lombiq.HelpfulExtensions.Extensions.ContentTypes; @@ -13,9 +14,9 @@ public class Migrations : DataMigration public Migrations(IContentDefinitionManager contentDefinitionManager) => _contentDefinitionManager = contentDefinitionManager; - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterTypeDefinition(Page, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder .Creatable() .Securable() .Draftable() @@ -33,16 +34,16 @@ public int Create() .WithPart("FlowPart", part => part.WithPosition("2")) ); - _contentDefinitionManager.AlterTypeDefinition(Empty, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder .WithDescription("A base content type for ad-hoc welding parts or fields on.") ); return 3; } - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - _contentDefinitionManager.AlterTypeDefinition(Page, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder .WithPart("TitlePart", part => part.WithPosition("0")) .WithPart("AutoroutePart", part => part.WithPosition("1")) .WithPart("FlowPart", part => part.WithPosition("2")) @@ -51,9 +52,9 @@ public int UpdateFrom1() return 2; } - public int UpdateFrom2() + public async Task UpdateFrom2Async() { - _contentDefinitionManager.AlterTypeDefinition(Empty, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder .WithDescription("A base content type for ad-hoc welding parts or fields on.") ); diff --git a/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs b/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs index 8b43e9a3..8fa611b0 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs @@ -14,15 +14,13 @@ public class AdditionalStylingPartHandler : ContentHandlerBase public AdditionalStylingPartHandler(IContentDefinitionManager contentDefinitionManager) => _contentDefinitionManager = contentDefinitionManager; - public override Task ActivatedAsync(ActivatedContentContext context) + public override async Task ActivatedAsync(ActivatedContentContext context) { if (!context.ContentItem.Has() && - _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType) + (await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType)) .GetSettings().Stereotype == "Widget") { context.ContentItem.Weld(); } - - return Task.CompletedTask; } } diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs index 622ca6b7..3ada4e8a 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs @@ -1,9 +1,9 @@ -using Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Controllers; +using Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Controllers; using Lombiq.HelpfulLibraries.OrchardCore.Navigation; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Localization; +using OrchardCore.Modules; using OrchardCore.Navigation; -using System; using System.Threading.Tasks; namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Navigation; diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs index 8d3c669b..d414e453 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs @@ -37,7 +37,9 @@ public OrchardExportToRecipeConverter( _userConverters = userConverters; _contentTypes = contentDefinitionManager - .ListTypeDefinitions() + .ListTypeDefinitionsAsync() + .GetAwaiter() + .GetResult() .Select(definition => definition.Name) .ToList(); } diff --git a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs index 97af29b4..f61d44db 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs @@ -27,20 +27,20 @@ public class StrictSecurityPermissionAuthorizationHandler : AuthorizationHandler public StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) => _contentDefinitionManager = contentDefinitionManager; - protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement) + protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement) { if ((context.Resource as IContent)?.ContentItem is not { } contentItem || !_permissionTemplates.TryGetValue(requirement.Permission.Name, out var claims) || - _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType) is not { } definition || + await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType) is not { } definition || definition.GetSettings()?.Enabled != true) { - return Task.CompletedTask; + return; } if (!context.User.Identity.IsAuthenticated) { context.Fail(); - return Task.CompletedTask; + return; } var contentType = contentItem.ContentType; @@ -54,7 +54,6 @@ protected override Task HandleRequirementAsync(AuthorizationHandlerContext conte .Select(claim => claim.Value); if (!permissionNames.Any(claims.Contains)) context.Fail(); - return Task.CompletedTask; } private static IList GetPermissionTemplates(Permission permission, IList templates) diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs index 84a47879..f52bdd82 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs @@ -1,6 +1,7 @@ -using OrchardCore.ContentLocalization.Models; +using OrchardCore.ContentLocalization.Models; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Data.Migration; +using System.Threading.Tasks; using static Lombiq.HelpfulExtensions.Extensions.SiteTexts.Constants.ContentTypes; namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts; @@ -12,9 +13,9 @@ public class LocalizationMigrations : DataMigration public LocalizationMigrations(IContentDefinitionManager contentDefinitionManager) => _contentDefinitionManager = contentDefinitionManager; - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterTypeDefinition(SiteText, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder .WithPart(nameof(LocalizationPart))); return 1; diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs index 4a3f9d32..b7fb7ffe 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs @@ -1,9 +1,10 @@ -using OrchardCore.ContentLocalization.Models; +using OrchardCore.ContentLocalization.Models; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Builders; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; using OrchardCore.Markdown.Models; +using System.Threading.Tasks; using static Lombiq.HelpfulExtensions.Extensions.SiteTexts.Constants.ContentTypes; using static Lombiq.HelpfulLibraries.OrchardCore.Contents.ContentFieldEditorEnums; @@ -16,9 +17,9 @@ public class SiteTextMigrations : DataMigration public SiteTextMigrations(IContentDefinitionManager contentDefinitionManager) => _contentDefinitionManager = contentDefinitionManager; - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterTypeDefinition(SiteText, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder .SetAbilities( creatable: true, securable: true, diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs index 1eff2d27..7a29c2c1 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs @@ -1,8 +1,8 @@ -using Lombiq.HelpfulExtensions.Extensions.Widgets.Models; +using Lombiq.HelpfulExtensions.Extensions.Widgets.Models; using Microsoft.AspNetCore.Http; using OrchardCore.ContentManagement.Display.ContentDisplay; +using OrchardCore.Modules; using OrchardCore.Rules; -using System; using System.Linq; using System.Threading.Tasks; diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs index 9425ebee..00147782 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs @@ -4,6 +4,7 @@ using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; +using System.Threading.Tasks; using static Lombiq.HelpfulExtensions.Extensions.Widgets.WidgetTypes; namespace Lombiq.HelpfulExtensions.Extensions.Widgets; @@ -15,16 +16,16 @@ public class Migrations : DataMigration public Migrations(IContentDefinitionManager contentDefinitionManager) => _contentDefinitionManager = contentDefinitionManager; - public int Create() + public async Task CreateAsync() { - _contentDefinitionManager.AlterTypeDefinition(ContainerWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("TitlePart", part => part.WithPosition("0")) .WithPart("FlowPart", part => part.WithPosition("1")) ); - _contentDefinitionManager.AlterTypeDefinition(HtmlWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(HtmlWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("HtmlBodyPart", part => part @@ -36,7 +37,7 @@ public int Create() ) ); - _contentDefinitionManager.AlterTypeDefinition(LiquidWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(LiquidWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("LiquidPart", part => part @@ -44,12 +45,12 @@ public int Create() ) ); - _contentDefinitionManager.AlterTypeDefinition(MenuWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) ); - _contentDefinitionManager.AlterTypeDefinition(MarkdownWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("MarkdownBodyPart", part => part @@ -57,7 +58,7 @@ public int Create() ) ); - var contentItemWidgetPartName = _contentDefinitionManager.AlterPartDefinition(builder => builder + var contentItemWidgetPartName = await _contentDefinitionManager.AlterPartDefinitionAsync(builder => builder .WithField(part => part.ContentToDisplay, field => field .WithDisplayName("Content to display") .WithSettings(new ContentPickerFieldSettings @@ -69,7 +70,7 @@ public int Create() .WithField(part => part.GroupId, field => field.WithDisplayName("Group ID")) ); - _contentDefinitionManager.AlterTypeDefinition(WidgetTypes.ContentItemWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart(contentItemWidgetPartName) @@ -78,9 +79,9 @@ public int Create() return 5; } - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - _contentDefinitionManager.AlterTypeDefinition(ContainerWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder .WithPart("TitlePart", part => part.WithPosition("0")) .WithPart("FlowPart", part => part.WithPosition("1")) ); @@ -88,9 +89,9 @@ public int UpdateFrom1() return 2; } - public int UpdateFrom2() + public async Task UpdateFrom2Async() { - _contentDefinitionManager.AlterTypeDefinition(MenuWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) ); @@ -98,9 +99,9 @@ public int UpdateFrom2() return 3; } - public int UpdateFrom3() + public async Task UpdateFrom3Async() { - _contentDefinitionManager.AlterTypeDefinition(MarkdownWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("MarkdownBodyPart", part => part @@ -111,15 +112,15 @@ public int UpdateFrom3() return 4; } - public int UpdateFrom4() + public async Task UpdateFrom4Async() { - var contentItemWidgetPartName = _contentDefinitionManager.AlterPartDefinition(builder => builder + var contentItemWidgetPartName = await _contentDefinitionManager.AlterPartDefinitionAsync(builder => builder .WithField(part => part.ContentToDisplay, field => field.WithDisplayName("Content to display")) .WithField(part => part.DisplayType, field => field.WithDisplayName("Display type")) .WithField(part => part.GroupId, field => field.WithDisplayName("Group ID")) ); - _contentDefinitionManager.AlterTypeDefinition(WidgetTypes.ContentItemWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart(contentItemWidgetPartName) diff --git a/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj b/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj index 53028f47..d81fff29 100644 --- a/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj +++ b/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj @@ -3,7 +3,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\** @@ -36,18 +36,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/Lombiq.HelpfulExtensions/Views/MenuWidget.cshtml b/Lombiq.HelpfulExtensions/Views/MenuWidget.cshtml index 68d66eaf..9f57bc86 100644 --- a/Lombiq.HelpfulExtensions/Views/MenuWidget.cshtml +++ b/Lombiq.HelpfulExtensions/Views/MenuWidget.cshtml @@ -1,5 +1,6 @@ @using Lombiq.HelpfulLibraries.Common.Utilities; @using Microsoft.AspNetCore.Http.Extensions +@using OrchardCore.Modules @using OrchardCore.Navigation From d845d84dbfc07c9ebc995880f4e2c3c497ff132e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Fri, 19 Jan 2024 14:06:27 +0100 Subject: [PATCH 02/43] Addressing warnings. --- .../OrchardRecipeMigrationAdminController.cs | 4 +- .../Models/ContentSetContentPickerField.cs | 7 +-- .../Services/UserOrchardContentConverter.cs | 3 +- Lombiq.HelpfulExtensions/Manifest.cs | 54 +++++++++---------- 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs b/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs index 5858da19..b093f9e3 100644 --- a/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs +++ b/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs @@ -1,4 +1,4 @@ -using AngleSharp.Io; +using AngleSharp.Io; using Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Services; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -55,7 +55,7 @@ public async Task Convert(IFormFile file) json = await _converter.ConvertAsync(XDocument.Load(stream)); } - Response.Headers.Add("Content-Disposition", "attachment;filename=export.recipe.json"); + Response.Headers.Append("Content-Disposition", "attachment;filename=export.recipe.json"); return Content(json, MimeTypeNames.ApplicationJson, Encoding.UTF8); } } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs index cc50fbeb..469f24ae 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs @@ -1,12 +1,7 @@ -using OrchardCore.ContentManagement; -using System.Diagnostics.CodeAnalysis; +using OrchardCore.ContentManagement; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; -[SuppressMessage( - "Minor Code Smell", - "S2094:Classes should not be empty", - Justification = "Only data we need is the field name.")] public class ContentSetContentPickerField : ContentField { } diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs index 40533b6f..522e7970 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs @@ -2,7 +2,6 @@ using OrchardCore.Users.Models; using OrchardCore.Users.Services; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using System.Xml.Linq; using static Lombiq.HelpfulLibraries.OrchardCore.Users.PasswordHelper; @@ -30,7 +29,7 @@ public async Task ImportAsync(XElement element) return; var roles = element.Element("UserRolesPart").Attribute("Roles")?.Value; - var rolesList = string.IsNullOrEmpty(roles) ? new List() : roles.Split(',').ToList(); + var rolesList = string.IsNullOrEmpty(roles) ? new List() : [.. roles.Split(',')]; await _userService.CreateUserAsync( new User diff --git a/Lombiq.HelpfulExtensions/Manifest.cs b/Lombiq.HelpfulExtensions/Manifest.cs index 320f3350..29ff8210 100644 --- a/Lombiq.HelpfulExtensions/Manifest.cs +++ b/Lombiq.HelpfulExtensions/Manifest.cs @@ -13,10 +13,10 @@ Name = "Lombiq Helpful Extensions - Code Generation Helpful Extensions", Category = "Development", Description = "Generates migrations from content type definitions.", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Resources", - } + ] )] [assembly: Feature( @@ -24,10 +24,10 @@ Name = "Lombiq Helpful Extensions - Content Sets", Category = "Development", Description = "Create arbitrary collections of content items.", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.ContentManagement", - } + ] )] [assembly: Feature( @@ -35,10 +35,10 @@ Name = "Lombiq Helpful Extensions - Flows Helpful Extensions", Category = "Content", Description = "Adds additional styling capabilities to Flow Part.", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Flows", - } + ] )] [assembly: Feature( @@ -46,12 +46,12 @@ Name = "Lombiq Helpful Extensions - Helpful Widgets", Category = "Content", Description = "Adds helpful widgets such as Container or Liquid widgets.", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Html", "OrchardCore.Liquid", "OrchardCore.Title", - } + ] )] [assembly: Feature( @@ -59,12 +59,12 @@ Name = "Lombiq Helpful Extensions - Helpful Content Types", Category = "Content", Description = "Adds helpful content types such as Page.", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Autoroute", "OrchardCore.Flows", "OrchardCore.Title", - } + ] )] [assembly: Feature( @@ -86,10 +86,10 @@ Name = "Lombiq Helpful Extensions - Emails", Category = "Messaging", Description = "Adds shape-based email template rendering and helpful email sending services.", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Email", - } + ] )] [assembly: Feature( @@ -107,10 +107,10 @@ "Adds a content type that lets the users with admin dashboard access customize string/HTML resources on the " + "site via Markdown. If OrchardCore.ContentLocalization is enabled, it also tries to retrieve the localized " + "version if available.", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Markdown", - } + ] )] [assembly: Feature( @@ -121,10 +121,10 @@ "Convert Orchard 1's export XML files into Orchard Core recipes. This feature contains the basics like " + "CommonPart and BodyPart (full list is in the Helpful Extensions repository readme), but can be extended " + "with additional converters that only have to handle more specialized export data.", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Contents", - } + ] )] [assembly: Feature( @@ -132,11 +132,11 @@ Name = "Lombiq Helpful Extensions - Reset password workflow activity", Category = "Security", Description = "Adds generate reset password token activity.", - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Users.ResetPassword", "OrchardCore.Workflows", - } + ] )] [assembly: Feature( From c7e673188b8bf5a278f1887a7c509871ead0f07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 20 Jan 2024 12:12:33 +0100 Subject: [PATCH 03/43] Addressing warnings. --- .../Controllers/ContentSetController.cs | 17 ++----- .../OrchardRecipeMigrationAdminController.cs | 22 +++------ .../CodeGenerationDisplayDriver.cs | 8 ++- .../Drivers/ContentSetPartDisplayDriver.cs | 37 +++++--------- .../ContentSets/Indexes/ContentSetIndex.cs | 11 +---- .../Extensions/ContentSets/Migrations.cs | 9 +--- .../ContentSets/Services/ContentSetManager.cs | 39 +++++---------- .../ContentSetGetSupportedOptionsEvent.cs | 10 ++-- .../ContentSetCreatingEventDisplayDriver.cs | 19 +++---- .../WorkflowContentSetEventHandler.cs | 23 +++------ .../Extensions/ContentTypes/Migrations.cs | 15 ++---- .../ShapeBasedEmailTemplateService.cs | 15 ++---- .../Handlers/AdditionalStylingPartHandler.cs | 9 +--- .../OrchardExportToRecipeConverter.cs | 49 ++++++------------- .../Services/UserOrchardContentConverter.cs | 19 ++----- .../ContentLocalizationSiteTextService.cs | 16 +++--- .../SiteTexts/SiteTextMigrations.cs | 7 +-- .../TargetBlank/Filters/TargetBlankFilter.cs | 6 +-- .../Drivers/MvcConditionDisplayDriver.cs | 17 +++---- .../Widgets/Liquid/MenuWidgetLiquidFilter.cs | 34 +++++-------- .../Extensions/Widgets/Migrations.cs | 7 +-- .../Widgets/ViewModels/MenuWidgetViewModel.cs | 14 ++---- ...rateResetPasswordTokenTaskDisplayDriver.cs | 11 +---- 23 files changed, 125 insertions(+), 289 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Controllers/ContentSetController.cs b/Lombiq.HelpfulExtensions/Controllers/ContentSetController.cs index 03b929c7..6c7845ad 100644 --- a/Lombiq.HelpfulExtensions/Controllers/ContentSetController.cs +++ b/Lombiq.HelpfulExtensions/Controllers/ContentSetController.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; using Microsoft.AspNetCore.Mvc; using OrchardCore; using OrchardCore.Modules; @@ -7,19 +7,10 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Controllers; [Feature(FeatureIds.ContentSets)] -public class ContentSetController : Controller +public class ContentSetController(IContentSetManager contentSetManager, IOrchardHelper orchardHelper) : Controller { - private readonly IContentSetManager _contentSetManager; - private readonly IOrchardHelper _orchardHelper; - - public ContentSetController(IContentSetManager contentSetManager, IOrchardHelper orchardHelper) - { - _contentSetManager = contentSetManager; - _orchardHelper = orchardHelper; - } - public async Task Create(string fromContentItemId, string fromPartName, string newKey) => - await _contentSetManager.CloneContentItemAsync(fromContentItemId, fromPartName, newKey) is { } content - ? Redirect(_orchardHelper.GetItemEditUrl(content)) + await contentSetManager.CloneContentItemAsync(fromContentItemId, fromPartName, newKey) is { } content + ? Redirect(orchardHelper.GetItemEditUrl(content)) : NotFound(); } diff --git a/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs b/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs index b093f9e3..a4992d7f 100644 --- a/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs +++ b/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs @@ -16,21 +16,11 @@ namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Controllers [Admin] [Feature(FeatureIds.OrchardRecipeMigration)] -public class OrchardRecipeMigrationAdminController : Controller +public class OrchardRecipeMigrationAdminController( + INotifier notifier, + IOrchardExportToRecipeConverter converter, + IHtmlLocalizer localizer) : Controller { - private readonly INotifier _notifier; - private readonly IOrchardExportToRecipeConverter _converter; - private readonly IHtmlLocalizer H; - public OrchardRecipeMigrationAdminController( - INotifier notifier, - IOrchardExportToRecipeConverter converter, - IHtmlLocalizer localizer) - { - _notifier = notifier; - _converter = converter; - H = localizer; - } - public IActionResult Index() => View(); [HttpPost] @@ -46,13 +36,13 @@ public async Task Convert(IFormFile file) } catch (Exception) { - await _notifier.ErrorAsync(H["Please add a file to import."]); + await notifier.ErrorAsync(localizer["Please add a file to import."]); return Redirect(nameof(Index)); } await using (stream) { - json = await _converter.ConvertAsync(XDocument.Load(stream)); + json = await converter.ConvertAsync(XDocument.Load(stream)); } Response.Headers.Append("Content-Disposition", "attachment;filename=export.recipe.json"); diff --git a/Lombiq.HelpfulExtensions/Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs index 67edb7f2..206d105a 100644 --- a/Lombiq.HelpfulExtensions/Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs @@ -12,12 +12,10 @@ namespace Lombiq.HelpfulExtensions.Extensions.CodeGeneration; -public class CodeGenerationDisplayDriver : ContentTypeDefinitionDisplayDriver +public class CodeGenerationDisplayDriver(IStringLocalizer stringLocalizer) + : ContentTypeDefinitionDisplayDriver { - private readonly IStringLocalizer T; - - public CodeGenerationDisplayDriver(IStringLocalizer stringLocalizer) => - T = stringLocalizer; + private readonly IStringLocalizer T = stringLocalizer; public override IDisplayResult Edit(ContentTypeDefinition model) => Initialize( diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs index 9b7f7cf1..8de2748d 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs @@ -14,34 +14,21 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; -public class ContentSetPartDisplayDriver : ContentPartDisplayDriver +public class ContentSetPartDisplayDriver( + IContentSetManager contentSetManager, + IIdGenerator idGenerator, + IEnumerable contentSetEventHandlers, + IStringLocalizer stringLocalizer) : ContentPartDisplayDriver { private const string ShapeType = $"{nameof(ContentSetPart)}_{CommonContentDisplayTypes.SummaryAdmin}"; - private readonly IContentSetManager _contentSetManager; - private readonly IIdGenerator _idGenerator; - private readonly IEnumerable _contentSetEventHandlers; - private readonly IStringLocalizer T; - - public ContentSetPartDisplayDriver( - IContentSetManager contentSetManager, - IIdGenerator idGenerator, - IEnumerable contentSetEventHandlers, - IStringLocalizer stringLocalizer) - { - _contentSetManager = contentSetManager; - _idGenerator = idGenerator; - _contentSetEventHandlers = contentSetEventHandlers; - T = stringLocalizer; - } - public override IDisplayResult Display(ContentSetPart part, BuildPartDisplayContext context) { ValueTask InitializeAsync(ContentSetPartViewModel model) => model.InitializeAsync( - _contentSetManager, - _contentSetEventHandlers, - T, + contentSetManager, + contentSetEventHandlers, + stringLocalizer, part, context.TypePartDefinition, isNew: false); @@ -56,9 +43,9 @@ ValueTask InitializeAsync(ContentSetPartViewModel model) => public override IDisplayResult Edit(ContentSetPart part, BuildPartEditorContext context) => Initialize($"{nameof(ContentSetPart)}_Edit", model => model.InitializeAsync( - _contentSetManager, - _contentSetEventHandlers, - T, + contentSetManager, + contentSetEventHandlers, + stringLocalizer, part, context.TypePartDefinition, context.IsNew)) @@ -79,7 +66,7 @@ public override async Task UpdateAsync( // item has not been saved yet. if (string.IsNullOrEmpty(part.ContentSet)) { - part.ContentSet = _idGenerator.GenerateUniqueId(); + part.ContentSet = idGenerator.GenerateUniqueId(); } } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs index 7a89ff46..d36aece1 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs @@ -27,21 +27,14 @@ public static ContentSetIndex FromPart(ContentSetPart part, string partName) => }; } -public class ContentSetIndexProvider : IndexProvider +public class ContentSetIndexProvider(IServiceProvider provider) : IndexProvider { - private readonly IServiceProvider _provider; - - // We can't inject Lazy because it will throw a "Cannot resolve scoped service - // 'OrchardCore.ContentManagement.Metadata.IContentDefinitionManager' from root provider." exception. - public ContentSetIndexProvider(IServiceProvider provider) => - _provider = provider; - public override void Describe(DescribeContext context) => context.For().Map(async contentItem => { if (!contentItem.Latest) return Enumerable.Empty(); - using var scope = _provider.CreateScope(); + using var scope = provider.CreateScope(); var contentDefinitionManager = scope.ServiceProvider.GetRequiredService(); return (await contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType)) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs index 46c3a4c4..e659e86a 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs @@ -9,16 +9,11 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets; -public class Migrations : DataMigration +public class Migrations(IContentDefinitionManager contentDefinitionManager) : DataMigration { - private readonly IContentDefinitionManager _contentDefinitionManager; - - public Migrations(IContentDefinitionManager contentDefinitionManager) => - _contentDefinitionManager = contentDefinitionManager; - public async Task CreateAsync() { - await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(ContentSetPart), builder => builder + await contentDefinitionManager.AlterPartDefinitionAsync(nameof(ContentSetPart), builder => builder .Attachable() .Reusable() .WithDisplayName("Content Set")); diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs index 226bfa21..7174b536 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs @@ -11,43 +11,30 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; -public class ContentSetManager : IContentSetManager +public class ContentSetManager( + IContentDefinitionManager contentDefinitionManager, + IContentManager contentManager, + IEnumerable contentSetEventHandlers, + ISession session) : IContentSetManager { - private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly IContentManager _contentManager; - private readonly IEnumerable _contentSetEventHandlers; - private readonly ISession _session; - - public ContentSetManager( - IContentDefinitionManager contentDefinitionManager, - IContentManager contentManager, - IEnumerable contentSetEventHandlers, - ISession session) - { - _contentDefinitionManager = contentDefinitionManager; - _contentManager = contentManager; - _contentSetEventHandlers = contentSetEventHandlers; - _session = session; - } - public Task> GetIndexAsync(string setId) => - _session.QueryIndex(index => index.ContentSet == setId).ListAsync(); + session.QueryIndex(index => index.ContentSet == setId).ListAsync(); public async Task> GetContentItemsAsync(string setId) => - await _contentManager.GetAsync((await GetIndexAsync(setId)).Select(index => index.ContentItemId)); + await contentManager.GetAsync((await GetIndexAsync(setId)).Select(index => index.ContentItemId)); public async Task CloneContentItemAsync(string fromContentItemId, string fromPartName, string newKey) { if (string.IsNullOrEmpty(fromPartName)) fromPartName = nameof(ContentSetPart); - if (await _contentManager.GetAsync(fromContentItemId) is not { } original || + if (await contentManager.GetAsync(fromContentItemId) is not { } original || original.Get(fromPartName)?.ContentSet is not { } contentSet || - await _contentManager.CloneAsync(original) is not { } content) + await contentManager.CloneAsync(original) is not { } content) { return null; } - var exists = await _session + var exists = await session .QueryIndex(index => index.ContentSet == contentSet && index.Key == newKey) .FirstOrDefaultAsync() is not null; if (exists) throw new InvalidOperationException($"The key \"{newKey}\" already exists for the content set \"{contentSet}\"."); @@ -58,16 +45,16 @@ await _contentManager.CloneAsync(original) is not { } content) part.Key = newKey; }); - var contentTypePartDefinition = (await _contentDefinitionManager.GetTypeDefinitionAsync(content.ContentType)) + var contentTypePartDefinition = (await contentDefinitionManager.GetTypeDefinitionAsync(content.ContentType)) .Parts .Single(definition => definition.Name == fromPartName); - foreach (var handler in _contentSetEventHandlers) + foreach (var handler in contentSetEventHandlers) { await handler.CreatingAsync(content, contentTypePartDefinition, contentSet, newKey); } - await _contentManager.PublishAsync(content); + await contentManager.PublishAsync(content); return content; } } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs index 239f4030..83f1cf10 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs @@ -1,17 +1,13 @@ -using Lombiq.HelpfulLibraries.OrchardCore.Workflow; +using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.Extensions.Localization; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; -public class ContentSetGetSupportedOptionsEvent : SimpleEventActivityBase +public class ContentSetGetSupportedOptionsEvent(IStringLocalizer stringLocalizer) + : SimpleEventActivityBase(stringLocalizer) { public const string OutputName = "MemberLinks"; public override LocalizedString DisplayText => T["Get Supported Content Set Options"]; public override LocalizedString Category => T["Content Sets"]; - - public ContentSetGetSupportedOptionsEvent(IStringLocalizer stringLocalizer) - : base(stringLocalizer) - { - } } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs index e452782e..53bf1920 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.AspNetCore.Mvc.Localization; @@ -10,12 +10,14 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Drivers; -public class ContentSetCreatingEventDisplayDriver : DocumentedEventActivityDisplayDriverBase +public class ContentSetCreatingEventDisplayDriver( + INotifier notifier, + IStringLocalizer baseLocalizer, + IHtmlLocalizer htmlLocalizer) + : DocumentedEventActivityDisplayDriverBase(notifier, baseLocalizer) { - private readonly IHtmlLocalizer H; - public override string IconClass => "fa-circle-half-stroke"; - public override LocalizedHtmlString Description => H["Executes when a new content item is created in the content set."]; + public override LocalizedHtmlString Description => htmlLocalizer["Executes when a new content item is created in the content set."]; public override IDictionary AvailableInputs { get; } = new Dictionary { [nameof(CreatingContext.ContentItem)] = nameof(ContentItem), @@ -23,11 +25,4 @@ public class ContentSetCreatingEventDisplayDriver : DocumentedEventActivityDispl [nameof(CreatingContext.ContentSet)] = "string", [nameof(CreatingContext.NewKey)] = "string", }; - - public ContentSetCreatingEventDisplayDriver( - INotifier notifier, - IStringLocalizer baseLocalizer, - IHtmlLocalizer htmlLocalizer) - : base(notifier, baseLocalizer) => - H = htmlLocalizer; } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs index f7e34c3b..2cbe8784 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; @@ -17,19 +17,10 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Handlers; -public class WorkflowContentSetEventHandler : IContentSetEventHandler +public class WorkflowContentSetEventHandler( + IWorkflowManager workflowManager, + IWorkflowTypeStore workflowTypeStore) : IContentSetEventHandler { - private readonly IWorkflowManager _workflowManager; - private readonly IWorkflowTypeStore _workflowTypeStore; - - public WorkflowContentSetEventHandler( - IWorkflowManager workflowManager, - IWorkflowTypeStore workflowTypeStore) - { - _workflowManager = workflowManager; - _workflowTypeStore = workflowTypeStore; - } - public async Task> GetSupportedOptionsAsync( ContentSetPart part, ContentTypePartDefinition definition) @@ -38,8 +29,8 @@ public async Task> GetSupportedOptionsAsync var values = new GetSupportedOptionsContext(definition, part).ToDictionary(); - var workflowContexts = await _workflowManager - .TriggerEventAndGetContextsAsync(_workflowTypeStore, values); + var workflowContexts = await workflowManager + .TriggerEventAndGetContextsAsync(workflowTypeStore, values); foreach (var context in workflowContexts) { @@ -75,7 +66,7 @@ public Task CreatingAsync( ContentTypePartDefinition definition, string contentSet, string newKey) => - _workflowManager.TriggerEventAsync( + workflowManager.TriggerEventAsync( new CreatingContext(content, definition, contentSet, newKey), $"{nameof(WorkflowContentSetEventHandler)}.{nameof(CreatingAsync)}" + $"({content.ContentItemId}, {definition.Name}, {contentSet}, {newKey})"); diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs index 946d2380..522b342f 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs @@ -7,16 +7,11 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentTypes; -public class Migrations : DataMigration +public class Migrations(IContentDefinitionManager contentDefinitionManager) : DataMigration { - private readonly IContentDefinitionManager _contentDefinitionManager; - - public Migrations(IContentDefinitionManager contentDefinitionManager) => - _contentDefinitionManager = contentDefinitionManager; - public async Task CreateAsync() { - await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder .Creatable() .Securable() .Draftable() @@ -34,7 +29,7 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builde .WithPart("FlowPart", part => part.WithPosition("2")) ); - await _contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder .WithDescription("A base content type for ad-hoc welding parts or fields on.") ); @@ -43,7 +38,7 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => build public async Task UpdateFrom1Async() { - await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder .WithPart("TitlePart", part => part.WithPosition("0")) .WithPart("AutoroutePart", part => part.WithPosition("1")) .WithPart("FlowPart", part => part.WithPosition("2")) @@ -54,7 +49,7 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builde public async Task UpdateFrom2Async() { - await _contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder .WithDescription("A base content type for ad-hoc welding parts or fields on.") ); diff --git a/Lombiq.HelpfulExtensions/Extensions/Emails/Services/ShapeBasedEmailTemplateService.cs b/Lombiq.HelpfulExtensions/Extensions/Emails/Services/ShapeBasedEmailTemplateService.cs index 57d3dd92..6ed6efb7 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Emails/Services/ShapeBasedEmailTemplateService.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Emails/Services/ShapeBasedEmailTemplateService.cs @@ -5,23 +5,14 @@ namespace Lombiq.HelpfulExtensions.Extensions.Emails.Services; -public class ShapeBasedEmailTemplateService : IEmailTemplateService +public class ShapeBasedEmailTemplateService(IShapeFactory shapeFactory, IShapeRenderer shapeRenderer) : IEmailTemplateService { - private readonly IShapeFactory _shapeFactory; - private readonly IShapeRenderer _shapeRenderer; - - public ShapeBasedEmailTemplateService(IShapeFactory shapeFactory, IShapeRenderer shapeRenderer) - { - _shapeFactory = shapeFactory; - _shapeRenderer = shapeRenderer; - } - public async Task RenderEmailTemplateAsync(string emailTemplateId, object model = null) { ExceptionHelpers.ThrowIfNull(emailTemplateId, nameof(emailTemplateId)); - var shape = await _shapeFactory.CreateAsync($"EmailTemplate__{emailTemplateId}", Arguments.From(model ?? new { })); + var shape = await shapeFactory.CreateAsync($"EmailTemplate__{emailTemplateId}", Arguments.From(model ?? new { })); - return await _shapeRenderer.RenderAsync(shape); + return await shapeRenderer.RenderAsync(shape); } } diff --git a/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs b/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs index 8fa611b0..a9b8c568 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs @@ -7,17 +7,12 @@ namespace Lombiq.HelpfulExtensions.Extensions.Flows.Handlers; -public class AdditionalStylingPartHandler : ContentHandlerBase +public class AdditionalStylingPartHandler(IContentDefinitionManager contentDefinitionManager) : ContentHandlerBase { - private readonly IContentDefinitionManager _contentDefinitionManager; - - public AdditionalStylingPartHandler(IContentDefinitionManager contentDefinitionManager) => - _contentDefinitionManager = contentDefinitionManager; - public override async Task ActivatedAsync(ActivatedContentContext context) { if (!context.ContentItem.Has() && - (await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType)) + (await contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType)) .GetSettings().Stereotype == "Widget") { context.ContentItem.Weld(); diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs index d414e453..a7847ad1 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs @@ -12,37 +12,20 @@ namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Services; -public class OrchardExportToRecipeConverter : IOrchardExportToRecipeConverter +public class OrchardExportToRecipeConverter( + IContentDefinitionManager contentDefinitionManager, + IContentManager contentManager, + IIdGenerator idGenerator, + IEnumerable exportConverters, + IEnumerable contentConverters, + IEnumerable userConverters) : IOrchardExportToRecipeConverter { - private readonly IContentManager _contentManager; - private readonly IIdGenerator _idGenerator; - private readonly IEnumerable _exportConverters; - private readonly IEnumerable _contentConverters; - private readonly IEnumerable _userConverters; - - private readonly ICollection _contentTypes; - - public OrchardExportToRecipeConverter( - IContentDefinitionManager contentDefinitionManager, - IContentManager contentManager, - IIdGenerator idGenerator, - IEnumerable exportConverters, - IEnumerable contentConverters, - IEnumerable userConverters) - { - _contentManager = contentManager; - _idGenerator = idGenerator; - _exportConverters = exportConverters; - _contentConverters = contentConverters; - _userConverters = userConverters; - - _contentTypes = contentDefinitionManager + private readonly List _contentTypes = contentDefinitionManager .ListTypeDefinitionsAsync() .GetAwaiter() .GetResult() .Select(definition => definition.Name) .ToList(); - } public async Task ConvertAsync(XDocument export) { @@ -53,10 +36,10 @@ public async Task ConvertAsync(XDocument export) { if (await CreateContentItemAsync(content) is { } contentItem) { - contentItem.ContentItemId ??= _idGenerator.GenerateUniqueId(); - contentItem.ContentItemVersionId ??= _idGenerator.GenerateUniqueId(); + contentItem.ContentItemId ??= idGenerator.GenerateUniqueId(); + contentItem.ContentItemVersionId ??= idGenerator.GenerateUniqueId(); - await _contentConverters + await contentConverters .Where(converter => converter.IsApplicable(content)) .OrderBy(converter => converter.Order) .AwaitEachAsync(converter => converter.ImportAsync(content, contentItem)); @@ -65,13 +48,13 @@ await _contentConverters } else if (content.Name == nameof(User)) { - var customUserConverter = _userConverters.FirstOrDefault(converter => converter.IgnoreDefaultConverter); - var userConverter = customUserConverter ?? _userConverters.First(); + var customUserConverter = userConverters.FirstOrDefault(converter => converter.IgnoreDefaultConverter); + var userConverter = customUserConverter ?? userConverters.First(); await userConverter.ImportAsync(content); } } - foreach (var converter in _exportConverters) + foreach (var converter in exportConverters) { await converter.UpdateContentItemsAsync(export, contentItems); } @@ -84,7 +67,7 @@ await _contentConverters private async Task CreateContentItemAsync(XElement content) { - foreach (var converter in _contentConverters.OrderBy(converter => converter.Order)) + foreach (var converter in contentConverters.OrderBy(converter => converter.Order)) { if (converter.IsApplicable(content) && await converter.CreateContentItemAsync(content) is { } contentItem) { @@ -93,7 +76,7 @@ private async Task CreateContentItemAsync(XElement content) } return _contentTypes.Contains(content.Name.LocalName) - ? await _contentManager.NewAsync(content.Name.LocalName) + ? await contentManager.NewAsync(content.Name.LocalName) : null; } } diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs index 522e7970..a1482bb0 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs @@ -8,19 +8,10 @@ namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Services; -public class UserOrchardContentConverter : IOrchardUserConverter +public class UserOrchardContentConverter( + IUserService userService, + ILogger logger) : IOrchardUserConverter { - private readonly IUserService _userService; - private readonly ILogger _logger; - - public UserOrchardContentConverter( - IUserService userService, - ILogger logger) - { - _userService = userService; - _logger = logger; - } - public bool IgnoreDefaultConverter => false; public async Task ImportAsync(XElement element) @@ -31,7 +22,7 @@ public async Task ImportAsync(XElement element) var roles = element.Element("UserRolesPart").Attribute("Roles")?.Value; var rolesList = string.IsNullOrEmpty(roles) ? new List() : [.. roles.Split(',')]; - await _userService.CreateUserAsync( + await userService.CreateUserAsync( new User { UserName = userPart.Attribute("UserName")?.Value, @@ -41,7 +32,7 @@ await _userService.CreateUserAsync( RoleNames = rolesList, }, GenerateRandomPassword(32), - (_, message) => _logger.LogError("User creation failed: \"{Message}\"", message)); + (_, message) => logger.LogError("User creation failed: \"{Message}\"", message)); return; } diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs index 18a24a14..8d2148cf 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Html; using OrchardCore.ContentLocalization; using OrchardCore.ContentLocalization.Models; using OrchardCore.ContentManagement; @@ -9,16 +9,12 @@ namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts.Services; -public class ContentLocalizationSiteTextService : SiteTextServiceBase +public class ContentLocalizationSiteTextService( + IContentManager contentManager, + IContentLocalizationManager contentLocalizationManager, + IMarkdownService markdownService) : SiteTextServiceBase(contentManager, markdownService) { - private readonly IContentLocalizationManager _contentLocalizationManager; - - public ContentLocalizationSiteTextService( - IContentManager contentManager, - IContentLocalizationManager contentLocalizationManager, - IMarkdownService markdownService) - : base(contentManager, markdownService) => - _contentLocalizationManager = contentLocalizationManager; + private readonly IContentLocalizationManager _contentLocalizationManager = contentLocalizationManager; public override async Task RenderHtmlByIdAsync(string contentItemId) { diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs index b7fb7ffe..eae5dcb1 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs @@ -10,12 +10,9 @@ namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts; -public class SiteTextMigrations : DataMigration +public class SiteTextMigrations(IContentDefinitionManager contentDefinitionManager) : DataMigration { - private readonly IContentDefinitionManager _contentDefinitionManager; - - public SiteTextMigrations(IContentDefinitionManager contentDefinitionManager) => - _contentDefinitionManager = contentDefinitionManager; + private readonly IContentDefinitionManager _contentDefinitionManager = contentDefinitionManager; public async Task CreateAsync() { diff --git a/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs b/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs index d89bfc13..13c93b5e 100644 --- a/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs @@ -6,11 +6,9 @@ namespace Lombiq.HelpfulExtensions.Extensions.TargetBlank.Filters; -public class TargetBlankFilter : IAsyncResultFilter +public class TargetBlankFilter(IResourceManager resourceManager) : IAsyncResultFilter { - private readonly IResourceManager _resourceManager; - - public TargetBlankFilter(IResourceManager resourceManager) => _resourceManager = resourceManager; + private readonly IResourceManager _resourceManager = resourceManager; public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionDisplayDriver.cs index 54df6e64..0a76fb70 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionDisplayDriver.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.Widgets.Models; +using Lombiq.HelpfulExtensions.Extensions.Widgets.Models; using Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Localization; @@ -11,17 +11,12 @@ namespace Lombiq.HelpfulExtensions.Extensions.Widgets.Drivers; -public class MvcConditionDisplayDriver : ConditionDisplayDriver +public class MvcConditionDisplayDriver( + IHtmlLocalizer htmlLocalizer, + IStringLocalizer stringLocalizer) : ConditionDisplayDriver { - private readonly IHtmlLocalizer H; - private readonly IStringLocalizer T; - public MvcConditionDisplayDriver( - IHtmlLocalizer htmlLocalizer, - IStringLocalizer stringLocalizer) - { - H = htmlLocalizer; - T = stringLocalizer; - } + private readonly IHtmlLocalizer H = htmlLocalizer; + private readonly IStringLocalizer T = stringLocalizer; protected override IDisplayResult GetEditor(MvcCondition model) => Initialize("MvcCondition_Fields_Edit", viewModel => diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs index 2cc0ac4a..a1ac482e 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs @@ -1,4 +1,4 @@ -using Fluid; +using Fluid; using Fluid.Values; using Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels; using Lombiq.HelpfulLibraries.OrchardCore.Liquid; @@ -17,25 +17,16 @@ namespace Lombiq.HelpfulExtensions.Extensions.Widgets.Liquid; -public class MenuWidgetLiquidFilter : ILiquidFilter +public class MenuWidgetLiquidFilter( + IActionContextAccessor actionContextAccessor, + ILiquidContentDisplayService liquidContentDisplayService, + IStringLocalizer stringLocalizer, + IUrlHelperFactory urlHelperFactory) : ILiquidFilter { - private readonly ILiquidContentDisplayService _liquidContentDisplayService; - private readonly Lazy _urlHelperLazy; - private readonly IStringLocalizer T; - - public MenuWidgetLiquidFilter( - IActionContextAccessor actionContextAccessor, - ILiquidContentDisplayService liquidContentDisplayService, - IStringLocalizer stringLocalizer, - IUrlHelperFactory urlHelperFactory) - { - _liquidContentDisplayService = liquidContentDisplayService; - - _urlHelperLazy = new Lazy(() => + private readonly ILiquidContentDisplayService _liquidContentDisplayService = liquidContentDisplayService; + private readonly Lazy _urlHelperLazy = new Lazy(() => urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext!)); - - T = stringLocalizer; - } + private readonly IStringLocalizer T = stringLocalizer; public ValueTask ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext context) { @@ -98,12 +89,9 @@ private void UpdateMenuItems(IEnumerable menuItems, bool localNav) } } - public class LocalizedStringJsonConverter : JsonConverter + public class LocalizedStringJsonConverter(IStringLocalizer stringLocalizer) : JsonConverter { - private readonly IStringLocalizer T; - - public LocalizedStringJsonConverter(IStringLocalizer stringLocalizer) => - T = stringLocalizer; + private readonly IStringLocalizer T = stringLocalizer; public override void WriteJson(JsonWriter writer, LocalizedString value, JsonSerializer serializer) => writer.WriteValue(value?.Value); diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs index 00147782..3fecdc7c 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs @@ -9,12 +9,9 @@ namespace Lombiq.HelpfulExtensions.Extensions.Widgets; -public class Migrations : DataMigration +public class Migrations(IContentDefinitionManager contentDefinitionManager) : DataMigration { - private readonly IContentDefinitionManager _contentDefinitionManager; - - public Migrations(IContentDefinitionManager contentDefinitionManager) => - _contentDefinitionManager = contentDefinitionManager; + private readonly IContentDefinitionManager _contentDefinitionManager = contentDefinitionManager; public async Task CreateAsync() { diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/ViewModels/MenuWidgetViewModel.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/ViewModels/MenuWidgetViewModel.cs index 48e7cdef..1c184418 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/ViewModels/MenuWidgetViewModel.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/ViewModels/MenuWidgetViewModel.cs @@ -1,14 +1,14 @@ -using OrchardCore.Navigation; +using OrchardCore.Navigation; using System.Collections.Generic; using System.Linq; namespace Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels; -public class MenuWidgetViewModel +public class MenuWidgetViewModel(bool noWrapper, IEnumerable menuItems) { - public bool NoWrapper { get; set; } + public bool NoWrapper { get; set; } = noWrapper; - public IEnumerable MenuItems { get; set; } + public IEnumerable MenuItems { get; set; } = menuItems ?? Enumerable.Empty(); public string HtmlClasses { get; set; } = string.Empty; @@ -17,12 +17,6 @@ public MenuWidgetViewModel() { } - public MenuWidgetViewModel(bool noWrapper, IEnumerable menuItems) - { - NoWrapper = noWrapper; - MenuItems = menuItems ?? Enumerable.Empty(); - } - public MenuWidgetViewModel(dynamic model) : this((model.NoWrapper as bool?) == true, model.MenuItems as IEnumerable) => HtmlClasses = model.HtmlClasses as string ?? string.Empty; diff --git a/Lombiq.HelpfulExtensions/Extensions/Workflows/Drivers/GenerateResetPasswordTokenTaskDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/Workflows/Drivers/GenerateResetPasswordTokenTaskDisplayDriver.cs index 32be3ce2..b4d4d66c 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Workflows/Drivers/GenerateResetPasswordTokenTaskDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Workflows/Drivers/GenerateResetPasswordTokenTaskDisplayDriver.cs @@ -1,6 +1,5 @@ using Lombiq.HelpfulExtensions.Extensions.Workflows.Activities; using Lombiq.HelpfulExtensions.Extensions.Workflows.ViewModels; -using Microsoft.Extensions.Localization; using OrchardCore.DisplayManagement.ModelBinding; using OrchardCore.DisplayManagement.Views; using OrchardCore.Users.Models; @@ -10,15 +9,9 @@ namespace Lombiq.HelpfulExtensions.Extensions.Workflows.Drivers; -public class GenerateResetPasswordTokenTaskDisplayDriver : ActivityDisplayDriver< - GenerateResetPasswordTokenTask, - GenerateResetPasswordTokenTaskViewModel> +public class GenerateResetPasswordTokenTaskDisplayDriver + : ActivityDisplayDriver { - private readonly IStringLocalizer T; - - public GenerateResetPasswordTokenTaskDisplayDriver(IStringLocalizer localizer) => - T = localizer; - protected override void EditActivity(GenerateResetPasswordTokenTask activity, GenerateResetPasswordTokenTaskViewModel model) { model.UserExpression = activity.User.Expression; From a41d98e2a2b18b5a905b0bcf0d87ab06d93c10c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 20 Jan 2024 12:50:19 +0100 Subject: [PATCH 04/43] Addressing warnings. --- ...ntentSetContentPickerFieldDisplayDriver.cs | 34 +++++---------- .../Activities/ContentSetCreatingEvent.cs | 9 +--- ...etGetSupportedOptionsEventDisplayDriver.cs | 20 ++++----- .../Navigation/AdminMenu.cs | 13 ++---- ...tSecurityPermissionAuthorizationHandler.cs | 9 +--- .../ShapeTracing/ShapeTracingShapeEvents.cs | 12 ++---- .../SiteTexts/LocalizationMigrations.cs | 9 +--- .../SiteTexts/Services/SiteTextService.cs | 9 +--- .../Drivers/MvcConditionEvaluatorDriver.cs | 9 +--- .../GenerateResetPasswordTokenTask.cs | 41 ++++++------------- 10 files changed, 47 insertions(+), 118 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs index 19a6a7b8..5ad07716 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs @@ -4,7 +4,6 @@ using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulLibraries.OrchardCore.Contents; using Microsoft.Extensions.Localization; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.ContentManagement.Display.Models; @@ -15,25 +14,12 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; -public class ContentSetContentPickerFieldDisplayDriver : ContentFieldDisplayDriver +public class ContentSetContentPickerFieldDisplayDriver( + IContentDefinitionManager contentDefinitionManager, + IContentSetManager contentSetManager, + IEnumerable contentSetEventHandlers, + IStringLocalizer stringLocalizer) : ContentFieldDisplayDriver { - private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly IContentSetManager _contentSetManager; - private readonly IEnumerable _contentSetEventHandlers; - private readonly IStringLocalizer T; - - public ContentSetContentPickerFieldDisplayDriver( - IContentDefinitionManager contentDefinitionManager, - IContentSetManager contentSetManager, - IEnumerable contentSetEventHandlers, - IStringLocalizer stringLocalizer) - { - _contentDefinitionManager = contentDefinitionManager; - _contentSetManager = contentSetManager; - _contentSetEventHandlers = contentSetEventHandlers; - T = stringLocalizer; - } - public override IDisplayResult Display( ContentSetContentPickerField field, BuildFieldDisplayContext fieldDisplayContext) @@ -45,14 +31,14 @@ public override IDisplayResult Display( { model.PartFieldDefinition = fieldDisplayContext.PartFieldDefinition; await model.InitializeAsync( - _contentSetManager, - _contentSetEventHandlers, - T, + contentSetManager, + contentSetEventHandlers, + stringLocalizer, part, new ContentTypePartDefinition( name, - await _contentDefinitionManager.GetPartDefinitionAsync(nameof(ContentSetPart)), - new JObject()), + await contentDefinitionManager.GetPartDefinitionAsync(nameof(ContentSetPart)), + []), isNew: false); }) .Location(CommonContentDisplayTypes.Detail, CommonLocationNames.Content) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs index c7462aab..1c477701 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs @@ -1,15 +1,10 @@ -using Lombiq.HelpfulLibraries.OrchardCore.Workflow; +using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.Extensions.Localization; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; -public class ContentSetCreatingEvent : SimpleEventActivityBase +public class ContentSetCreatingEvent(IStringLocalizer stringLocalizer) : SimpleEventActivityBase(stringLocalizer) { public override LocalizedString DisplayText => T["Creating Content Set"]; public override LocalizedString Category => T["Content Sets"]; - - public ContentSetCreatingEvent(IStringLocalizer stringLocalizer) - : base(stringLocalizer) - { - } } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs index b1bcd1df..4bd8dee3 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models; @@ -12,15 +12,16 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Drivers; -public class ContentSetGetSupportedOptionsEventDisplayDriver : - DocumentedEventActivityDisplayDriverBase +public class ContentSetGetSupportedOptionsEventDisplayDriver( + INotifier notifier, + IStringLocalizer baseLocalizer, + IHtmlLocalizer htmlLocalizer) : + DocumentedEventActivityDisplayDriverBase(notifier, baseLocalizer) { - private readonly IHtmlLocalizer H; - public override string IconClass => "fa-circle-half-stroke"; public override LocalizedHtmlString Description => - H["Tries to get a list of links representing the supported options for this content set."]; + htmlLocalizer["Tries to get a list of links representing the supported options for this content set."]; public override IDictionary AvailableInputs { get; } = new Dictionary { @@ -34,11 +35,4 @@ public class ContentSetGetSupportedOptionsEventDisplayDriver : [ContentSetGetSupportedOptionsEvent.OutputName] = $"{{ \"{nameof(ContentSetLinkViewModel.Key)}\": string, \"{nameof(ContentSetLinkViewModel.DisplayText)}\": string }}[]", }; - - public ContentSetGetSupportedOptionsEventDisplayDriver( - INotifier notifier, - IStringLocalizer baseLocalizer, - IHtmlLocalizer htmlLocalizer) - : base(notifier, baseLocalizer) => - H = htmlLocalizer; } diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs index 3ada4e8a..4a0442e9 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs @@ -8,16 +8,9 @@ namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Navigation; -public class AdminMenu : INavigationProvider +public class AdminMenu(IHttpContextAccessor hca, IStringLocalizer stringLocalizer) : INavigationProvider { - private readonly IHttpContextAccessor _hca; - private readonly IStringLocalizer T; - - public AdminMenu(IHttpContextAccessor hca, IStringLocalizer stringLocalizer) - { - _hca = hca; - T = stringLocalizer; - } + private readonly IStringLocalizer T = stringLocalizer; public Task BuildNavigationAsync(string name, NavigationBuilder builder) { @@ -26,7 +19,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder.Add(T["Configuration"], configuration => configuration .Add(T["Import/Export"], importExport => importExport .Add(T["Orchard 1 Recipe Migration"], T["Orchard 1 Recipe Migration"], migration => migration - .Action(_hca.HttpContext, controller => controller.Index()) + .Action(hca.HttpContext, controller => controller.Index()) .LocalNav() ))); diff --git a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs index f61d44db..3acaaf9c 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs @@ -14,7 +14,7 @@ namespace Lombiq.HelpfulExtensions.Extensions.Security.Services; [RequireFeatures(FeatureIds.Security)] -public class StrictSecurityPermissionAuthorizationHandler : AuthorizationHandler +public class StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) : AuthorizationHandler { private static readonly Dictionary> _permissionTemplates = ContentTypePermissionsHelper .PermissionTemplates @@ -22,16 +22,11 @@ public class StrictSecurityPermissionAuthorizationHandler : AuthorizationHandler pair => pair.Key, pair => GetPermissionTemplates(pair.Value, new List())); - private readonly IContentDefinitionManager _contentDefinitionManager; - - public StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) => - _contentDefinitionManager = contentDefinitionManager; - protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement) { if ((context.Resource as IContent)?.ContentItem is not { } contentItem || !_permissionTemplates.TryGetValue(requirement.Permission.Name, out var claims) || - await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType) is not { } definition || + await contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType) is not { } definition || definition.GetSettings()?.Enabled != true) { return; diff --git a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs index bb4271b9..8790e852 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs @@ -7,15 +7,11 @@ namespace Lombiq.HelpfulExtensions.Extensions.ShapeTracing; -internal sealed class ShapeTracingShapeEvents : IShapeDisplayEvents +internal sealed class ShapeTracingShapeEvents(IHttpContextAccessor hca) : IShapeDisplayEvents { - private readonly IHttpContextAccessor _hca; - - public ShapeTracingShapeEvents(IHttpContextAccessor hca) => _hca = hca; - public Task DisplayedAsync(ShapeDisplayContext context) { - if (!_hca.HttpContext.IsDevelopment()) return Task.CompletedTask; + if (!hca.HttpContext.IsDevelopment()) return Task.CompletedTask; // We could also use _orchardHelper.ConsoleLog(context.Shape) here but that causes an OutOfMemoryException. @@ -37,7 +33,7 @@ void AddIfNotNullOrEmpty(string name, string value) } } - if (shapeMetadata.Alternates.Any()) + if (shapeMetadata.Alternates.Count != 0) { builder.AppendHtml("Alternates: "); builder.AppendHtmlLine(string.Join(", ", shapeMetadata.Alternates)); @@ -49,7 +45,7 @@ void AddIfNotNullOrEmpty(string name, string value) builder.AppendHtmlLine(string.Join(", ", shapeMetadata.BindingSources)); } - if (shapeMetadata.Wrappers.Any()) + if (shapeMetadata.Wrappers.Count != 0) { builder.AppendHtml("Wrappers: "); builder.AppendHtmlLine(string.Join(", ", shapeMetadata.Wrappers)); diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs index f52bdd82..f0c2c989 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs @@ -6,16 +6,11 @@ namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts; -public class LocalizationMigrations : DataMigration +public class LocalizationMigrations(IContentDefinitionManager contentDefinitionManager) : DataMigration { - private readonly IContentDefinitionManager _contentDefinitionManager; - - public LocalizationMigrations(IContentDefinitionManager contentDefinitionManager) => - _contentDefinitionManager = contentDefinitionManager; - public async Task CreateAsync() { - await _contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder .WithPart(nameof(LocalizationPart))); return 1; diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextService.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextService.cs index c55b3a5f..e122ad62 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextService.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextService.cs @@ -1,17 +1,12 @@ -using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Html; using OrchardCore.ContentManagement; using OrchardCore.Markdown.Services; using System.Threading.Tasks; namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts.Services; -public class SiteTextService : SiteTextServiceBase +public class SiteTextService(IContentManager contentManager, IMarkdownService markdownService) : SiteTextServiceBase(contentManager, markdownService) { - public SiteTextService(IContentManager contentManager, IMarkdownService markdownService) - : base(contentManager, markdownService) - { - } - public override async Task RenderHtmlByIdAsync(string contentItemId) { var part = await GetSiteTextMarkdownBodyPartByIdAsync(contentItemId); diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs index 7a29c2c1..df275c38 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs @@ -8,13 +8,8 @@ namespace Lombiq.HelpfulExtensions.Extensions.Widgets.Drivers; -public class MvcConditionEvaluatorDriver : ContentDisplayDriver, IConditionEvaluator +public class MvcConditionEvaluatorDriver(IHttpContextAccessor hca) : ContentDisplayDriver, IConditionEvaluator { - private readonly IHttpContextAccessor _hca; - - public MvcConditionEvaluatorDriver(IHttpContextAccessor hca) => - _hca = hca; - public ValueTask EvaluateAsync(Condition condition) => new(Evaluate((MvcCondition)condition)); private bool Evaluate(MvcCondition condition) => @@ -28,7 +23,7 @@ private bool MatchRouteValue(string name, string value) // Ignore this match operation if the target value is not set. if (string.IsNullOrWhiteSpace(value)) return true; - return _hca.HttpContext?.Request.RouteValues.TryGetValue(name, out var routeValue) == true && + return hca.HttpContext?.Request.RouteValues.TryGetValue(name, out var routeValue) == true && value.EqualsOrdinalIgnoreCase(routeValue?.ToString()); } } diff --git a/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs b/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs index a1181e43..5602d832 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs @@ -16,17 +16,16 @@ namespace Lombiq.HelpfulExtensions.Extensions.Workflows.Activities; -public class GenerateResetPasswordTokenTask : TaskActivity +public class GenerateResetPasswordTokenTask( + IStringLocalizer localizer, + LinkGenerator linkGenerator, + IHttpContextAccessor hca, + UserManager userManager, + IWorkflowScriptEvaluator workflowScriptEvaluator) : TaskActivity { - private readonly IStringLocalizer T; - private readonly LinkGenerator _linkGenerator; - private readonly IHttpContextAccessor _hca; - private readonly UserManager _userManager; - private readonly IWorkflowScriptEvaluator _workflowScriptEvaluator; - public override string Name => nameof(GenerateResetPasswordTokenTask); - public override LocalizedString DisplayText => T["Generate reset password token"]; - public override LocalizedString Category => T["User"]; + public override LocalizedString DisplayText => localizer["Generate reset password token"]; + public override LocalizedString Category => localizer["User"]; public WorkflowExpression User { @@ -46,37 +45,23 @@ public string ResetPasswordUrlPropertyKey set => SetProperty(value); } - public GenerateResetPasswordTokenTask( - IStringLocalizer localizer, - LinkGenerator linkGenerator, - IHttpContextAccessor hca, - UserManager userManager, - IWorkflowScriptEvaluator workflowScriptEvaluator) - { - T = localizer; - _linkGenerator = linkGenerator; - _hca = hca; - _userManager = userManager; - _workflowScriptEvaluator = workflowScriptEvaluator; - } - public override IEnumerable GetPossibleOutcomes( WorkflowExecutionContext workflowContext, ActivityContext activityContext) => - Outcomes(T["Done"], T["Error"]); + Outcomes(localizer["Done"], localizer["Error"]); public override async Task ExecuteAsync( WorkflowExecutionContext workflowContext, ActivityContext activityContext) { - var user = await _workflowScriptEvaluator.EvaluateAsync(User, workflowContext); + var user = await workflowScriptEvaluator.EvaluateAsync(User, workflowContext); if (user == null) return Outcomes("Error"); - var generatedToken = await _userManager.GeneratePasswordResetTokenAsync(user); + var generatedToken = await userManager.GeneratePasswordResetTokenAsync(user); user.ResetToken = Convert.ToBase64String(Encoding.UTF8.GetBytes(generatedToken)); - var resetPasswordUrl = _linkGenerator.GetUriByAction( - _hca.HttpContext, + var resetPasswordUrl = linkGenerator.GetUriByAction( + hca.HttpContext, "ResetPassword", "ResetPassword", new { area = "OrchardCore.Users", code = user.ResetToken }); From 425acc04c9dc7ea3408300c13dce45fdf52f24a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 20 Jan 2024 13:19:56 +0100 Subject: [PATCH 05/43] Addressing warnings. --- .../Services/StrictSecurityPermissionAuthorizationHandler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs index 3acaaf9c..ee68b921 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs @@ -14,7 +14,8 @@ namespace Lombiq.HelpfulExtensions.Extensions.Security.Services; [RequireFeatures(FeatureIds.Security)] -public class StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) : AuthorizationHandler +public class StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) + : AuthorizationHandler { private static readonly Dictionary> _permissionTemplates = ContentTypePermissionsHelper .PermissionTemplates From 857e19da57eb6de0e24e410e0d3f20805823f534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 20 Jan 2024 15:28:25 +0100 Subject: [PATCH 06/43] Addressing warnings. --- .../Extensions/SiteTexts/Services/SiteTextServiceBase.cs | 2 +- .../Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs index d9e5f902..0ca15971 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs @@ -36,7 +36,7 @@ protected async Task RenderMarkdownAsync(string markdown) // If it's a single-line expression, then it's presumably inline so don't wrap it in a

element. if (doc.Body is { ChildElementCount: 1, FirstElementChild: { } first } && - first.TagName.ToUpperInvariant() == "P") + first.TagName.Equals("P", StringComparison.OrdinalIgnoreCase)) { html = first.InnerHtml.Trim(); } diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs index a1ac482e..23c626e0 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs @@ -24,7 +24,7 @@ public class MenuWidgetLiquidFilter( IUrlHelperFactory urlHelperFactory) : ILiquidFilter { private readonly ILiquidContentDisplayService _liquidContentDisplayService = liquidContentDisplayService; - private readonly Lazy _urlHelperLazy = new Lazy(() => + private readonly Lazy _urlHelperLazy = new(() => urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext!)); private readonly IStringLocalizer T = stringLocalizer; From f170b6cbbb2bd1f7c1bd3b04540e83f26f1bc9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 27 Jan 2024 09:41:31 +0100 Subject: [PATCH 07/43] Adding DecoratedResourceManager --- .../DecoratedResourceManager.cs | 121 ++++++++++++++++++ .../Extensions/ResourceManagement/Startup.cs | 13 ++ Lombiq.HelpfulExtensions/FeatureIds.cs | 1 + .../Lombiq.HelpfulExtensions.csproj | 1 + Lombiq.HelpfulExtensions/Manifest.cs | 7 + 5 files changed, 143 insertions(+) create mode 100644 Lombiq.HelpfulExtensions/Extensions/ResourceManagement/DecoratedResourceManager.cs create mode 100644 Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/DecoratedResourceManager.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/DecoratedResourceManager.cs new file mode 100644 index 00000000..66873ed9 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/DecoratedResourceManager.cs @@ -0,0 +1,121 @@ +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Microsoft.Extensions.Options; +using OrchardCore.DisplayManagement.Manifest; +using OrchardCore.DisplayManagement.Theming; +using OrchardCore.Environment.Extensions; +using OrchardCore.Modules; +using OrchardCore.ResourceManagement; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Lombiq.HelpfulLibraries.OrchardCore.ResourceManagement; +public class DecoratedResourceManager( + IResourceManager resourceManager, + IThemeManager themeManager, + IOptions resourceManagementOptions) : IResourceManager +{ + private readonly ResourceManagementOptions _options = resourceManagementOptions.Value; + + public ResourceManifest InlineManifest => resourceManager.InlineManifest; + + public void AppendMeta(MetaEntry meta, string contentSeparator) => resourceManager.AppendMeta(meta, contentSeparator); + + public ResourceDefinition FindResource(RequireSettings settings) => resourceManager.FindResource(settings); + + public IEnumerable GetRegisteredFootScripts() => resourceManager.GetRegisteredFootScripts(); + + public IEnumerable GetRegisteredHeadScripts() => resourceManager.GetRegisteredHeadScripts(); + + public IEnumerable GetRegisteredLinks() => resourceManager.GetRegisteredLinks(); + + public IEnumerable GetRegisteredMetas() => resourceManager.GetRegisteredMetas(); + + public IEnumerable GetRegisteredStyles() => resourceManager.GetRegisteredStyles(); + + public IEnumerable GetRequiredResources(string resourceType) => + resourceManager.GetRequiredResources(resourceType); + + public void NotRequired(string resourceType, string resourceName) => + resourceManager.NotRequired(resourceType, resourceName); + + public void RegisterFootScript(IHtmlContent script) => resourceManager.RegisterFootScript(script); + + public void RegisterHeadScript(IHtmlContent script) => resourceManager.RegisterHeadScript(script); + + public void RegisterLink(LinkEntry link) => resourceManager.RegisterLink(link); + + public void RegisterMeta(MetaEntry meta) => resourceManager.RegisterMeta(meta); + + public RequireSettings RegisterResource(string resourceType, string resourceName) => + resourceManager.RegisterResource(resourceType, resourceName); + + public void RegisterStyle(IHtmlContent style) => resourceManager.RegisterStyle(style); + + public RequireSettings RegisterUrl(string resourceType, string resourcePath, string resourceDebugPath) => + resourceManager.RegisterUrl(resourceType, resourcePath, resourceDebugPath); + public void RenderFootScript(TextWriter writer) => resourceManager.RenderFootScript(writer); + + public void RenderHeadLink(TextWriter writer) => resourceManager.RenderHeadLink(writer); + + public void RenderHeadScript(TextWriter writer) => resourceManager.RenderHeadScript(writer); + + public void RenderLocalScript(RequireSettings settings, TextWriter writer) => resourceManager.RenderLocalScript(settings, writer); + + public void RenderLocalStyle(RequireSettings settings, TextWriter writer) => resourceManager.RenderLocalStyle(settings, writer); + + public void RenderMeta(TextWriter writer) => resourceManager.RenderMeta(writer); + + public void RenderStylesheet(TextWriter writer) + { + var first = true; + + var styleSheets = GetRequiredResources("stylesheet").ToList(); + var displayedTheme = themeManager.GetThemeAsync().GetAwaiter().GetResult(); + + foreach (var context in styleSheets) + { + if (context.Settings.Location == ResourceLocation.Inline) + { + continue; + } + + var resourceName = context.Resource.Name; + var contextIsBootstrap = resourceName.EqualsOrdinalIgnoreCase("bootstrap"); + + if (contextIsBootstrap && IsCurrentTheme(displayedTheme)) + { + continue; + } + + if (!first) + { + writer.Write(Environment.NewLine); + } + + first = false; + + context.WriteTo(writer, _options.ContentBasePath); + } + + var registeredStyles = GetRegisteredStyles().ToArray(); + for (var i = 0; i < registeredStyles.Length; i++) + { + var context = registeredStyles[i]; + if (!first) + { + writer.Write(Environment.NewLine); + } + + first = false; + + context.WriteTo(writer, NullHtmlEncoder.Default); + } + } + + private static bool IsCurrentTheme(IExtensionInfo currentSiteTheme) => + currentSiteTheme?.Id == "Lombiq.BaseTheme" || + currentSiteTheme?.Manifest.ModuleInfo is ThemeAttribute { BaseTheme: "Lombiq.BaseTheme" }; +} diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs new file mode 100644 index 00000000..c281ee51 --- /dev/null +++ b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs @@ -0,0 +1,13 @@ +using Lombiq.HelpfulLibraries.OrchardCore.ResourceManagement; +using Microsoft.Extensions.DependencyInjection; +using OrchardCore.Modules; +using OrchardCore.ResourceManagement; + +namespace Lombiq.HelpfulExtensions.Extensions.ResourceManagement; + +[Feature(FeatureIds.ResourceManagement)] +public class Startup : StartupBase +{ + public override void ConfigureServices(IServiceCollection services) => + services.Decorate(); +} diff --git a/Lombiq.HelpfulExtensions/FeatureIds.cs b/Lombiq.HelpfulExtensions/FeatureIds.cs index 3cd3b3ee..a99af5e4 100644 --- a/Lombiq.HelpfulExtensions/FeatureIds.cs +++ b/Lombiq.HelpfulExtensions/FeatureIds.cs @@ -19,4 +19,5 @@ public static class FeatureIds public const string Workflows = FeatureIdPrefix + nameof(Workflows); public const string Trumbowyg = FeatureIdPrefix + nameof(Trumbowyg); public const string ResetPasswordActivity = Workflows + "." + nameof(ResetPasswordActivity); + public const string ResourceManagement = FeatureIdPrefix + nameof(ResourceManagement); } diff --git a/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj b/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj index d81fff29..822024ba 100644 --- a/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj +++ b/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj @@ -48,6 +48,7 @@ + diff --git a/Lombiq.HelpfulExtensions/Manifest.cs b/Lombiq.HelpfulExtensions/Manifest.cs index 29ff8210..18579bee 100644 --- a/Lombiq.HelpfulExtensions/Manifest.cs +++ b/Lombiq.HelpfulExtensions/Manifest.cs @@ -145,3 +145,10 @@ Category = "Content", Description = "Adds option for inserting code snippets in Trumbowyg editor." )] + +[assembly: Feature( + Id = ResourceManagement, + Name = "Lombiq Helpful Extensions - Resource Management", + Category = "ResourceManagement", + Description = "Adds a decorated version of IResourceManager" +)] From d0f85aa05350c6169ac3255d864e8f71eeb2ee60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 27 Jan 2024 09:45:37 +0100 Subject: [PATCH 08/43] Renaming. --- ...{DecoratedResourceManager.cs => ResourceManagerDecorator.cs} | 2 +- .../Extensions/ResourceManagement/Startup.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename Lombiq.HelpfulExtensions/Extensions/ResourceManagement/{DecoratedResourceManager.cs => ResourceManagerDecorator.cs} (99%) diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/DecoratedResourceManager.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs similarity index 99% rename from Lombiq.HelpfulExtensions/Extensions/ResourceManagement/DecoratedResourceManager.cs rename to Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs index 66873ed9..b2a9ccee 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/DecoratedResourceManager.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs @@ -12,7 +12,7 @@ using System.Linq; namespace Lombiq.HelpfulLibraries.OrchardCore.ResourceManagement; -public class DecoratedResourceManager( +public class ResourceManagerDecorator( IResourceManager resourceManager, IThemeManager themeManager, IOptions resourceManagementOptions) : IResourceManager diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs index c281ee51..7b613e55 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs @@ -9,5 +9,5 @@ namespace Lombiq.HelpfulExtensions.Extensions.ResourceManagement; public class Startup : StartupBase { public override void ConfigureServices(IServiceCollection services) => - services.Decorate(); + services.Decorate(); } From 98d268a4157956da7b275948978f487c0e28a56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 27 Jan 2024 16:49:33 +0100 Subject: [PATCH 09/43] Resolving jQuery not being registered prior to its user script. --- .../ResourceManagerDecorator.cs | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs index b2a9ccee..a892ba84 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs @@ -56,7 +56,43 @@ public RequireSettings RegisterResource(string resourceType, string resourceName public RequireSettings RegisterUrl(string resourceType, string resourcePath, string resourceDebugPath) => resourceManager.RegisterUrl(resourceType, resourcePath, resourceDebugPath); - public void RenderFootScript(TextWriter writer) => resourceManager.RenderFootScript(writer); + public void RenderFootScript(TextWriter writer) + { + var footScripts = GetRequiredResources("script") + .OrderBy(script => !script.Resource.Name.EqualsOrdinalIgnoreCase("jquery")); + + var first = true; + foreach (var context in footScripts) + { + if (context.Settings.Location != ResourceLocation.Foot) + { + continue; + } + + if (!first) + { + writer.Write(Environment.NewLine); + } + + first = false; + + context.WriteTo(writer, _options.ContentBasePath); + } + + var registeredFootScripts = GetRegisteredFootScripts().ToArray(); + for (var i = 0; i < registeredFootScripts.Length; i++) + { + var context = registeredFootScripts[i]; + if (!first) + { + writer.Write(Environment.NewLine); + } + + first = false; + + context.WriteTo(writer, NullHtmlEncoder.Default); + } + } public void RenderHeadLink(TextWriter writer) => resourceManager.RenderHeadLink(writer); From 646c2233d9873f17f83d4f762c6469a6073d5d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sun, 28 Jan 2024 18:33:35 +0100 Subject: [PATCH 10/43] Updating ResourceManagerDecorator. --- .../ResourceManagerDecorator.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs index a892ba84..b9e6c511 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs @@ -56,19 +56,23 @@ public RequireSettings RegisterResource(string resourceType, string resourceName public RequireSettings RegisterUrl(string resourceType, string resourcePath, string resourceDebugPath) => resourceManager.RegisterUrl(resourceType, resourcePath, resourceDebugPath); + public void RenderFootScript(TextWriter writer) { + static bool CheckResourceNameIsJquery(ResourceRequiredContext context) => context.Resource.Name.EqualsOrdinalIgnoreCase("jquery"); + var footScripts = GetRequiredResources("script") - .OrderBy(script => !script.Resource.Name.EqualsOrdinalIgnoreCase("jquery")); + .Where(footScript => footScript.Settings.Location == ResourceLocation.Foot) + .ToList(); + + if (footScripts.Exists(CheckResourceNameIsJquery)) + { + footScripts = [.. footScripts.OrderBy(script => !CheckResourceNameIsJquery(script))]; + } var first = true; foreach (var context in footScripts) { - if (context.Settings.Location != ResourceLocation.Foot) - { - continue; - } - if (!first) { writer.Write(Environment.NewLine); @@ -108,8 +112,8 @@ public void RenderStylesheet(TextWriter writer) { var first = true; - var styleSheets = GetRequiredResources("stylesheet").ToList(); var displayedTheme = themeManager.GetThemeAsync().GetAwaiter().GetResult(); + var styleSheets = GetRequiredResources("stylesheet").ToList(); foreach (var context in styleSheets) { From c2004e87b9c230331250890774b62d05604a3397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sun, 28 Jan 2024 20:39:19 +0100 Subject: [PATCH 11/43] Adding summary. --- .../ResourceManagerDecorator.cs | 50 ++++--------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs index b9e6c511..bd04c9ea 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs @@ -12,6 +12,15 @@ using System.Linq; namespace Lombiq.HelpfulLibraries.OrchardCore.ResourceManagement; + +///

+/// This decorator is replacing the old ReplaceBootstrapMiddleware with the same purpose. +/// Removes the built-in Bootstrap resource if the currently selected theme uses Lombiq.BaseTheme as its base theme. +/// Themes derived from Lombiq.BaseTheme use Bootstrap from NPM as it's compiled into their site stylesheet. So this +/// duplicate resource is not needed and can cause problems if not removed. This situation can arise when a module +/// (such as Lombiq.DataTables) depends on Bootstrap and doesn't explicitly depend on Lombiq.BaseTheme so the built-in +/// resource would be injected if this middleware didn't remove it. +/// public class ResourceManagerDecorator( IResourceManager resourceManager, IThemeManager themeManager, @@ -57,46 +66,7 @@ public RequireSettings RegisterResource(string resourceType, string resourceName public RequireSettings RegisterUrl(string resourceType, string resourcePath, string resourceDebugPath) => resourceManager.RegisterUrl(resourceType, resourcePath, resourceDebugPath); - public void RenderFootScript(TextWriter writer) - { - static bool CheckResourceNameIsJquery(ResourceRequiredContext context) => context.Resource.Name.EqualsOrdinalIgnoreCase("jquery"); - - var footScripts = GetRequiredResources("script") - .Where(footScript => footScript.Settings.Location == ResourceLocation.Foot) - .ToList(); - - if (footScripts.Exists(CheckResourceNameIsJquery)) - { - footScripts = [.. footScripts.OrderBy(script => !CheckResourceNameIsJquery(script))]; - } - - var first = true; - foreach (var context in footScripts) - { - if (!first) - { - writer.Write(Environment.NewLine); - } - - first = false; - - context.WriteTo(writer, _options.ContentBasePath); - } - - var registeredFootScripts = GetRegisteredFootScripts().ToArray(); - for (var i = 0; i < registeredFootScripts.Length; i++) - { - var context = registeredFootScripts[i]; - if (!first) - { - writer.Write(Environment.NewLine); - } - - first = false; - - context.WriteTo(writer, NullHtmlEncoder.Default); - } - } + public void RenderFootScript(TextWriter writer) => resourceManager.RenderFootScript(writer); public void RenderHeadLink(TextWriter writer) => resourceManager.RenderHeadLink(writer); From 71068edc770670a5bd86f41e33135a402f643a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:07:39 +0100 Subject: [PATCH 12/43] Keeping H. --- .../Controllers/OrchardRecipeMigrationAdminController.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs b/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs index a4992d7f..8e590441 100644 --- a/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs +++ b/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs @@ -21,6 +21,8 @@ public class OrchardRecipeMigrationAdminController( IOrchardExportToRecipeConverter converter, IHtmlLocalizer localizer) : Controller { + private readonly IHtmlLocalizer H = localizer; + public IActionResult Index() => View(); [HttpPost] @@ -36,7 +38,7 @@ public async Task Convert(IFormFile file) } catch (Exception) { - await notifier.ErrorAsync(localizer["Please add a file to import."]); + await notifier.ErrorAsync(H["Please add a file to import."]); return Redirect(nameof(Index)); } From 943ac57b181b252e03b7e40b667df9bc14955f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:08:58 +0100 Subject: [PATCH 13/43] Keeping T. --- .../Drivers/ContentSetContentPickerFieldDisplayDriver.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs index 5ad07716..9f377156 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs @@ -20,6 +20,8 @@ public class ContentSetContentPickerFieldDisplayDriver( IEnumerable contentSetEventHandlers, IStringLocalizer stringLocalizer) : ContentFieldDisplayDriver { + private readonly IStringLocalizer T = stringLocalizer; + public override IDisplayResult Display( ContentSetContentPickerField field, BuildFieldDisplayContext fieldDisplayContext) @@ -33,7 +35,7 @@ public override IDisplayResult Display( await model.InitializeAsync( contentSetManager, contentSetEventHandlers, - stringLocalizer, + T, part, new ContentTypePartDefinition( name, From ac6bf265bd8cc7c097fb86ee2b49c52b3ab81d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:10:19 +0100 Subject: [PATCH 14/43] Keeping T. --- .../ContentSets/Drivers/ContentSetPartDisplayDriver.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs index 8de2748d..8f836aec 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs @@ -22,13 +22,15 @@ public class ContentSetPartDisplayDriver( { private const string ShapeType = $"{nameof(ContentSetPart)}_{CommonContentDisplayTypes.SummaryAdmin}"; + private readonly IStringLocalizer T = stringLocalizer; + public override IDisplayResult Display(ContentSetPart part, BuildPartDisplayContext context) { ValueTask InitializeAsync(ContentSetPartViewModel model) => model.InitializeAsync( contentSetManager, contentSetEventHandlers, - stringLocalizer, + T, part, context.TypePartDefinition, isNew: false); @@ -45,7 +47,7 @@ public override IDisplayResult Edit(ContentSetPart part, BuildPartEditorContext Initialize($"{nameof(ContentSetPart)}_Edit", model => model.InitializeAsync( contentSetManager, contentSetEventHandlers, - stringLocalizer, + T, part, context.TypePartDefinition, context.IsNew)) From a857043c09155d21d6e16616107617359a131024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:11:35 +0100 Subject: [PATCH 15/43] Keeping H. --- .../Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs index 53bf1920..241377e1 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs @@ -16,8 +16,9 @@ public class ContentSetCreatingEventDisplayDriver( IHtmlLocalizer htmlLocalizer) : DocumentedEventActivityDisplayDriverBase(notifier, baseLocalizer) { + private readonly IHtmlLocalizer H = htmlLocalizer; public override string IconClass => "fa-circle-half-stroke"; - public override LocalizedHtmlString Description => htmlLocalizer["Executes when a new content item is created in the content set."]; + public override LocalizedHtmlString Description => H["Executes when a new content item is created in the content set."]; public override IDictionary AvailableInputs { get; } = new Dictionary { [nameof(CreatingContext.ContentItem)] = nameof(ContentItem), From 43545cc009083fe8d9361bcaef50dc7306cc0a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:12:27 +0100 Subject: [PATCH 16/43] Keeping H. --- .../ContentSetGetSupportedOptionsEventDisplayDriver.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs index 4bd8dee3..8cedcf48 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs @@ -18,10 +18,12 @@ public class ContentSetGetSupportedOptionsEventDisplayDriver( IHtmlLocalizer htmlLocalizer) : DocumentedEventActivityDisplayDriverBase(notifier, baseLocalizer) { + private readonly IHtmlLocalizer H = htmlLocalizer; + public override string IconClass => "fa-circle-half-stroke"; public override LocalizedHtmlString Description => - htmlLocalizer["Tries to get a list of links representing the supported options for this content set."]; + H["Tries to get a list of links representing the supported options for this content set."]; public override IDictionary AvailableInputs { get; } = new Dictionary { From bb5e8d32adc4ba2f9f2924fabf62c241ed945c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:16:41 +0100 Subject: [PATCH 17/43] Removing field. --- .../SiteTexts/Services/ContentLocalizationSiteTextService.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs index 8d2148cf..cabd2e21 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs @@ -14,8 +14,6 @@ public class ContentLocalizationSiteTextService( IContentLocalizationManager contentLocalizationManager, IMarkdownService markdownService) : SiteTextServiceBase(contentManager, markdownService) { - private readonly IContentLocalizationManager _contentLocalizationManager = contentLocalizationManager; - public override async Task RenderHtmlByIdAsync(string contentItemId) { var part = await GetSiteTextMarkdownBodyPartByIdAsync(contentItemId); @@ -23,7 +21,7 @@ public override async Task RenderHtmlByIdAsync(string contentItemId) if (part.As() is { Culture: { } partCulture, LocalizationSet: { } localizationSet } && partCulture != culture && - await _contentLocalizationManager.GetContentItemAsync(localizationSet, culture) is { } contentItem && + await contentLocalizationManager.GetContentItemAsync(localizationSet, culture) is { } contentItem && contentItem.As() is { } localizedPart) { part = localizedPart; From d2dc72abcf654afff041c020ec1bfe668034afb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:17:31 +0100 Subject: [PATCH 18/43] Removing field. --- .../Extensions/SiteTexts/SiteTextMigrations.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs index eae5dcb1..0b2ff5ec 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs @@ -12,11 +12,9 @@ namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts; public class SiteTextMigrations(IContentDefinitionManager contentDefinitionManager) : DataMigration { - private readonly IContentDefinitionManager _contentDefinitionManager = contentDefinitionManager; - public async Task CreateAsync() { - await _contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder .SetAbilities( creatable: true, securable: true, From 4cecd5ae4f4f6c3ef6cbaa374728d3a2fc3038f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:18:25 +0100 Subject: [PATCH 19/43] Removing field. --- .../Extensions/TargetBlank/Filters/TargetBlankFilter.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs b/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs index 13c93b5e..350b6f64 100644 --- a/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs @@ -8,8 +8,6 @@ namespace Lombiq.HelpfulExtensions.Extensions.TargetBlank.Filters; public class TargetBlankFilter(IResourceManager resourceManager) : IAsyncResultFilter { - private readonly IResourceManager _resourceManager = resourceManager; - public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (context.Result is not ViewResult) @@ -19,7 +17,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE return; } - _resourceManager.RegisterResource("script", ResourceNames.TargetBlank).AtFoot(); + resourceManager.RegisterResource("script", ResourceNames.TargetBlank).AtFoot(); await next(); } From 480e3dc7de15b58d90da877fcaca082503802dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:19:34 +0100 Subject: [PATCH 20/43] Removing field. --- .../Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs index 23c626e0..a94054c8 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs @@ -23,7 +23,6 @@ public class MenuWidgetLiquidFilter( IStringLocalizer stringLocalizer, IUrlHelperFactory urlHelperFactory) : ILiquidFilter { - private readonly ILiquidContentDisplayService _liquidContentDisplayService = liquidContentDisplayService; private readonly Lazy _urlHelperLazy = new(() => urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext!)); private readonly IStringLocalizer T = stringLocalizer; @@ -60,7 +59,7 @@ public ValueTask ProcessAsync(FluidValue input, FilterArguments argu UpdateMenuItems(menuItems, localNav); - return _liquidContentDisplayService.DisplayNewAsync( + return liquidContentDisplayService.DisplayNewAsync( WidgetTypes.MenuWidget, model => { From 8c35cf6f1aba872f20ea247574fb54a227752e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:20:38 +0100 Subject: [PATCH 21/43] Removing field. --- .../Extensions/Widgets/Migrations.cs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs index 3fecdc7c..4fa656fa 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs @@ -11,18 +11,16 @@ namespace Lombiq.HelpfulExtensions.Extensions.Widgets; public class Migrations(IContentDefinitionManager contentDefinitionManager) : DataMigration { - private readonly IContentDefinitionManager _contentDefinitionManager = contentDefinitionManager; - public async Task CreateAsync() { - await _contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("TitlePart", part => part.WithPosition("0")) .WithPart("FlowPart", part => part.WithPosition("1")) ); - await _contentDefinitionManager.AlterTypeDefinitionAsync(HtmlWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(HtmlWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("HtmlBodyPart", part => part @@ -34,7 +32,7 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(HtmlWidget, builder => ) ); - await _contentDefinitionManager.AlterTypeDefinitionAsync(LiquidWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(LiquidWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("LiquidPart", part => part @@ -42,12 +40,12 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(LiquidWidget, builder = ) ); - await _contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) ); - await _contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("MarkdownBodyPart", part => part @@ -55,7 +53,7 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder ) ); - var contentItemWidgetPartName = await _contentDefinitionManager.AlterPartDefinitionAsync(builder => builder + var contentItemWidgetPartName = await contentDefinitionManager.AlterPartDefinitionAsync(builder => builder .WithField(part => part.ContentToDisplay, field => field .WithDisplayName("Content to display") .WithSettings(new ContentPickerFieldSettings @@ -67,7 +65,7 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder .WithField(part => part.GroupId, field => field.WithDisplayName("Group ID")) ); - await _contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart(contentItemWidgetPartName) @@ -78,7 +76,7 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItem public async Task UpdateFrom1Async() { - await _contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder .WithPart("TitlePart", part => part.WithPosition("0")) .WithPart("FlowPart", part => part.WithPosition("1")) ); @@ -88,7 +86,7 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builde public async Task UpdateFrom2Async() { - await _contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) ); @@ -98,7 +96,7 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => public async Task UpdateFrom3Async() { - await _contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("MarkdownBodyPart", part => part @@ -111,13 +109,13 @@ await _contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder public async Task UpdateFrom4Async() { - var contentItemWidgetPartName = await _contentDefinitionManager.AlterPartDefinitionAsync(builder => builder + var contentItemWidgetPartName = await contentDefinitionManager.AlterPartDefinitionAsync(builder => builder .WithField(part => part.ContentToDisplay, field => field.WithDisplayName("Content to display")) .WithField(part => part.DisplayType, field => field.WithDisplayName("Display type")) .WithField(part => part.GroupId, field => field.WithDisplayName("Group ID")) ); - await _contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder + await contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart(contentItemWidgetPartName) From a25607f03a733f21628a3092182a180213f9483a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:22:37 +0100 Subject: [PATCH 22/43] Keeping T. --- .../Activities/GenerateResetPasswordTokenTask.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs b/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs index 5602d832..3dbbdc02 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs @@ -23,9 +23,11 @@ public class GenerateResetPasswordTokenTask( UserManager userManager, IWorkflowScriptEvaluator workflowScriptEvaluator) : TaskActivity { + private readonly IStringLocalizer T = localizer; + public override string Name => nameof(GenerateResetPasswordTokenTask); - public override LocalizedString DisplayText => localizer["Generate reset password token"]; - public override LocalizedString Category => localizer["User"]; + public override LocalizedString DisplayText => T["Generate reset password token"]; + public override LocalizedString Category => T["User"]; public WorkflowExpression User { @@ -48,7 +50,7 @@ public string ResetPasswordUrlPropertyKey public override IEnumerable GetPossibleOutcomes( WorkflowExecutionContext workflowContext, ActivityContext activityContext) => - Outcomes(localizer["Done"], localizer["Error"]); + Outcomes(T["Done"], T["Error"]); public override async Task ExecuteAsync( WorkflowExecutionContext workflowContext, From edc7f6b06f793c1d25aec850575e7fa0fdfbc728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 30 Jan 2024 11:46:23 +0100 Subject: [PATCH 23/43] Revert "Addressing warnings."This reverts commit c7e673188b8bf5a278f1887a7c509871ead0f07e.# Conflicts:# Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs# Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs# Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs# Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs# Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs# Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs# Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs# Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.csRevert "Addressing warnings."This reverts commit a41d98e2a2b18b5a905b0bcf0d87ab06d93c10c8.# Conflicts:# Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs# Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs# Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs# Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs Revert "Addressing warnings." This reverts commit 425acc04c9dc7ea3408300c13dce45fdf52f24a2. # Conflicts: # Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs --- .../Controllers/ContentSetController.cs | 17 +++++-- .../OrchardRecipeMigrationAdminController.cs | 22 ++++++--- .../CodeGenerationDisplayDriver.cs | 8 +-- ...ntentSetContentPickerFieldDisplayDriver.cs | 32 ++++++++---- .../Drivers/ContentSetPartDisplayDriver.cs | 33 ++++++++----- .../ContentSets/Indexes/ContentSetIndex.cs | 11 ++++- .../Extensions/ContentSets/Migrations.cs | 9 +++- .../ContentSets/Services/ContentSetManager.cs | 39 ++++++++++----- .../Activities/ContentSetCreatingEvent.cs | 9 +++- .../ContentSetGetSupportedOptionsEvent.cs | 10 ++-- .../ContentSetCreatingEventDisplayDriver.cs | 18 ++++--- ...etGetSupportedOptionsEventDisplayDriver.cs | 18 ++++--- .../WorkflowContentSetEventHandler.cs | 23 ++++++--- .../Extensions/ContentTypes/Migrations.cs | 15 ++++-- .../ShapeBasedEmailTemplateService.cs | 15 ++++-- .../Handlers/AdditionalStylingPartHandler.cs | 9 +++- .../Navigation/AdminMenu.cs | 13 +++-- .../OrchardExportToRecipeConverter.cs | 49 +++++++++++++------ .../Services/UserOrchardContentConverter.cs | 19 +++++-- ...tSecurityPermissionAuthorizationHandler.cs | 3 +- .../ShapeTracing/ShapeTracingShapeEvents.cs | 12 +++-- .../SiteTexts/LocalizationMigrations.cs | 9 +++- .../ContentLocalizationSiteTextService.cs | 18 ++++--- .../SiteTexts/Services/SiteTextService.cs | 9 +++- .../SiteTexts/SiteTextMigrations.cs | 9 +++- .../TargetBlank/Filters/TargetBlankFilter.cs | 8 ++- .../Drivers/MvcConditionDisplayDriver.cs | 17 ++++--- .../Drivers/MvcConditionEvaluatorDriver.cs | 9 +++- .../Widgets/Liquid/MenuWidgetLiquidFilter.cs | 35 ++++++++----- .../Extensions/Widgets/Migrations.cs | 31 +++++++----- .../Widgets/ViewModels/MenuWidgetViewModel.cs | 14 ++++-- .../GenerateResetPasswordTokenTask.cs | 35 ++++++++----- ...rateResetPasswordTokenTaskDisplayDriver.cs | 11 ++++- 33 files changed, 408 insertions(+), 181 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Controllers/ContentSetController.cs b/Lombiq.HelpfulExtensions/Controllers/ContentSetController.cs index 6c7845ad..03b929c7 100644 --- a/Lombiq.HelpfulExtensions/Controllers/ContentSetController.cs +++ b/Lombiq.HelpfulExtensions/Controllers/ContentSetController.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; using Microsoft.AspNetCore.Mvc; using OrchardCore; using OrchardCore.Modules; @@ -7,10 +7,19 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Controllers; [Feature(FeatureIds.ContentSets)] -public class ContentSetController(IContentSetManager contentSetManager, IOrchardHelper orchardHelper) : Controller +public class ContentSetController : Controller { + private readonly IContentSetManager _contentSetManager; + private readonly IOrchardHelper _orchardHelper; + + public ContentSetController(IContentSetManager contentSetManager, IOrchardHelper orchardHelper) + { + _contentSetManager = contentSetManager; + _orchardHelper = orchardHelper; + } + public async Task Create(string fromContentItemId, string fromPartName, string newKey) => - await contentSetManager.CloneContentItemAsync(fromContentItemId, fromPartName, newKey) is { } content - ? Redirect(orchardHelper.GetItemEditUrl(content)) + await _contentSetManager.CloneContentItemAsync(fromContentItemId, fromPartName, newKey) is { } content + ? Redirect(_orchardHelper.GetItemEditUrl(content)) : NotFound(); } diff --git a/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs b/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs index 8e590441..b093f9e3 100644 --- a/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs +++ b/Lombiq.HelpfulExtensions/Controllers/OrchardRecipeMigrationAdminController.cs @@ -16,12 +16,20 @@ namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Controllers [Admin] [Feature(FeatureIds.OrchardRecipeMigration)] -public class OrchardRecipeMigrationAdminController( - INotifier notifier, - IOrchardExportToRecipeConverter converter, - IHtmlLocalizer localizer) : Controller +public class OrchardRecipeMigrationAdminController : Controller { - private readonly IHtmlLocalizer H = localizer; + private readonly INotifier _notifier; + private readonly IOrchardExportToRecipeConverter _converter; + private readonly IHtmlLocalizer H; + public OrchardRecipeMigrationAdminController( + INotifier notifier, + IOrchardExportToRecipeConverter converter, + IHtmlLocalizer localizer) + { + _notifier = notifier; + _converter = converter; + H = localizer; + } public IActionResult Index() => View(); @@ -38,13 +46,13 @@ public async Task Convert(IFormFile file) } catch (Exception) { - await notifier.ErrorAsync(H["Please add a file to import."]); + await _notifier.ErrorAsync(H["Please add a file to import."]); return Redirect(nameof(Index)); } await using (stream) { - json = await converter.ConvertAsync(XDocument.Load(stream)); + json = await _converter.ConvertAsync(XDocument.Load(stream)); } Response.Headers.Append("Content-Disposition", "attachment;filename=export.recipe.json"); diff --git a/Lombiq.HelpfulExtensions/Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs index 206d105a..67edb7f2 100644 --- a/Lombiq.HelpfulExtensions/Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs @@ -12,10 +12,12 @@ namespace Lombiq.HelpfulExtensions.Extensions.CodeGeneration; -public class CodeGenerationDisplayDriver(IStringLocalizer stringLocalizer) - : ContentTypeDefinitionDisplayDriver +public class CodeGenerationDisplayDriver : ContentTypeDefinitionDisplayDriver { - private readonly IStringLocalizer T = stringLocalizer; + private readonly IStringLocalizer T; + + public CodeGenerationDisplayDriver(IStringLocalizer stringLocalizer) => + T = stringLocalizer; public override IDisplayResult Edit(ContentTypeDefinition model) => Initialize( diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs index 9f377156..19a6a7b8 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs @@ -4,6 +4,7 @@ using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulLibraries.OrchardCore.Contents; using Microsoft.Extensions.Localization; +using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.ContentManagement.Display.Models; @@ -14,13 +15,24 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; -public class ContentSetContentPickerFieldDisplayDriver( - IContentDefinitionManager contentDefinitionManager, - IContentSetManager contentSetManager, - IEnumerable contentSetEventHandlers, - IStringLocalizer stringLocalizer) : ContentFieldDisplayDriver +public class ContentSetContentPickerFieldDisplayDriver : ContentFieldDisplayDriver { - private readonly IStringLocalizer T = stringLocalizer; + private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly IContentSetManager _contentSetManager; + private readonly IEnumerable _contentSetEventHandlers; + private readonly IStringLocalizer T; + + public ContentSetContentPickerFieldDisplayDriver( + IContentDefinitionManager contentDefinitionManager, + IContentSetManager contentSetManager, + IEnumerable contentSetEventHandlers, + IStringLocalizer stringLocalizer) + { + _contentDefinitionManager = contentDefinitionManager; + _contentSetManager = contentSetManager; + _contentSetEventHandlers = contentSetEventHandlers; + T = stringLocalizer; + } public override IDisplayResult Display( ContentSetContentPickerField field, @@ -33,14 +45,14 @@ public override IDisplayResult Display( { model.PartFieldDefinition = fieldDisplayContext.PartFieldDefinition; await model.InitializeAsync( - contentSetManager, - contentSetEventHandlers, + _contentSetManager, + _contentSetEventHandlers, T, part, new ContentTypePartDefinition( name, - await contentDefinitionManager.GetPartDefinitionAsync(nameof(ContentSetPart)), - []), + await _contentDefinitionManager.GetPartDefinitionAsync(nameof(ContentSetPart)), + new JObject()), isNew: false); }) .Location(CommonContentDisplayTypes.Detail, CommonLocationNames.Content) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs index 8f836aec..9b7f7cf1 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetPartDisplayDriver.cs @@ -14,22 +14,33 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Drivers; -public class ContentSetPartDisplayDriver( - IContentSetManager contentSetManager, - IIdGenerator idGenerator, - IEnumerable contentSetEventHandlers, - IStringLocalizer stringLocalizer) : ContentPartDisplayDriver +public class ContentSetPartDisplayDriver : ContentPartDisplayDriver { private const string ShapeType = $"{nameof(ContentSetPart)}_{CommonContentDisplayTypes.SummaryAdmin}"; - private readonly IStringLocalizer T = stringLocalizer; + private readonly IContentSetManager _contentSetManager; + private readonly IIdGenerator _idGenerator; + private readonly IEnumerable _contentSetEventHandlers; + private readonly IStringLocalizer T; + + public ContentSetPartDisplayDriver( + IContentSetManager contentSetManager, + IIdGenerator idGenerator, + IEnumerable contentSetEventHandlers, + IStringLocalizer stringLocalizer) + { + _contentSetManager = contentSetManager; + _idGenerator = idGenerator; + _contentSetEventHandlers = contentSetEventHandlers; + T = stringLocalizer; + } public override IDisplayResult Display(ContentSetPart part, BuildPartDisplayContext context) { ValueTask InitializeAsync(ContentSetPartViewModel model) => model.InitializeAsync( - contentSetManager, - contentSetEventHandlers, + _contentSetManager, + _contentSetEventHandlers, T, part, context.TypePartDefinition, @@ -45,8 +56,8 @@ ValueTask InitializeAsync(ContentSetPartViewModel model) => public override IDisplayResult Edit(ContentSetPart part, BuildPartEditorContext context) => Initialize($"{nameof(ContentSetPart)}_Edit", model => model.InitializeAsync( - contentSetManager, - contentSetEventHandlers, + _contentSetManager, + _contentSetEventHandlers, T, part, context.TypePartDefinition, @@ -68,7 +79,7 @@ public override async Task UpdateAsync( // item has not been saved yet. if (string.IsNullOrEmpty(part.ContentSet)) { - part.ContentSet = idGenerator.GenerateUniqueId(); + part.ContentSet = _idGenerator.GenerateUniqueId(); } } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs index d36aece1..7a89ff46 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Indexes/ContentSetIndex.cs @@ -27,14 +27,21 @@ public static ContentSetIndex FromPart(ContentSetPart part, string partName) => }; } -public class ContentSetIndexProvider(IServiceProvider provider) : IndexProvider +public class ContentSetIndexProvider : IndexProvider { + private readonly IServiceProvider _provider; + + // We can't inject Lazy because it will throw a "Cannot resolve scoped service + // 'OrchardCore.ContentManagement.Metadata.IContentDefinitionManager' from root provider." exception. + public ContentSetIndexProvider(IServiceProvider provider) => + _provider = provider; + public override void Describe(DescribeContext context) => context.For().Map(async contentItem => { if (!contentItem.Latest) return Enumerable.Empty(); - using var scope = provider.CreateScope(); + using var scope = _provider.CreateScope(); var contentDefinitionManager = scope.ServiceProvider.GetRequiredService(); return (await contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType)) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs index e659e86a..46c3a4c4 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs @@ -9,11 +9,16 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets; -public class Migrations(IContentDefinitionManager contentDefinitionManager) : DataMigration +public class Migrations : DataMigration { + private readonly IContentDefinitionManager _contentDefinitionManager; + + public Migrations(IContentDefinitionManager contentDefinitionManager) => + _contentDefinitionManager = contentDefinitionManager; + public async Task CreateAsync() { - await contentDefinitionManager.AlterPartDefinitionAsync(nameof(ContentSetPart), builder => builder + await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(ContentSetPart), builder => builder .Attachable() .Reusable() .WithDisplayName("Content Set")); diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs index 7174b536..226bfa21 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Services/ContentSetManager.cs @@ -11,30 +11,43 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Services; -public class ContentSetManager( - IContentDefinitionManager contentDefinitionManager, - IContentManager contentManager, - IEnumerable contentSetEventHandlers, - ISession session) : IContentSetManager +public class ContentSetManager : IContentSetManager { + private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly IContentManager _contentManager; + private readonly IEnumerable _contentSetEventHandlers; + private readonly ISession _session; + + public ContentSetManager( + IContentDefinitionManager contentDefinitionManager, + IContentManager contentManager, + IEnumerable contentSetEventHandlers, + ISession session) + { + _contentDefinitionManager = contentDefinitionManager; + _contentManager = contentManager; + _contentSetEventHandlers = contentSetEventHandlers; + _session = session; + } + public Task> GetIndexAsync(string setId) => - session.QueryIndex(index => index.ContentSet == setId).ListAsync(); + _session.QueryIndex(index => index.ContentSet == setId).ListAsync(); public async Task> GetContentItemsAsync(string setId) => - await contentManager.GetAsync((await GetIndexAsync(setId)).Select(index => index.ContentItemId)); + await _contentManager.GetAsync((await GetIndexAsync(setId)).Select(index => index.ContentItemId)); public async Task CloneContentItemAsync(string fromContentItemId, string fromPartName, string newKey) { if (string.IsNullOrEmpty(fromPartName)) fromPartName = nameof(ContentSetPart); - if (await contentManager.GetAsync(fromContentItemId) is not { } original || + if (await _contentManager.GetAsync(fromContentItemId) is not { } original || original.Get(fromPartName)?.ContentSet is not { } contentSet || - await contentManager.CloneAsync(original) is not { } content) + await _contentManager.CloneAsync(original) is not { } content) { return null; } - var exists = await session + var exists = await _session .QueryIndex(index => index.ContentSet == contentSet && index.Key == newKey) .FirstOrDefaultAsync() is not null; if (exists) throw new InvalidOperationException($"The key \"{newKey}\" already exists for the content set \"{contentSet}\"."); @@ -45,16 +58,16 @@ await contentManager.CloneAsync(original) is not { } content) part.Key = newKey; }); - var contentTypePartDefinition = (await contentDefinitionManager.GetTypeDefinitionAsync(content.ContentType)) + var contentTypePartDefinition = (await _contentDefinitionManager.GetTypeDefinitionAsync(content.ContentType)) .Parts .Single(definition => definition.Name == fromPartName); - foreach (var handler in contentSetEventHandlers) + foreach (var handler in _contentSetEventHandlers) { await handler.CreatingAsync(content, contentTypePartDefinition, contentSet, newKey); } - await contentManager.PublishAsync(content); + await _contentManager.PublishAsync(content); return content; } } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs index 1c477701..c7462aab 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetCreatingEvent.cs @@ -1,10 +1,15 @@ -using Lombiq.HelpfulLibraries.OrchardCore.Workflow; +using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.Extensions.Localization; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; -public class ContentSetCreatingEvent(IStringLocalizer stringLocalizer) : SimpleEventActivityBase(stringLocalizer) +public class ContentSetCreatingEvent : SimpleEventActivityBase { public override LocalizedString DisplayText => T["Creating Content Set"]; public override LocalizedString Category => T["Content Sets"]; + + public ContentSetCreatingEvent(IStringLocalizer stringLocalizer) + : base(stringLocalizer) + { + } } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs index 83f1cf10..239f4030 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Activities/ContentSetGetSupportedOptionsEvent.cs @@ -1,13 +1,17 @@ -using Lombiq.HelpfulLibraries.OrchardCore.Workflow; +using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.Extensions.Localization; namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; -public class ContentSetGetSupportedOptionsEvent(IStringLocalizer stringLocalizer) - : SimpleEventActivityBase(stringLocalizer) +public class ContentSetGetSupportedOptionsEvent : SimpleEventActivityBase { public const string OutputName = "MemberLinks"; public override LocalizedString DisplayText => T["Get Supported Content Set Options"]; public override LocalizedString Category => T["Content Sets"]; + + public ContentSetGetSupportedOptionsEvent(IStringLocalizer stringLocalizer) + : base(stringLocalizer) + { + } } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs index 241377e1..e452782e 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetCreatingEventDisplayDriver.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models; using Lombiq.HelpfulLibraries.OrchardCore.Workflow; using Microsoft.AspNetCore.Mvc.Localization; @@ -10,13 +10,10 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Drivers; -public class ContentSetCreatingEventDisplayDriver( - INotifier notifier, - IStringLocalizer baseLocalizer, - IHtmlLocalizer htmlLocalizer) - : DocumentedEventActivityDisplayDriverBase(notifier, baseLocalizer) +public class ContentSetCreatingEventDisplayDriver : DocumentedEventActivityDisplayDriverBase { - private readonly IHtmlLocalizer H = htmlLocalizer; + private readonly IHtmlLocalizer H; + public override string IconClass => "fa-circle-half-stroke"; public override LocalizedHtmlString Description => H["Executes when a new content item is created in the content set."]; public override IDictionary AvailableInputs { get; } = new Dictionary @@ -26,4 +23,11 @@ public class ContentSetCreatingEventDisplayDriver( [nameof(CreatingContext.ContentSet)] = "string", [nameof(CreatingContext.NewKey)] = "string", }; + + public ContentSetCreatingEventDisplayDriver( + INotifier notifier, + IStringLocalizer baseLocalizer, + IHtmlLocalizer htmlLocalizer) + : base(notifier, baseLocalizer) => + H = htmlLocalizer; } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs index 8cedcf48..b1bcd1df 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Drivers/ContentSetGetSupportedOptionsEventDisplayDriver.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models; @@ -12,13 +12,10 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Drivers; -public class ContentSetGetSupportedOptionsEventDisplayDriver( - INotifier notifier, - IStringLocalizer baseLocalizer, - IHtmlLocalizer htmlLocalizer) : - DocumentedEventActivityDisplayDriverBase(notifier, baseLocalizer) +public class ContentSetGetSupportedOptionsEventDisplayDriver : + DocumentedEventActivityDisplayDriverBase { - private readonly IHtmlLocalizer H = htmlLocalizer; + private readonly IHtmlLocalizer H; public override string IconClass => "fa-circle-half-stroke"; @@ -37,4 +34,11 @@ public class ContentSetGetSupportedOptionsEventDisplayDriver( [ContentSetGetSupportedOptionsEvent.OutputName] = $"{{ \"{nameof(ContentSetLinkViewModel.Key)}\": string, \"{nameof(ContentSetLinkViewModel.DisplayText)}\": string }}[]", }; + + public ContentSetGetSupportedOptionsEventDisplayDriver( + INotifier notifier, + IStringLocalizer baseLocalizer, + IHtmlLocalizer htmlLocalizer) + : base(notifier, baseLocalizer) => + H = htmlLocalizer; } diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs index 2cbe8784..f7e34c3b 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Workflows/Handlers/WorkflowContentSetEventHandler.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; +using Lombiq.HelpfulExtensions.Extensions.ContentSets.Events; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities; @@ -17,10 +17,19 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Handlers; -public class WorkflowContentSetEventHandler( - IWorkflowManager workflowManager, - IWorkflowTypeStore workflowTypeStore) : IContentSetEventHandler +public class WorkflowContentSetEventHandler : IContentSetEventHandler { + private readonly IWorkflowManager _workflowManager; + private readonly IWorkflowTypeStore _workflowTypeStore; + + public WorkflowContentSetEventHandler( + IWorkflowManager workflowManager, + IWorkflowTypeStore workflowTypeStore) + { + _workflowManager = workflowManager; + _workflowTypeStore = workflowTypeStore; + } + public async Task> GetSupportedOptionsAsync( ContentSetPart part, ContentTypePartDefinition definition) @@ -29,8 +38,8 @@ public async Task> GetSupportedOptionsAsync var values = new GetSupportedOptionsContext(definition, part).ToDictionary(); - var workflowContexts = await workflowManager - .TriggerEventAndGetContextsAsync(workflowTypeStore, values); + var workflowContexts = await _workflowManager + .TriggerEventAndGetContextsAsync(_workflowTypeStore, values); foreach (var context in workflowContexts) { @@ -66,7 +75,7 @@ public Task CreatingAsync( ContentTypePartDefinition definition, string contentSet, string newKey) => - workflowManager.TriggerEventAsync( + _workflowManager.TriggerEventAsync( new CreatingContext(content, definition, contentSet, newKey), $"{nameof(WorkflowContentSetEventHandler)}.{nameof(CreatingAsync)}" + $"({content.ContentItemId}, {definition.Name}, {contentSet}, {newKey})"); diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs index 522b342f..946d2380 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs @@ -7,11 +7,16 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentTypes; -public class Migrations(IContentDefinitionManager contentDefinitionManager) : DataMigration +public class Migrations : DataMigration { + private readonly IContentDefinitionManager _contentDefinitionManager; + + public Migrations(IContentDefinitionManager contentDefinitionManager) => + _contentDefinitionManager = contentDefinitionManager; + public async Task CreateAsync() { - await contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder .Creatable() .Securable() .Draftable() @@ -29,7 +34,7 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder .WithPart("FlowPart", part => part.WithPosition("2")) ); - await contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder .WithDescription("A base content type for ad-hoc welding parts or fields on.") ); @@ -38,7 +43,7 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builde public async Task UpdateFrom1Async() { - await contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder .WithPart("TitlePart", part => part.WithPosition("0")) .WithPart("AutoroutePart", part => part.WithPosition("1")) .WithPart("FlowPart", part => part.WithPosition("2")) @@ -49,7 +54,7 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder public async Task UpdateFrom2Async() { - await contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(Empty, builder => builder .WithDescription("A base content type for ad-hoc welding parts or fields on.") ); diff --git a/Lombiq.HelpfulExtensions/Extensions/Emails/Services/ShapeBasedEmailTemplateService.cs b/Lombiq.HelpfulExtensions/Extensions/Emails/Services/ShapeBasedEmailTemplateService.cs index 6ed6efb7..57d3dd92 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Emails/Services/ShapeBasedEmailTemplateService.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Emails/Services/ShapeBasedEmailTemplateService.cs @@ -5,14 +5,23 @@ namespace Lombiq.HelpfulExtensions.Extensions.Emails.Services; -public class ShapeBasedEmailTemplateService(IShapeFactory shapeFactory, IShapeRenderer shapeRenderer) : IEmailTemplateService +public class ShapeBasedEmailTemplateService : IEmailTemplateService { + private readonly IShapeFactory _shapeFactory; + private readonly IShapeRenderer _shapeRenderer; + + public ShapeBasedEmailTemplateService(IShapeFactory shapeFactory, IShapeRenderer shapeRenderer) + { + _shapeFactory = shapeFactory; + _shapeRenderer = shapeRenderer; + } + public async Task RenderEmailTemplateAsync(string emailTemplateId, object model = null) { ExceptionHelpers.ThrowIfNull(emailTemplateId, nameof(emailTemplateId)); - var shape = await shapeFactory.CreateAsync($"EmailTemplate__{emailTemplateId}", Arguments.From(model ?? new { })); + var shape = await _shapeFactory.CreateAsync($"EmailTemplate__{emailTemplateId}", Arguments.From(model ?? new { })); - return await shapeRenderer.RenderAsync(shape); + return await _shapeRenderer.RenderAsync(shape); } } diff --git a/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs b/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs index a9b8c568..8fa611b0 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Flows/Handlers/AdditionalStylingPartHandler.cs @@ -7,12 +7,17 @@ namespace Lombiq.HelpfulExtensions.Extensions.Flows.Handlers; -public class AdditionalStylingPartHandler(IContentDefinitionManager contentDefinitionManager) : ContentHandlerBase +public class AdditionalStylingPartHandler : ContentHandlerBase { + private readonly IContentDefinitionManager _contentDefinitionManager; + + public AdditionalStylingPartHandler(IContentDefinitionManager contentDefinitionManager) => + _contentDefinitionManager = contentDefinitionManager; + public override async Task ActivatedAsync(ActivatedContentContext context) { if (!context.ContentItem.Has() && - (await contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType)) + (await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType)) .GetSettings().Stereotype == "Widget") { context.ContentItem.Weld(); diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs index 4a0442e9..3ada4e8a 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Navigation/AdminMenu.cs @@ -8,9 +8,16 @@ namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Navigation; -public class AdminMenu(IHttpContextAccessor hca, IStringLocalizer stringLocalizer) : INavigationProvider +public class AdminMenu : INavigationProvider { - private readonly IStringLocalizer T = stringLocalizer; + private readonly IHttpContextAccessor _hca; + private readonly IStringLocalizer T; + + public AdminMenu(IHttpContextAccessor hca, IStringLocalizer stringLocalizer) + { + _hca = hca; + T = stringLocalizer; + } public Task BuildNavigationAsync(string name, NavigationBuilder builder) { @@ -19,7 +26,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder.Add(T["Configuration"], configuration => configuration .Add(T["Import/Export"], importExport => importExport .Add(T["Orchard 1 Recipe Migration"], T["Orchard 1 Recipe Migration"], migration => migration - .Action(hca.HttpContext, controller => controller.Index()) + .Action(_hca.HttpContext, controller => controller.Index()) .LocalNav() ))); diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs index a7847ad1..d414e453 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs @@ -12,20 +12,37 @@ namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Services; -public class OrchardExportToRecipeConverter( - IContentDefinitionManager contentDefinitionManager, - IContentManager contentManager, - IIdGenerator idGenerator, - IEnumerable exportConverters, - IEnumerable contentConverters, - IEnumerable userConverters) : IOrchardExportToRecipeConverter +public class OrchardExportToRecipeConverter : IOrchardExportToRecipeConverter { - private readonly List _contentTypes = contentDefinitionManager + private readonly IContentManager _contentManager; + private readonly IIdGenerator _idGenerator; + private readonly IEnumerable _exportConverters; + private readonly IEnumerable _contentConverters; + private readonly IEnumerable _userConverters; + + private readonly ICollection _contentTypes; + + public OrchardExportToRecipeConverter( + IContentDefinitionManager contentDefinitionManager, + IContentManager contentManager, + IIdGenerator idGenerator, + IEnumerable exportConverters, + IEnumerable contentConverters, + IEnumerable userConverters) + { + _contentManager = contentManager; + _idGenerator = idGenerator; + _exportConverters = exportConverters; + _contentConverters = contentConverters; + _userConverters = userConverters; + + _contentTypes = contentDefinitionManager .ListTypeDefinitionsAsync() .GetAwaiter() .GetResult() .Select(definition => definition.Name) .ToList(); + } public async Task ConvertAsync(XDocument export) { @@ -36,10 +53,10 @@ public async Task ConvertAsync(XDocument export) { if (await CreateContentItemAsync(content) is { } contentItem) { - contentItem.ContentItemId ??= idGenerator.GenerateUniqueId(); - contentItem.ContentItemVersionId ??= idGenerator.GenerateUniqueId(); + contentItem.ContentItemId ??= _idGenerator.GenerateUniqueId(); + contentItem.ContentItemVersionId ??= _idGenerator.GenerateUniqueId(); - await contentConverters + await _contentConverters .Where(converter => converter.IsApplicable(content)) .OrderBy(converter => converter.Order) .AwaitEachAsync(converter => converter.ImportAsync(content, contentItem)); @@ -48,13 +65,13 @@ await contentConverters } else if (content.Name == nameof(User)) { - var customUserConverter = userConverters.FirstOrDefault(converter => converter.IgnoreDefaultConverter); - var userConverter = customUserConverter ?? userConverters.First(); + var customUserConverter = _userConverters.FirstOrDefault(converter => converter.IgnoreDefaultConverter); + var userConverter = customUserConverter ?? _userConverters.First(); await userConverter.ImportAsync(content); } } - foreach (var converter in exportConverters) + foreach (var converter in _exportConverters) { await converter.UpdateContentItemsAsync(export, contentItems); } @@ -67,7 +84,7 @@ await contentConverters private async Task CreateContentItemAsync(XElement content) { - foreach (var converter in contentConverters.OrderBy(converter => converter.Order)) + foreach (var converter in _contentConverters.OrderBy(converter => converter.Order)) { if (converter.IsApplicable(content) && await converter.CreateContentItemAsync(content) is { } contentItem) { @@ -76,7 +93,7 @@ private async Task CreateContentItemAsync(XElement content) } return _contentTypes.Contains(content.Name.LocalName) - ? await contentManager.NewAsync(content.Name.LocalName) + ? await _contentManager.NewAsync(content.Name.LocalName) : null; } } diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs index a1482bb0..522e7970 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/UserOrchardContentConverter.cs @@ -8,10 +8,19 @@ namespace Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Services; -public class UserOrchardContentConverter( - IUserService userService, - ILogger logger) : IOrchardUserConverter +public class UserOrchardContentConverter : IOrchardUserConverter { + private readonly IUserService _userService; + private readonly ILogger _logger; + + public UserOrchardContentConverter( + IUserService userService, + ILogger logger) + { + _userService = userService; + _logger = logger; + } + public bool IgnoreDefaultConverter => false; public async Task ImportAsync(XElement element) @@ -22,7 +31,7 @@ public async Task ImportAsync(XElement element) var roles = element.Element("UserRolesPart").Attribute("Roles")?.Value; var rolesList = string.IsNullOrEmpty(roles) ? new List() : [.. roles.Split(',')]; - await userService.CreateUserAsync( + await _userService.CreateUserAsync( new User { UserName = userPart.Attribute("UserName")?.Value, @@ -32,7 +41,7 @@ await userService.CreateUserAsync( RoleNames = rolesList, }, GenerateRandomPassword(32), - (_, message) => logger.LogError("User creation failed: \"{Message}\"", message)); + (_, message) => _logger.LogError("User creation failed: \"{Message}\"", message)); return; } diff --git a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs index ee68b921..3acaaf9c 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs @@ -14,8 +14,7 @@ namespace Lombiq.HelpfulExtensions.Extensions.Security.Services; [RequireFeatures(FeatureIds.Security)] -public class StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) - : AuthorizationHandler +public class StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) : AuthorizationHandler { private static readonly Dictionary> _permissionTemplates = ContentTypePermissionsHelper .PermissionTemplates diff --git a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs index 8790e852..bb4271b9 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs @@ -7,11 +7,15 @@ namespace Lombiq.HelpfulExtensions.Extensions.ShapeTracing; -internal sealed class ShapeTracingShapeEvents(IHttpContextAccessor hca) : IShapeDisplayEvents +internal sealed class ShapeTracingShapeEvents : IShapeDisplayEvents { + private readonly IHttpContextAccessor _hca; + + public ShapeTracingShapeEvents(IHttpContextAccessor hca) => _hca = hca; + public Task DisplayedAsync(ShapeDisplayContext context) { - if (!hca.HttpContext.IsDevelopment()) return Task.CompletedTask; + if (!_hca.HttpContext.IsDevelopment()) return Task.CompletedTask; // We could also use _orchardHelper.ConsoleLog(context.Shape) here but that causes an OutOfMemoryException. @@ -33,7 +37,7 @@ void AddIfNotNullOrEmpty(string name, string value) } } - if (shapeMetadata.Alternates.Count != 0) + if (shapeMetadata.Alternates.Any()) { builder.AppendHtml("Alternates: "); builder.AppendHtmlLine(string.Join(", ", shapeMetadata.Alternates)); @@ -45,7 +49,7 @@ void AddIfNotNullOrEmpty(string name, string value) builder.AppendHtmlLine(string.Join(", ", shapeMetadata.BindingSources)); } - if (shapeMetadata.Wrappers.Count != 0) + if (shapeMetadata.Wrappers.Any()) { builder.AppendHtml("Wrappers: "); builder.AppendHtmlLine(string.Join(", ", shapeMetadata.Wrappers)); diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs index f0c2c989..f52bdd82 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/LocalizationMigrations.cs @@ -6,11 +6,16 @@ namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts; -public class LocalizationMigrations(IContentDefinitionManager contentDefinitionManager) : DataMigration +public class LocalizationMigrations : DataMigration { + private readonly IContentDefinitionManager _contentDefinitionManager; + + public LocalizationMigrations(IContentDefinitionManager contentDefinitionManager) => + _contentDefinitionManager = contentDefinitionManager; + public async Task CreateAsync() { - await contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder .WithPart(nameof(LocalizationPart))); return 1; diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs index cabd2e21..18a24a14 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/ContentLocalizationSiteTextService.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Html; using OrchardCore.ContentLocalization; using OrchardCore.ContentLocalization.Models; using OrchardCore.ContentManagement; @@ -9,11 +9,17 @@ namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts.Services; -public class ContentLocalizationSiteTextService( - IContentManager contentManager, - IContentLocalizationManager contentLocalizationManager, - IMarkdownService markdownService) : SiteTextServiceBase(contentManager, markdownService) +public class ContentLocalizationSiteTextService : SiteTextServiceBase { + private readonly IContentLocalizationManager _contentLocalizationManager; + + public ContentLocalizationSiteTextService( + IContentManager contentManager, + IContentLocalizationManager contentLocalizationManager, + IMarkdownService markdownService) + : base(contentManager, markdownService) => + _contentLocalizationManager = contentLocalizationManager; + public override async Task RenderHtmlByIdAsync(string contentItemId) { var part = await GetSiteTextMarkdownBodyPartByIdAsync(contentItemId); @@ -21,7 +27,7 @@ public override async Task RenderHtmlByIdAsync(string contentItemId) if (part.As() is { Culture: { } partCulture, LocalizationSet: { } localizationSet } && partCulture != culture && - await contentLocalizationManager.GetContentItemAsync(localizationSet, culture) is { } contentItem && + await _contentLocalizationManager.GetContentItemAsync(localizationSet, culture) is { } contentItem && contentItem.As() is { } localizedPart) { part = localizedPart; diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextService.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextService.cs index e122ad62..c55b3a5f 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextService.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextService.cs @@ -1,12 +1,17 @@ -using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Html; using OrchardCore.ContentManagement; using OrchardCore.Markdown.Services; using System.Threading.Tasks; namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts.Services; -public class SiteTextService(IContentManager contentManager, IMarkdownService markdownService) : SiteTextServiceBase(contentManager, markdownService) +public class SiteTextService : SiteTextServiceBase { + public SiteTextService(IContentManager contentManager, IMarkdownService markdownService) + : base(contentManager, markdownService) + { + } + public override async Task RenderHtmlByIdAsync(string contentItemId) { var part = await GetSiteTextMarkdownBodyPartByIdAsync(contentItemId); diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs index 0b2ff5ec..b7fb7ffe 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/SiteTextMigrations.cs @@ -10,11 +10,16 @@ namespace Lombiq.HelpfulExtensions.Extensions.SiteTexts; -public class SiteTextMigrations(IContentDefinitionManager contentDefinitionManager) : DataMigration +public class SiteTextMigrations : DataMigration { + private readonly IContentDefinitionManager _contentDefinitionManager; + + public SiteTextMigrations(IContentDefinitionManager contentDefinitionManager) => + _contentDefinitionManager = contentDefinitionManager; + public async Task CreateAsync() { - await contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder .SetAbilities( creatable: true, securable: true, diff --git a/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs b/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs index 350b6f64..d89bfc13 100644 --- a/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/TargetBlank/Filters/TargetBlankFilter.cs @@ -6,8 +6,12 @@ namespace Lombiq.HelpfulExtensions.Extensions.TargetBlank.Filters; -public class TargetBlankFilter(IResourceManager resourceManager) : IAsyncResultFilter +public class TargetBlankFilter : IAsyncResultFilter { + private readonly IResourceManager _resourceManager; + + public TargetBlankFilter(IResourceManager resourceManager) => _resourceManager = resourceManager; + public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (context.Result is not ViewResult) @@ -17,7 +21,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE return; } - resourceManager.RegisterResource("script", ResourceNames.TargetBlank).AtFoot(); + _resourceManager.RegisterResource("script", ResourceNames.TargetBlank).AtFoot(); await next(); } diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionDisplayDriver.cs index 0a76fb70..54df6e64 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionDisplayDriver.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.Widgets.Models; +using Lombiq.HelpfulExtensions.Extensions.Widgets.Models; using Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Localization; @@ -11,12 +11,17 @@ namespace Lombiq.HelpfulExtensions.Extensions.Widgets.Drivers; -public class MvcConditionDisplayDriver( - IHtmlLocalizer htmlLocalizer, - IStringLocalizer stringLocalizer) : ConditionDisplayDriver +public class MvcConditionDisplayDriver : ConditionDisplayDriver { - private readonly IHtmlLocalizer H = htmlLocalizer; - private readonly IStringLocalizer T = stringLocalizer; + private readonly IHtmlLocalizer H; + private readonly IStringLocalizer T; + public MvcConditionDisplayDriver( + IHtmlLocalizer htmlLocalizer, + IStringLocalizer stringLocalizer) + { + H = htmlLocalizer; + T = stringLocalizer; + } protected override IDisplayResult GetEditor(MvcCondition model) => Initialize("MvcCondition_Fields_Edit", viewModel => diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs index df275c38..7a29c2c1 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Drivers/MvcConditionEvaluatorDriver.cs @@ -8,8 +8,13 @@ namespace Lombiq.HelpfulExtensions.Extensions.Widgets.Drivers; -public class MvcConditionEvaluatorDriver(IHttpContextAccessor hca) : ContentDisplayDriver, IConditionEvaluator +public class MvcConditionEvaluatorDriver : ContentDisplayDriver, IConditionEvaluator { + private readonly IHttpContextAccessor _hca; + + public MvcConditionEvaluatorDriver(IHttpContextAccessor hca) => + _hca = hca; + public ValueTask EvaluateAsync(Condition condition) => new(Evaluate((MvcCondition)condition)); private bool Evaluate(MvcCondition condition) => @@ -23,7 +28,7 @@ private bool MatchRouteValue(string name, string value) // Ignore this match operation if the target value is not set. if (string.IsNullOrWhiteSpace(value)) return true; - return hca.HttpContext?.Request.RouteValues.TryGetValue(name, out var routeValue) == true && + return _hca.HttpContext?.Request.RouteValues.TryGetValue(name, out var routeValue) == true && value.EqualsOrdinalIgnoreCase(routeValue?.ToString()); } } diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs index a94054c8..2cc0ac4a 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Liquid/MenuWidgetLiquidFilter.cs @@ -1,4 +1,4 @@ -using Fluid; +using Fluid; using Fluid.Values; using Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels; using Lombiq.HelpfulLibraries.OrchardCore.Liquid; @@ -17,15 +17,25 @@ namespace Lombiq.HelpfulExtensions.Extensions.Widgets.Liquid; -public class MenuWidgetLiquidFilter( - IActionContextAccessor actionContextAccessor, - ILiquidContentDisplayService liquidContentDisplayService, - IStringLocalizer stringLocalizer, - IUrlHelperFactory urlHelperFactory) : ILiquidFilter +public class MenuWidgetLiquidFilter : ILiquidFilter { - private readonly Lazy _urlHelperLazy = new(() => + private readonly ILiquidContentDisplayService _liquidContentDisplayService; + private readonly Lazy _urlHelperLazy; + private readonly IStringLocalizer T; + + public MenuWidgetLiquidFilter( + IActionContextAccessor actionContextAccessor, + ILiquidContentDisplayService liquidContentDisplayService, + IStringLocalizer stringLocalizer, + IUrlHelperFactory urlHelperFactory) + { + _liquidContentDisplayService = liquidContentDisplayService; + + _urlHelperLazy = new Lazy(() => urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext!)); - private readonly IStringLocalizer T = stringLocalizer; + + T = stringLocalizer; + } public ValueTask ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext context) { @@ -59,7 +69,7 @@ public ValueTask ProcessAsync(FluidValue input, FilterArguments argu UpdateMenuItems(menuItems, localNav); - return liquidContentDisplayService.DisplayNewAsync( + return _liquidContentDisplayService.DisplayNewAsync( WidgetTypes.MenuWidget, model => { @@ -88,9 +98,12 @@ private void UpdateMenuItems(IEnumerable menuItems, bool localNav) } } - public class LocalizedStringJsonConverter(IStringLocalizer stringLocalizer) : JsonConverter + public class LocalizedStringJsonConverter : JsonConverter { - private readonly IStringLocalizer T = stringLocalizer; + private readonly IStringLocalizer T; + + public LocalizedStringJsonConverter(IStringLocalizer stringLocalizer) => + T = stringLocalizer; public override void WriteJson(JsonWriter writer, LocalizedString value, JsonSerializer serializer) => writer.WriteValue(value?.Value); diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs index 4fa656fa..00147782 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/Migrations.cs @@ -9,18 +9,23 @@ namespace Lombiq.HelpfulExtensions.Extensions.Widgets; -public class Migrations(IContentDefinitionManager contentDefinitionManager) : DataMigration +public class Migrations : DataMigration { + private readonly IContentDefinitionManager _contentDefinitionManager; + + public Migrations(IContentDefinitionManager contentDefinitionManager) => + _contentDefinitionManager = contentDefinitionManager; + public async Task CreateAsync() { - await contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("TitlePart", part => part.WithPosition("0")) .WithPart("FlowPart", part => part.WithPosition("1")) ); - await contentDefinitionManager.AlterTypeDefinitionAsync(HtmlWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(HtmlWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("HtmlBodyPart", part => part @@ -32,7 +37,7 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(HtmlWidget, builder => b ) ); - await contentDefinitionManager.AlterTypeDefinitionAsync(LiquidWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(LiquidWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("LiquidPart", part => part @@ -40,12 +45,12 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(LiquidWidget, builder => ) ); - await contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) ); - await contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("MarkdownBodyPart", part => part @@ -53,7 +58,7 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder ) ); - var contentItemWidgetPartName = await contentDefinitionManager.AlterPartDefinitionAsync(builder => builder + var contentItemWidgetPartName = await _contentDefinitionManager.AlterPartDefinitionAsync(builder => builder .WithField(part => part.ContentToDisplay, field => field .WithDisplayName("Content to display") .WithSettings(new ContentPickerFieldSettings @@ -65,7 +70,7 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder .WithField(part => part.GroupId, field => field.WithDisplayName("Group ID")) ); - await contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart(contentItemWidgetPartName) @@ -76,7 +81,7 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemW public async Task UpdateFrom1Async() { - await contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder => builder .WithPart("TitlePart", part => part.WithPosition("0")) .WithPart("FlowPart", part => part.WithPosition("1")) ); @@ -86,7 +91,7 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(ContainerWidget, builder public async Task UpdateFrom2Async() { - await contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) ); @@ -96,7 +101,7 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(MenuWidget, builder => b public async Task UpdateFrom3Async() { - await contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart("MarkdownBodyPart", part => part @@ -109,13 +114,13 @@ await contentDefinitionManager.AlterTypeDefinitionAsync(MarkdownWidget, builder public async Task UpdateFrom4Async() { - var contentItemWidgetPartName = await contentDefinitionManager.AlterPartDefinitionAsync(builder => builder + var contentItemWidgetPartName = await _contentDefinitionManager.AlterPartDefinitionAsync(builder => builder .WithField(part => part.ContentToDisplay, field => field.WithDisplayName("Content to display")) .WithField(part => part.DisplayType, field => field.WithDisplayName("Display type")) .WithField(part => part.GroupId, field => field.WithDisplayName("Group ID")) ); - await contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder + await _contentDefinitionManager.AlterTypeDefinitionAsync(WidgetTypes.ContentItemWidget, builder => builder .Securable() .Stereotype(CommonStereotypes.Widget) .WithPart(contentItemWidgetPartName) diff --git a/Lombiq.HelpfulExtensions/Extensions/Widgets/ViewModels/MenuWidgetViewModel.cs b/Lombiq.HelpfulExtensions/Extensions/Widgets/ViewModels/MenuWidgetViewModel.cs index 1c184418..48e7cdef 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Widgets/ViewModels/MenuWidgetViewModel.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Widgets/ViewModels/MenuWidgetViewModel.cs @@ -1,14 +1,14 @@ -using OrchardCore.Navigation; +using OrchardCore.Navigation; using System.Collections.Generic; using System.Linq; namespace Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels; -public class MenuWidgetViewModel(bool noWrapper, IEnumerable menuItems) +public class MenuWidgetViewModel { - public bool NoWrapper { get; set; } = noWrapper; + public bool NoWrapper { get; set; } - public IEnumerable MenuItems { get; set; } = menuItems ?? Enumerable.Empty(); + public IEnumerable MenuItems { get; set; } public string HtmlClasses { get; set; } = string.Empty; @@ -17,6 +17,12 @@ public MenuWidgetViewModel() { } + public MenuWidgetViewModel(bool noWrapper, IEnumerable menuItems) + { + NoWrapper = noWrapper; + MenuItems = menuItems ?? Enumerable.Empty(); + } + public MenuWidgetViewModel(dynamic model) : this((model.NoWrapper as bool?) == true, model.MenuItems as IEnumerable) => HtmlClasses = model.HtmlClasses as string ?? string.Empty; diff --git a/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs b/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs index 3dbbdc02..a1181e43 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Workflows/Activities/GenerateResetPasswordTokenTask.cs @@ -16,14 +16,13 @@ namespace Lombiq.HelpfulExtensions.Extensions.Workflows.Activities; -public class GenerateResetPasswordTokenTask( - IStringLocalizer localizer, - LinkGenerator linkGenerator, - IHttpContextAccessor hca, - UserManager userManager, - IWorkflowScriptEvaluator workflowScriptEvaluator) : TaskActivity +public class GenerateResetPasswordTokenTask : TaskActivity { - private readonly IStringLocalizer T = localizer; + private readonly IStringLocalizer T; + private readonly LinkGenerator _linkGenerator; + private readonly IHttpContextAccessor _hca; + private readonly UserManager _userManager; + private readonly IWorkflowScriptEvaluator _workflowScriptEvaluator; public override string Name => nameof(GenerateResetPasswordTokenTask); public override LocalizedString DisplayText => T["Generate reset password token"]; @@ -47,6 +46,20 @@ public string ResetPasswordUrlPropertyKey set => SetProperty(value); } + public GenerateResetPasswordTokenTask( + IStringLocalizer localizer, + LinkGenerator linkGenerator, + IHttpContextAccessor hca, + UserManager userManager, + IWorkflowScriptEvaluator workflowScriptEvaluator) + { + T = localizer; + _linkGenerator = linkGenerator; + _hca = hca; + _userManager = userManager; + _workflowScriptEvaluator = workflowScriptEvaluator; + } + public override IEnumerable GetPossibleOutcomes( WorkflowExecutionContext workflowContext, ActivityContext activityContext) => @@ -56,14 +69,14 @@ public override async Task ExecuteAsync( WorkflowExecutionContext workflowContext, ActivityContext activityContext) { - var user = await workflowScriptEvaluator.EvaluateAsync(User, workflowContext); + var user = await _workflowScriptEvaluator.EvaluateAsync(User, workflowContext); if (user == null) return Outcomes("Error"); - var generatedToken = await userManager.GeneratePasswordResetTokenAsync(user); + var generatedToken = await _userManager.GeneratePasswordResetTokenAsync(user); user.ResetToken = Convert.ToBase64String(Encoding.UTF8.GetBytes(generatedToken)); - var resetPasswordUrl = linkGenerator.GetUriByAction( - hca.HttpContext, + var resetPasswordUrl = _linkGenerator.GetUriByAction( + _hca.HttpContext, "ResetPassword", "ResetPassword", new { area = "OrchardCore.Users", code = user.ResetToken }); diff --git a/Lombiq.HelpfulExtensions/Extensions/Workflows/Drivers/GenerateResetPasswordTokenTaskDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/Workflows/Drivers/GenerateResetPasswordTokenTaskDisplayDriver.cs index b4d4d66c..32be3ce2 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Workflows/Drivers/GenerateResetPasswordTokenTaskDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Workflows/Drivers/GenerateResetPasswordTokenTaskDisplayDriver.cs @@ -1,5 +1,6 @@ using Lombiq.HelpfulExtensions.Extensions.Workflows.Activities; using Lombiq.HelpfulExtensions.Extensions.Workflows.ViewModels; +using Microsoft.Extensions.Localization; using OrchardCore.DisplayManagement.ModelBinding; using OrchardCore.DisplayManagement.Views; using OrchardCore.Users.Models; @@ -9,9 +10,15 @@ namespace Lombiq.HelpfulExtensions.Extensions.Workflows.Drivers; -public class GenerateResetPasswordTokenTaskDisplayDriver - : ActivityDisplayDriver +public class GenerateResetPasswordTokenTaskDisplayDriver : ActivityDisplayDriver< + GenerateResetPasswordTokenTask, + GenerateResetPasswordTokenTaskViewModel> { + private readonly IStringLocalizer T; + + public GenerateResetPasswordTokenTaskDisplayDriver(IStringLocalizer localizer) => + T = localizer; + protected override void EditActivity(GenerateResetPasswordTokenTask activity, GenerateResetPasswordTokenTaskViewModel model) { model.UserExpression = activity.User.Expression; From ca914d8bef7db61127268d400e10da8b45fcc537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 30 Jan 2024 11:48:35 +0100 Subject: [PATCH 24/43] Fix. --- .../StrictSecurityPermissionAuthorizationHandler.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs index 3acaaf9c..94a325f4 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs @@ -14,8 +14,13 @@ namespace Lombiq.HelpfulExtensions.Extensions.Security.Services; [RequireFeatures(FeatureIds.Security)] -public class StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) : AuthorizationHandler +public class StrictSecurityPermissionAuthorizationHandler : AuthorizationHandler { + private readonly IContentDefinitionManager _contentDefinitionManager; + + public StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) => + _contentDefinitionManager = contentDefinitionManager; + private static readonly Dictionary> _permissionTemplates = ContentTypePermissionsHelper .PermissionTemplates .ToDictionary( @@ -26,7 +31,7 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext { if ((context.Resource as IContent)?.ContentItem is not { } contentItem || !_permissionTemplates.TryGetValue(requirement.Permission.Name, out var claims) || - await contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType) is not { } definition || + await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType) is not { } definition || definition.GetSettings()?.Enabled != true) { return; From 8e2511d487c296ae4df52255aedfc403427a06f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 30 Jan 2024 11:50:21 +0100 Subject: [PATCH 25/43] Fix. --- .../StrictSecurityPermissionAuthorizationHandler.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs index 94a325f4..f61d44db 100644 --- a/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs +++ b/Lombiq.HelpfulExtensions/Extensions/Security/Services/StrictSecurityPermissionAuthorizationHandler.cs @@ -16,17 +16,17 @@ namespace Lombiq.HelpfulExtensions.Extensions.Security.Services; [RequireFeatures(FeatureIds.Security)] public class StrictSecurityPermissionAuthorizationHandler : AuthorizationHandler { - private readonly IContentDefinitionManager _contentDefinitionManager; - - public StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) => - _contentDefinitionManager = contentDefinitionManager; - private static readonly Dictionary> _permissionTemplates = ContentTypePermissionsHelper .PermissionTemplates .ToDictionary( pair => pair.Key, pair => GetPermissionTemplates(pair.Value, new List())); + private readonly IContentDefinitionManager _contentDefinitionManager; + + public StrictSecurityPermissionAuthorizationHandler(IContentDefinitionManager contentDefinitionManager) => + _contentDefinitionManager = contentDefinitionManager; + protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement) { if ((context.Resource as IContent)?.ContentItem is not { } contentItem || From c7e6e8428ea7080c9eddaa56760dd28d2204c7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 30 Jan 2024 12:06:52 +0100 Subject: [PATCH 26/43] Fixes. --- .../Drivers/ContentSetContentPickerFieldDisplayDriver.cs | 3 +-- .../Services/OrchardExportToRecipeConverter.cs | 2 +- .../Extensions/ShapeTracing/ShapeTracingShapeEvents.cs | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs index 19a6a7b8..dfe278f0 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Drivers/ContentSetContentPickerFieldDisplayDriver.cs @@ -4,7 +4,6 @@ using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels; using Lombiq.HelpfulLibraries.OrchardCore.Contents; using Microsoft.Extensions.Localization; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.ContentManagement.Display.Models; @@ -52,7 +51,7 @@ await model.InitializeAsync( new ContentTypePartDefinition( name, await _contentDefinitionManager.GetPartDefinitionAsync(nameof(ContentSetPart)), - new JObject()), + []), isNew: false); }) .Location(CommonContentDisplayTypes.Detail, CommonLocationNames.Content) diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs index d414e453..4b75fe4e 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs @@ -20,7 +20,7 @@ public class OrchardExportToRecipeConverter : IOrchardExportToRecipeConverter private readonly IEnumerable _contentConverters; private readonly IEnumerable _userConverters; - private readonly ICollection _contentTypes; + private readonly List _contentTypes; public OrchardExportToRecipeConverter( IContentDefinitionManager contentDefinitionManager, diff --git a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs index bb4271b9..c9fae732 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ShapeTracing/ShapeTracingShapeEvents.cs @@ -37,7 +37,7 @@ void AddIfNotNullOrEmpty(string name, string value) } } - if (shapeMetadata.Alternates.Any()) + if (shapeMetadata.Alternates.Count != 0) { builder.AppendHtml("Alternates: "); builder.AppendHtmlLine(string.Join(", ", shapeMetadata.Alternates)); @@ -49,7 +49,7 @@ void AddIfNotNullOrEmpty(string name, string value) builder.AppendHtmlLine(string.Join(", ", shapeMetadata.BindingSources)); } - if (shapeMetadata.Wrappers.Any()) + if (shapeMetadata.Wrappers.Count != 0) { builder.AppendHtml("Wrappers: "); builder.AppendHtmlLine(string.Join(", ", shapeMetadata.Wrappers)); From 6d6b04964bde1a60a16528eb0c34196ea6c40d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Thu, 1 Feb 2024 01:09:36 +0100 Subject: [PATCH 27/43] Making ResourceManagerDecorator easier to update --- .../ResourceManagement/ResourceManagerDecorator.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs index bd04c9ea..e1c354eb 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs @@ -8,6 +8,7 @@ using OrchardCore.ResourceManagement; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; @@ -78,11 +79,20 @@ public RequireSettings RegisterUrl(string resourceType, string resourcePath, str public void RenderMeta(TextWriter writer) => resourceManager.RenderMeta(writer); + // Apart from the marked sections, this does the same as the method in OC's ResourceManager. This needs to be kept + // up-to-date with Orchard upgrades. + [SuppressMessage( + "StyleCop.CSharp.ReadabilityRules", + "SA1123:Do not place regions within elements", + Justification = "Needed for easier Orchard upgrades.")] public void RenderStylesheet(TextWriter writer) { + #region CustomCode + var displayedTheme = themeManager.GetThemeAsync().GetAwaiter().GetResult(); + #endregion + var first = true; - var displayedTheme = themeManager.GetThemeAsync().GetAwaiter().GetResult(); var styleSheets = GetRequiredResources("stylesheet").ToList(); foreach (var context in styleSheets) @@ -92,6 +102,7 @@ public void RenderStylesheet(TextWriter writer) continue; } + #region CustomCode var resourceName = context.Resource.Name; var contextIsBootstrap = resourceName.EqualsOrdinalIgnoreCase("bootstrap"); @@ -99,6 +110,7 @@ public void RenderStylesheet(TextWriter writer) { continue; } + #endregion if (!first) { From 063554752f24d066118b7d1238e0559ce639c74f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Thu, 1 Feb 2024 01:12:19 +0100 Subject: [PATCH 28/43] Optimization --- .../ResourceManagement/ResourceManagerDecorator.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs index e1c354eb..70435b44 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs @@ -3,7 +3,6 @@ using Microsoft.Extensions.Options; using OrchardCore.DisplayManagement.Manifest; using OrchardCore.DisplayManagement.Theming; -using OrchardCore.Environment.Extensions; using OrchardCore.Modules; using OrchardCore.ResourceManagement; using System; @@ -89,6 +88,8 @@ public void RenderStylesheet(TextWriter writer) { #region CustomCode var displayedTheme = themeManager.GetThemeAsync().GetAwaiter().GetResult(); + var currentThemeUsesLombiqBaseTheme = displayedTheme?.Id == "Lombiq.BaseTheme" || + displayedTheme?.Manifest.ModuleInfo is ThemeAttribute { BaseTheme: "Lombiq.BaseTheme" }; #endregion var first = true; @@ -103,10 +104,7 @@ public void RenderStylesheet(TextWriter writer) } #region CustomCode - var resourceName = context.Resource.Name; - var contextIsBootstrap = resourceName.EqualsOrdinalIgnoreCase("bootstrap"); - - if (contextIsBootstrap && IsCurrentTheme(displayedTheme)) + if (context.Resource.Name.EqualsOrdinalIgnoreCase("bootstrap") && currentThemeUsesLombiqBaseTheme) { continue; } @@ -136,8 +134,4 @@ public void RenderStylesheet(TextWriter writer) context.WriteTo(writer, NullHtmlEncoder.Default); } } - - private static bool IsCurrentTheme(IExtensionInfo currentSiteTheme) => - currentSiteTheme?.Id == "Lombiq.BaseTheme" || - currentSiteTheme?.Manifest.ModuleInfo is ThemeAttribute { BaseTheme: "Lombiq.BaseTheme" }; } From 4bf30c32d30422e54f6ccf32a4acff6a7164a002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= <92299130+Psichorex@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:06:38 +0100 Subject: [PATCH 29/43] Update Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- .../Extensions/SiteTexts/Services/SiteTextServiceBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs index 0ca15971..5e222bab 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs @@ -36,7 +36,7 @@ protected async Task RenderMarkdownAsync(string markdown) // If it's a single-line expression, then it's presumably inline so don't wrap it in a

element. if (doc.Body is { ChildElementCount: 1, FirstElementChild: { } first } && - first.TagName.Equals("P", StringComparison.OrdinalIgnoreCase)) + first.TagName.EqualsOrdinalIgnoreCase("P")) { html = first.InnerHtml.Trim(); } From 235f271c91b3c23ab4d5bff02e54c4b14e4ab302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Thu, 1 Feb 2024 11:17:23 +0100 Subject: [PATCH 30/43] Moving decorator to BaseTheme. --- .../ResourceManagerDecorator.cs | 137 ------------------ .../Extensions/ResourceManagement/Startup.cs | 13 -- Lombiq.HelpfulExtensions/FeatureIds.cs | 1 - Lombiq.HelpfulExtensions/Manifest.cs | 7 - 4 files changed, 158 deletions(-) delete mode 100644 Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs delete mode 100644 Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs deleted file mode 100644 index 70435b44..00000000 --- a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/ResourceManagerDecorator.cs +++ /dev/null @@ -1,137 +0,0 @@ -using Microsoft.AspNetCore.Html; -using Microsoft.AspNetCore.Razor.TagHelpers; -using Microsoft.Extensions.Options; -using OrchardCore.DisplayManagement.Manifest; -using OrchardCore.DisplayManagement.Theming; -using OrchardCore.Modules; -using OrchardCore.ResourceManagement; -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Linq; - -namespace Lombiq.HelpfulLibraries.OrchardCore.ResourceManagement; - -///

-/// This decorator is replacing the old ReplaceBootstrapMiddleware with the same purpose. -/// Removes the built-in Bootstrap resource if the currently selected theme uses Lombiq.BaseTheme as its base theme. -/// Themes derived from Lombiq.BaseTheme use Bootstrap from NPM as it's compiled into their site stylesheet. So this -/// duplicate resource is not needed and can cause problems if not removed. This situation can arise when a module -/// (such as Lombiq.DataTables) depends on Bootstrap and doesn't explicitly depend on Lombiq.BaseTheme so the built-in -/// resource would be injected if this middleware didn't remove it. -/// -public class ResourceManagerDecorator( - IResourceManager resourceManager, - IThemeManager themeManager, - IOptions resourceManagementOptions) : IResourceManager -{ - private readonly ResourceManagementOptions _options = resourceManagementOptions.Value; - - public ResourceManifest InlineManifest => resourceManager.InlineManifest; - - public void AppendMeta(MetaEntry meta, string contentSeparator) => resourceManager.AppendMeta(meta, contentSeparator); - - public ResourceDefinition FindResource(RequireSettings settings) => resourceManager.FindResource(settings); - - public IEnumerable GetRegisteredFootScripts() => resourceManager.GetRegisteredFootScripts(); - - public IEnumerable GetRegisteredHeadScripts() => resourceManager.GetRegisteredHeadScripts(); - - public IEnumerable GetRegisteredLinks() => resourceManager.GetRegisteredLinks(); - - public IEnumerable GetRegisteredMetas() => resourceManager.GetRegisteredMetas(); - - public IEnumerable GetRegisteredStyles() => resourceManager.GetRegisteredStyles(); - - public IEnumerable GetRequiredResources(string resourceType) => - resourceManager.GetRequiredResources(resourceType); - - public void NotRequired(string resourceType, string resourceName) => - resourceManager.NotRequired(resourceType, resourceName); - - public void RegisterFootScript(IHtmlContent script) => resourceManager.RegisterFootScript(script); - - public void RegisterHeadScript(IHtmlContent script) => resourceManager.RegisterHeadScript(script); - - public void RegisterLink(LinkEntry link) => resourceManager.RegisterLink(link); - - public void RegisterMeta(MetaEntry meta) => resourceManager.RegisterMeta(meta); - - public RequireSettings RegisterResource(string resourceType, string resourceName) => - resourceManager.RegisterResource(resourceType, resourceName); - - public void RegisterStyle(IHtmlContent style) => resourceManager.RegisterStyle(style); - - public RequireSettings RegisterUrl(string resourceType, string resourcePath, string resourceDebugPath) => - resourceManager.RegisterUrl(resourceType, resourcePath, resourceDebugPath); - - public void RenderFootScript(TextWriter writer) => resourceManager.RenderFootScript(writer); - - public void RenderHeadLink(TextWriter writer) => resourceManager.RenderHeadLink(writer); - - public void RenderHeadScript(TextWriter writer) => resourceManager.RenderHeadScript(writer); - - public void RenderLocalScript(RequireSettings settings, TextWriter writer) => resourceManager.RenderLocalScript(settings, writer); - - public void RenderLocalStyle(RequireSettings settings, TextWriter writer) => resourceManager.RenderLocalStyle(settings, writer); - - public void RenderMeta(TextWriter writer) => resourceManager.RenderMeta(writer); - - // Apart from the marked sections, this does the same as the method in OC's ResourceManager. This needs to be kept - // up-to-date with Orchard upgrades. - [SuppressMessage( - "StyleCop.CSharp.ReadabilityRules", - "SA1123:Do not place regions within elements", - Justification = "Needed for easier Orchard upgrades.")] - public void RenderStylesheet(TextWriter writer) - { - #region CustomCode - var displayedTheme = themeManager.GetThemeAsync().GetAwaiter().GetResult(); - var currentThemeUsesLombiqBaseTheme = displayedTheme?.Id == "Lombiq.BaseTheme" || - displayedTheme?.Manifest.ModuleInfo is ThemeAttribute { BaseTheme: "Lombiq.BaseTheme" }; - #endregion - - var first = true; - - var styleSheets = GetRequiredResources("stylesheet").ToList(); - - foreach (var context in styleSheets) - { - if (context.Settings.Location == ResourceLocation.Inline) - { - continue; - } - - #region CustomCode - if (context.Resource.Name.EqualsOrdinalIgnoreCase("bootstrap") && currentThemeUsesLombiqBaseTheme) - { - continue; - } - #endregion - - if (!first) - { - writer.Write(Environment.NewLine); - } - - first = false; - - context.WriteTo(writer, _options.ContentBasePath); - } - - var registeredStyles = GetRegisteredStyles().ToArray(); - for (var i = 0; i < registeredStyles.Length; i++) - { - var context = registeredStyles[i]; - if (!first) - { - writer.Write(Environment.NewLine); - } - - first = false; - - context.WriteTo(writer, NullHtmlEncoder.Default); - } - } -} diff --git a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs b/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs deleted file mode 100644 index 7b613e55..00000000 --- a/Lombiq.HelpfulExtensions/Extensions/ResourceManagement/Startup.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Lombiq.HelpfulLibraries.OrchardCore.ResourceManagement; -using Microsoft.Extensions.DependencyInjection; -using OrchardCore.Modules; -using OrchardCore.ResourceManagement; - -namespace Lombiq.HelpfulExtensions.Extensions.ResourceManagement; - -[Feature(FeatureIds.ResourceManagement)] -public class Startup : StartupBase -{ - public override void ConfigureServices(IServiceCollection services) => - services.Decorate(); -} diff --git a/Lombiq.HelpfulExtensions/FeatureIds.cs b/Lombiq.HelpfulExtensions/FeatureIds.cs index a99af5e4..3cd3b3ee 100644 --- a/Lombiq.HelpfulExtensions/FeatureIds.cs +++ b/Lombiq.HelpfulExtensions/FeatureIds.cs @@ -19,5 +19,4 @@ public static class FeatureIds public const string Workflows = FeatureIdPrefix + nameof(Workflows); public const string Trumbowyg = FeatureIdPrefix + nameof(Trumbowyg); public const string ResetPasswordActivity = Workflows + "." + nameof(ResetPasswordActivity); - public const string ResourceManagement = FeatureIdPrefix + nameof(ResourceManagement); } diff --git a/Lombiq.HelpfulExtensions/Manifest.cs b/Lombiq.HelpfulExtensions/Manifest.cs index 18579bee..29ff8210 100644 --- a/Lombiq.HelpfulExtensions/Manifest.cs +++ b/Lombiq.HelpfulExtensions/Manifest.cs @@ -145,10 +145,3 @@ Category = "Content", Description = "Adds option for inserting code snippets in Trumbowyg editor." )] - -[assembly: Feature( - Id = ResourceManagement, - Name = "Lombiq Helpful Extensions - Resource Management", - Category = "ResourceManagement", - Description = "Adds a decorated version of IResourceManager" -)] From 6bbbc899a009e7de599ff4eaef83198cf776646b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Thu, 1 Feb 2024 11:17:43 +0100 Subject: [PATCH 31/43] Addressing ctor logic. --- .../Models/ContentSetContentPickerField.cs | 2 ++ .../OrchardExportToRecipeConverter.cs | 20 ++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs index 469f24ae..08ee2b3d 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs @@ -2,6 +2,8 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; +#pragma warning disable S2094 // Classes should not be empty public class ContentSetContentPickerField : ContentField +#pragma warning restore S2094 // Classes should not be empty { } diff --git a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs index 4b75fe4e..5eddadb5 100644 --- a/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs +++ b/Lombiq.HelpfulExtensions/Extensions/OrchardRecipeMigration/Services/OrchardExportToRecipeConverter.cs @@ -19,8 +19,7 @@ public class OrchardExportToRecipeConverter : IOrchardExportToRecipeConverter private readonly IEnumerable _exportConverters; private readonly IEnumerable _contentConverters; private readonly IEnumerable _userConverters; - - private readonly List _contentTypes; + private readonly IContentDefinitionManager _contentDefinitionManager; public OrchardExportToRecipeConverter( IContentDefinitionManager contentDefinitionManager, @@ -35,23 +34,20 @@ public OrchardExportToRecipeConverter( _exportConverters = exportConverters; _contentConverters = contentConverters; _userConverters = userConverters; - - _contentTypes = contentDefinitionManager - .ListTypeDefinitionsAsync() - .GetAwaiter() - .GetResult() - .Select(definition => definition.Name) - .ToList(); + _contentDefinitionManager = contentDefinitionManager; } public async Task ConvertAsync(XDocument export) { var contentItems = new List(); var contents = export.XPathSelectElement("//Content")?.Elements() ?? Enumerable.Empty(); + var contentTypes = (await _contentDefinitionManager.ListTypeDefinitionsAsync()) + .Select(definition => definition.Name) + .ToList(); foreach (var content in contents) { - if (await CreateContentItemAsync(content) is { } contentItem) + if (await CreateContentItemAsync(content, contentTypes) is { } contentItem) { contentItem.ContentItemId ??= _idGenerator.GenerateUniqueId(); contentItem.ContentItemVersionId ??= _idGenerator.GenerateUniqueId(); @@ -82,7 +78,7 @@ await _contentConverters return recipe.ToString(); } - private async Task CreateContentItemAsync(XElement content) + private async Task CreateContentItemAsync(XElement content, List contentTypes) { foreach (var converter in _contentConverters.OrderBy(converter => converter.Order)) { @@ -92,7 +88,7 @@ private async Task CreateContentItemAsync(XElement content) } } - return _contentTypes.Contains(content.Name.LocalName) + return contentTypes.Contains(content.Name.LocalName) ? await _contentManager.NewAsync(content.Name.LocalName) : null; } From 895bade2f60a88d49f6fc2bd27b54a82ce73d885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Thu, 1 Feb 2024 11:19:07 +0100 Subject: [PATCH 32/43] Adding directive. --- .../Extensions/SiteTexts/Services/SiteTextServiceBase.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs index 5e222bab..01971090 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs @@ -3,6 +3,7 @@ using OrchardCore.ContentManagement; using OrchardCore.Markdown.Models; using OrchardCore.Markdown.Services; +using OrchardCore.Modules; using System; using System.Threading.Tasks; From e61f9a213367a28e34c2016c921bd75c67ba2cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Thu, 1 Feb 2024 12:46:58 +0100 Subject: [PATCH 33/43] Minor fixing. --- .../Extensions/SiteTexts/Services/SiteTextServiceBase.cs | 1 - Lombiq.HelpfulExtensions/Views/MenuWidget.cshtml | 1 - 2 files changed, 2 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs index 01971090..5e222bab 100644 --- a/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs +++ b/Lombiq.HelpfulExtensions/Extensions/SiteTexts/Services/SiteTextServiceBase.cs @@ -3,7 +3,6 @@ using OrchardCore.ContentManagement; using OrchardCore.Markdown.Models; using OrchardCore.Markdown.Services; -using OrchardCore.Modules; using System; using System.Threading.Tasks; diff --git a/Lombiq.HelpfulExtensions/Views/MenuWidget.cshtml b/Lombiq.HelpfulExtensions/Views/MenuWidget.cshtml index 9f57bc86..68d66eaf 100644 --- a/Lombiq.HelpfulExtensions/Views/MenuWidget.cshtml +++ b/Lombiq.HelpfulExtensions/Views/MenuWidget.cshtml @@ -1,6 +1,5 @@ @using Lombiq.HelpfulLibraries.Common.Utilities; @using Microsoft.AspNetCore.Http.Extensions -@using OrchardCore.Modules @using OrchardCore.Navigation From 437f57c4d7e53349e8800f49bc110dc62f540e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Thu, 1 Feb 2024 17:48:41 +0100 Subject: [PATCH 34/43] Adding form-label. --- .../Views/AdditionalStylingPart.Edit.cshtml | 4 ++-- Lombiq.HelpfulExtensions/Views/ContentSetPart.Edit.cshtml | 4 ++-- .../Items/GenerateResetPasswordTokenTask.Fields.Edit.cshtml | 6 +++--- .../Views/MvcCondition.Fields.Edit.cshtml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Views/AdditionalStylingPart.Edit.cshtml b/Lombiq.HelpfulExtensions/Views/AdditionalStylingPart.Edit.cshtml index 44a280ee..bbfe0b77 100644 --- a/Lombiq.HelpfulExtensions/Views/AdditionalStylingPart.Edit.cshtml +++ b/Lombiq.HelpfulExtensions/Views/AdditionalStylingPart.Edit.cshtml @@ -6,12 +6,12 @@ diff --git a/Lombiq.HelpfulExtensions/Views/ContentSetPart.Edit.cshtml b/Lombiq.HelpfulExtensions/Views/ContentSetPart.Edit.cshtml index 9fb2805b..b2d10c57 100644 --- a/Lombiq.HelpfulExtensions/Views/ContentSetPart.Edit.cshtml +++ b/Lombiq.HelpfulExtensions/Views/ContentSetPart.Edit.cshtml @@ -1,4 +1,4 @@ -@model Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels.ContentSetPartViewModel +@model Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels.ContentSetPartViewModel

@T["Information about the \"{0}\" content set part.", Model.Definition.Name]

@@ -7,7 +7,7 @@ @if (!Model.IsNew) {
- +
    @foreach (var link in Model.MemberLinks) { diff --git a/Lombiq.HelpfulExtensions/Views/Items/GenerateResetPasswordTokenTask.Fields.Edit.cshtml b/Lombiq.HelpfulExtensions/Views/Items/GenerateResetPasswordTokenTask.Fields.Edit.cshtml index 862a0857..6f8ac589 100644 --- a/Lombiq.HelpfulExtensions/Views/Items/GenerateResetPasswordTokenTask.Fields.Edit.cshtml +++ b/Lombiq.HelpfulExtensions/Views/Items/GenerateResetPasswordTokenTask.Fields.Edit.cshtml @@ -1,19 +1,19 @@ @model Lombiq.HelpfulExtensions.Extensions.Workflows.ViewModels.GenerateResetPasswordTokenTaskViewModel
    - + @T["Enter a JavaScript expression that evaluates to the User object."]
    - + @T["Optional key of the property in the Workflow context where this Task will set the reset password token to."]
    - + @T["Optional key of the property in the Workflow context where this Task will set the reset password URL to."] diff --git a/Lombiq.HelpfulExtensions/Views/MvcCondition.Fields.Edit.cshtml b/Lombiq.HelpfulExtensions/Views/MvcCondition.Fields.Edit.cshtml index bbf2dfc4..f75783b8 100644 --- a/Lombiq.HelpfulExtensions/Views/MvcCondition.Fields.Edit.cshtml +++ b/Lombiq.HelpfulExtensions/Views/MvcCondition.Fields.Edit.cshtml @@ -17,7 +17,7 @@
    - + \ No newline at end of file + From 5481622ec68970e14392190240fde39b22c26576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 5 Feb 2024 15:12:02 +0100 Subject: [PATCH 35/43] Removing supresses. --- .../ContentSets/Models/ContentSetContentPickerField.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs index 08ee2b3d..469f24ae 100644 --- a/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs +++ b/Lombiq.HelpfulExtensions/Extensions/ContentSets/Models/ContentSetContentPickerField.cs @@ -2,8 +2,6 @@ namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Models; -#pragma warning disable S2094 // Classes should not be empty public class ContentSetContentPickerField : ContentField -#pragma warning restore S2094 // Classes should not be empty { } From 8048da782712ffd913ed61e90faaac6dbf678c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Fri, 16 Feb 2024 14:08:55 +0100 Subject: [PATCH 36/43] Upgrading alpha of Tests.UI. --- .../Lombiq.HelpfulExtensions.Tests.UI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj index e3366a44..4a129b62 100644 --- a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj +++ b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj @@ -37,7 +37,7 @@ - + From 0ee41adbe951ec4010394e0da4381e1755f179a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Fri, 16 Feb 2024 14:09:44 +0100 Subject: [PATCH 37/43] Upgrading alpha of HelpfulLibraries. --- Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj b/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj index 822024ba..5ac53cc9 100644 --- a/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj +++ b/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj @@ -57,7 +57,7 @@ - + From fce006c3fb6d36a6eff73b2a0149e0656e7d349f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Fri, 16 Feb 2024 14:10:51 +0100 Subject: [PATCH 38/43] Upgrading publish-nuget branch reference. --- .github/workflows/publish-nuget.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index 4b26cfcf..8360fd9e 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -7,6 +7,6 @@ on: jobs: publish-nuget: - uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@dev + uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@issue/OSOE-751 secrets: API_KEY: ${{ secrets.DEFAULT_NUGET_PUBLISH_API_KEY }} From f6c62655b292380f10a7706f4302575cf2a7fced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 17 Feb 2024 10:10:42 +0100 Subject: [PATCH 39/43] Using alpha. --- Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj b/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj index 5ac53cc9..5224bdce 100644 --- a/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj +++ b/Lombiq.HelpfulExtensions/Lombiq.HelpfulExtensions.csproj @@ -58,7 +58,7 @@ - + From 3deab83fd375665f3993d7475f06d6ba16fb5dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sun, 18 Feb 2024 13:54:00 +0100 Subject: [PATCH 40/43] Updating UITT with latest Atata. --- .../Lombiq.HelpfulExtensions.Tests.UI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj index 4a129b62..638db4fb 100644 --- a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj +++ b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj @@ -37,7 +37,7 @@ - + From 90387bc0a9b8af5d73ae9ba32c452ef0c3968210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 20 Feb 2024 09:47:24 +0100 Subject: [PATCH 41/43] Using new UITT alpha. --- .../Lombiq.HelpfulExtensions.Tests.UI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj index 638db4fb..bef6e215 100644 --- a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj +++ b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj @@ -37,7 +37,7 @@ - + From cc2d6649b685177b11fa348e635cc157a8adff98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Wed, 21 Feb 2024 11:41:08 +0100 Subject: [PATCH 42/43] Using new UITT alpha. --- .../Lombiq.HelpfulExtensions.Tests.UI.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj index bef6e215..fbc9a14a 100644 --- a/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj +++ b/Lombiq.HelpfulExtensions.Tests.UI/Lombiq.HelpfulExtensions.Tests.UI.csproj @@ -37,7 +37,7 @@ - + From e39c494c163c7b8c8f716601abed0bd4607648a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Wed, 21 Feb 2024 16:24:00 +0100 Subject: [PATCH 43/43] Reverting to dev reference. --- .github/workflows/publish-nuget.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index 8360fd9e..4b26cfcf 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -7,6 +7,6 @@ on: jobs: publish-nuget: - uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@issue/OSOE-751 + uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@dev secrets: API_KEY: ${{ secrets.DEFAULT_NUGET_PUBLISH_API_KEY }}