Skip to content

Commit

Permalink
Upgrading to .NET 8 and OC 1.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Psichorex committed Jan 18, 2024
1 parent af85be4 commit c57ba17
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 73 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
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.Models;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Services;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels;
Expand Down Expand Up @@ -41,17 +41,17 @@ 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)),
await _contentDefinitionManager.GetPartDefinitionAsync(nameof(ContentSetPart)),
new JObject()),
isNew: false);
})
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,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 @@ -37,7 +37,9 @@ public OrchardExportToRecipeConverter(
_userConverters = userConverters;

_contentTypes = contentDefinitionManager
.ListTypeDefinitions()
.ListTypeDefinitionsAsync()
.GetAwaiter()
.GetResult()
.Select(definition => definition.Name)
.ToList();
}
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
@@ -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
@@ -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;

Expand All @@ -16,9 +17,9 @@ public class SiteTextMigrations : DataMigration
public SiteTextMigrations(IContentDefinitionManager contentDefinitionManager) =>
_contentDefinitionManager = contentDefinitionManager;

public int Create()
public async Task<int> CreateAsync()
{
_contentDefinitionManager.AlterTypeDefinition(SiteText, builder => builder
await _contentDefinitionManager.AlterTypeDefinitionAsync(SiteText, builder => builder
.SetAbilities(
creatable: true,
securable: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Loading

0 comments on commit c57ba17

Please sign in to comment.