Skip to content

Commit

Permalink
Merge pull request #160 from Lombiq/issue/OSOE-751
Browse files Browse the repository at this point in the history
OSOE-751: Upgrade to Orchard Core 1.8
  • Loading branch information
Psichorex authored Feb 21, 2024
2 parents c75f295 + e39c494 commit 29c2ed1
Show file tree
Hide file tree
Showing 25 changed files with 128 additions and 136 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes>
</PropertyGroup>

Expand Down Expand Up @@ -37,7 +37,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.Tests.UI" Version="8.1.0-alpha.1.osoe-638" />
<PackageReference Include="Lombiq.Tests.UI" Version="8.2.1-alpha.22.osoe-751" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AngleSharp.Io;
using AngleSharp.Io;
using Lombiq.HelpfulExtensions.Extensions.OrchardRecipeMigration.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -55,7 +55,7 @@ public async Task<IActionResult> 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
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;
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;
Expand Down Expand Up @@ -41,18 +40,18 @@ public override IDisplayResult Display(
var name = fieldDisplayContext.PartFieldDefinition.Name;
if (field.ContentItem.Get<ContentSetPart>(name) is not { } part) return null;

return Initialize<ContentSetContentPickerFieldViewModel>(GetDisplayShapeType(fieldDisplayContext), model =>
return Initialize<ContentSetContentPickerFieldViewModel>(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)),
new JObject()),
await _contentDefinitionManager.GetPartDefinitionAsync(nameof(ContentSetPart)),
[]),
isNew: false);
})
.Location(CommonContentDisplayTypes.Detail, CommonLocationNames.Content)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,15 +37,14 @@ public ContentSetIndexProvider(IServiceProvider provider) =>
_provider = provider;

public override void Describe(DescribeContext<ContentItem> context) =>
context.For<ContentSetIndex>().Map(contentItem =>
context.For<ContentSetIndex>().Map(async contentItem =>
{
if (!contentItem.Latest) return Enumerable.Empty<ContentSetIndex>();

using var scope = _provider.CreateScope();
var contentDefinitionManager = scope.ServiceProvider.GetRequiredService<IContentDefinitionManager>();

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<ContentSetPart>(part.Name), part.Name })
Expand Down
9 changes: 5 additions & 4 deletions Lombiq.HelpfulExtensions/Extensions/ContentSets/Migrations.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,14 +16,14 @@ public class Migrations : DataMigration
public Migrations(IContentDefinitionManager contentDefinitionManager) =>
_contentDefinitionManager = contentDefinitionManager;

public int Create()
public async Task<int> CreateAsync()
{
_contentDefinitionManager.AlterPartDefinition(nameof(ContentSetPart), builder => builder
await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(ContentSetPart), builder => builder
.Attachable()
.Reusable()
.WithDisplayName("Content Set"));

SchemaBuilder.CreateMapIndexTable<ContentSetIndex>(table => table
await SchemaBuilder.CreateMapIndexTableAsync<ContentSetIndex>(table => table
.Column<string>(nameof(ContentSetIndex.ContentItemId), column => column.WithCommonUniqueIdLength())
.Column<string>(nameof(ContentSetIndex.PartName))
.Column<bool>(nameof(ContentSetIndex.IsPublished))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand Down
15 changes: 8 additions & 7 deletions Lombiq.HelpfulExtensions/Extensions/ContentTypes/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,9 +14,9 @@ public class Migrations : DataMigration
public Migrations(IContentDefinitionManager contentDefinitionManager) =>
_contentDefinitionManager = contentDefinitionManager;

public int Create()
public async Task<int> CreateAsync()
{
_contentDefinitionManager.AlterTypeDefinition(Page, builder => builder
await _contentDefinitionManager.AlterTypeDefinitionAsync(Page, builder => builder
.Creatable()
.Securable()
.Draftable()
Expand All @@ -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<int> 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"))
Expand All @@ -51,9 +52,9 @@ public int UpdateFrom1()
return 2;
}

public int UpdateFrom2()
public async Task<int> 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.")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AdditionalStylingPart>() &&
_contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType)
(await _contentDefinitionManager.GetTypeDefinitionAsync(context.ContentItem.ContentType))
.GetSettings<ContentTypeSettings>().Stereotype == "Widget")
{
context.ContentItem.Weld<AdditionalStylingPart>();
}

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class OrchardExportToRecipeConverter : IOrchardExportToRecipeConverter
private readonly IEnumerable<IOrchardExportConverter> _exportConverters;
private readonly IEnumerable<IOrchardContentConverter> _contentConverters;
private readonly IEnumerable<IOrchardUserConverter> _userConverters;

private readonly ICollection<string> _contentTypes;
private readonly IContentDefinitionManager _contentDefinitionManager;

public OrchardExportToRecipeConverter(
IContentDefinitionManager contentDefinitionManager,
Expand All @@ -35,21 +34,20 @@ public OrchardExportToRecipeConverter(
_exportConverters = exportConverters;
_contentConverters = contentConverters;
_userConverters = userConverters;

_contentTypes = contentDefinitionManager
.ListTypeDefinitions()
.Select(definition => definition.Name)
.ToList();
_contentDefinitionManager = contentDefinitionManager;
}

public async Task<string> ConvertAsync(XDocument export)
{
var contentItems = new List<ContentItem>();
var contents = export.XPathSelectElement("//Content")?.Elements() ?? Enumerable.Empty<XElement>();
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();
Expand Down Expand Up @@ -80,7 +78,7 @@ await _contentConverters
return recipe.ToString();
}

private async Task<ContentItem> CreateContentItemAsync(XElement content)
private async Task<ContentItem> CreateContentItemAsync(XElement content, List<string> contentTypes)
{
foreach (var converter in _contentConverters.OrderBy(converter => converter.Order))
{
Expand All @@ -90,7 +88,7 @@ private async Task<ContentItem> CreateContentItemAsync(XElement content)
}
}

return _contentTypes.Contains(content.Name.LocalName)
return contentTypes.Contains(content.Name.LocalName)
? await _contentManager.NewAsync(content.Name.LocalName)
: null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string>() : roles.Split(',').ToList();
var rolesList = string.IsNullOrEmpty(roles) ? new List<string>() : [.. roles.Split(',')];

await _userService.CreateUserAsync(
new User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<StrictSecuritySettings>()?.Enabled != true)
{
return Task.CompletedTask;
return;
}

if (!context.User.Identity.IsAuthenticated)
{
context.Fail();
return Task.CompletedTask;
return;
}

var contentType = contentItem.ContentType;
Expand All @@ -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<string> GetPermissionTemplates(Permission permission, IList<string> templates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,9 +13,9 @@ public class LocalizationMigrations : DataMigration
public LocalizationMigrations(IContentDefinitionManager contentDefinitionManager) =>
_contentDefinitionManager = contentDefinitionManager;

public int Create()
public async Task<int> CreateAsync()
{
_contentDefinitionManager.AlterTypeDefinition(SiteText, builder => builder
await _contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder
.WithPart(nameof(LocalizationPart)));

return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected async Task<HtmlString> RenderMarkdownAsync(string markdown)

// If it's a single-line expression, then it's presumably inline so don't wrap it in a <p> element.
if (doc.Body is { ChildElementCount: 1, FirstElementChild: { } first } &&
first.TagName.ToUpperInvariant() == "P")
first.TagName.EqualsOrdinalIgnoreCase("P"))
{
html = first.InnerHtml.Trim();
}
Expand Down
Loading

0 comments on commit 29c2ed1

Please sign in to comment.