Skip to content

Commit

Permalink
Merge pull request #265 from Lombiq/issue/OCC-245
Browse files Browse the repository at this point in the history
OCC-245: Update OC preview version and fix breaking changes
  • Loading branch information
Piedone authored Jul 28, 2024
2 parents dcd3701 + b7e6247 commit 2a3dee8
Show file tree
Hide file tree
Showing 24 changed files with 237 additions and 223 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
publish-nuget:
if: ${{ !contains(github.ref_name, '-preview.') }}
uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@dev
secrets:
API_KEY: ${{ secrets.DEFAULT_NUGET_PUBLISH_API_KEY }}

This file was deleted.

37 changes: 37 additions & 0 deletions Lombiq.HelpfulLibraries.AspNetCore/Mvc/HttpRequestInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#nullable enable

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using System.Collections.Generic;
using System.Text.Json;

namespace Lombiq.HelpfulLibraries.AspNetCore.Mvc;

/// <summary>
/// A simplified intermediate type that can be used to debug <see cref="HttpRequest"/>.
/// </summary>
public record HttpRequestInfo(
string Url,
string? ContentType,
IHeaderDictionary Headers,
IDictionary<string, string> Form,
IRequestCookieCollection Cookies)
{
public HttpRequestInfo(HttpRequest request)
: this(
request.GetDisplayUrl(),
request.ContentType,
request.Headers,
request.HasFormContentType ?
request.Form.ToDictionaryIgnoreCase(pair => pair.Key, pair => pair.Value.ToString()) :
new Dictionary<string, string>(),
request.Cookies)
{
}

public override string ToString() => $"HTTP Request at \"{Url}\"";

public string ToJson() => JsonSerializer.Serialize(this);

public static string? ToJson(HttpRequest? request) => request == null ? null : new HttpRequestInfo(request).ToJson();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@

<ItemGroup>
<PackageReference Include="linq2db" Version="5.4.0" />
<PackageReference Include="OrchardCore.Data.YesSql" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Data.YesSql" Version="2.0.0-preview-18282" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
using System;
using OrchardCore.DisplayManagement.Entities;
using System;
using System.Threading.Tasks;

namespace OrchardCore.DisplayManagement.Handlers;

public static class BuildEditorContextExtensions
{
public static async Task<T> CreateModelMaybeAsync<T>(
/// <summary>
/// Creates a new instance of <typeparamref name="TViewModel"/> and tries to populate it from the <paramref
/// name="context"/> with the <paramref name="prefix"/>.
/// </summary>
/// <param name="context">The editor context of the current update request.</param>
/// <param name="prefix">The name prefix of the fields being edited.</param>
/// <param name="groupId">
/// If not <see langword="null"/>, it's needed to check the group (e.g. in <see
/// cref="SectionDisplayDriver{TModel,TSection}"/>. The value is checked against the <see
/// cref="BuildShapeContext.GroupId"/> and if they don't match <see langword="null"/> is returned.
/// </param>
/// <param name="authorizeAsync">
/// If not <see langword="null"/> and the awaited result is <see langword="false"/>, then <see langword="null"/> is
/// returned.
/// </param>
/// <typeparam name="TViewModel">The expected view-model type.</typeparam>
/// <returns>
/// A new instance of <typeparamref name="TViewModel"/>, populated with data from <paramref name="context"/>. Unless
/// at least one of <paramref name="groupId"/> and <paramref name="authorizeAsync"/> are provided and the checks
/// failed, at which case <see langword="null"/> is returned.
/// </returns>
public static async Task<TViewModel> CreateModelMaybeAsync<TViewModel>(
this BuildEditorContext context,
string prefix,
string groupId = null,
Func<Task<bool>> authorizeAsync = null)
where T : class, new()
where TViewModel : class, new()
{
if (!string.IsNullOrEmpty(groupId) && context.GroupId != groupId) return null;

Expand All @@ -19,9 +41,8 @@ public static async Task<T> CreateModelMaybeAsync<T>(
return null;
}

var viewModel = new T();
return await context.Updater.TryUpdateModelAsync(viewModel, prefix)
? viewModel
: null;
var viewModel = new TViewModel();
await context.Updater.TryUpdateModelAsync(viewModel, prefix);
return viewModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static Task<ContentItem> GetContentItemOrPreviewAsync(

if (httpContext.Request.Method == "POST")
{
var previewContentItemId = httpContext.Request.Form["PreviewContentItemId"];
var previewContentItemId = httpContext.Request.Form["PreviewContentItemId"].ToString();
if (!string.IsNullOrEmpty(previewContentItemId))
{
return httpContext.RequestServices.GetService<IContentManager>().GetAsync(previewContentItemId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ await AuthorizeAsync()

public override async Task<IDisplayResult> UpdateAsync(TSection section, UpdateEditorContext context)
{
var viewModel = new JsonViewModel<TAdditionalData>();

if (context.GroupId == GroupId &&
await AuthorizeAsync() &&
await context.Updater.TryUpdateModelAsync(viewModel, Prefix) &&
if (await context.CreateModelMaybeAsync<JsonViewModel<TAdditionalData>>(Prefix, GroupId, AuthorizeAsync) is { } viewModel &&
TryParseJson(viewModel.Json, out var result))
{
await UpdateAsync(section, context, result);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Microsoft.AspNetCore.Builder;
#nullable enable

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Modules;
using System;
using System.Threading.Tasks;

namespace Lombiq.HelpfulLibraries.OrchardCore.DependencyInjection;

Expand All @@ -11,33 +14,39 @@ namespace Lombiq.HelpfulLibraries.OrchardCore.DependencyInjection;
/// </summary>
public class InlineStartup : StartupBase
{
private readonly Action<IServiceCollection> _configureServices;
private readonly Action<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider> _configure;
private readonly int _order;
private readonly Action<IServiceCollection>? _configureServices;
private readonly Action<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider>? _configure;
private readonly Func<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider, ValueTask>? _configureAsync;

public override int Order => _order;
public override int Order { get; }

public InlineStartup(
Action<IServiceCollection> configureServices,
Action<IServiceCollection>? configureServices,
Action<IApplicationBuilder> configure,
Func<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider, ValueTask>? configureAsync = null,
int order = 0)
: this(configureServices, (app, _, _) => configure(app), order)
: this(configureServices, (app, _, _) => configure(app), configureAsync, order)
{
}

public InlineStartup(
Action<IServiceCollection> configureServices,
Action<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider> configure = null,
Action<IServiceCollection>? configureServices = null,
Action<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider>? configure = null,
Func<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider, ValueTask>? configureAsync = null,
int order = 0)
{
_configureServices = configureServices;
_configure = configure;
_order = order;
_configureAsync = configureAsync;
Order = order;
}

public override void ConfigureServices(IServiceCollection services) =>
_configureServices?.Invoke(services);

public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) =>
_configure?.Invoke(app, routes, serviceProvider);

public override ValueTask ConfigureAsync(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) =>
_configureAsync?.Invoke(app, routes, serviceProvider) ?? ValueTask.CompletedTask;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#nullable enable

using Lombiq.HelpfulLibraries.Common.DependencyInjection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OrchardCore.Modules;
using System;
using System.Threading.Tasks;

namespace Lombiq.HelpfulLibraries.OrchardCore.DependencyInjection;

Expand All @@ -26,19 +29,21 @@ public static void AddOrchardServices(this IServiceCollection services)
/// </summary>
public static IServiceCollection AddInlineStartup(
this IServiceCollection services,
Action<IServiceCollection> configureServices,
Action<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider> configure,
Action<IServiceCollection>? configureServices = null,
Action<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider>? configure = null,
Func<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider, ValueTask>? configureAsync = null,
int order = 0) =>
services.AddSingleton<IStartup>(new InlineStartup(configureServices, configure, order));
services.AddSingleton<IStartup>(new InlineStartup(configureServices, configure, configureAsync, order));

/// <summary>
/// Creates a new <see cref="InlineStartup"/> instance using the provided parameters, and adds it to the service
/// collection.
/// </summary>
public static IServiceCollection AddInlineStartup(
this IServiceCollection services,
Action<IServiceCollection> configureServices,
Action<IServiceCollection>? configureServices,
Action<IApplicationBuilder> configure,
Func<IApplicationBuilder, IEndpointRouteBuilder, IServiceProvider, ValueTask>? configureAsync = null,
int order = 0) =>
services.AddSingleton<IStartup>(new InlineStartup(configureServices, configure, order));
services.AddSingleton<IStartup>(new InlineStartup(configureServices, configure, configureAsync, order));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OrchardCore.Email;
using OrchardCore.Environment.Shell.Configuration;
using OrchardCore.ResourceManagement;
using System;

namespace Microsoft.Extensions.DependencyInjection;

Expand Down Expand Up @@ -29,6 +30,7 @@ public static OrchardCoreBuilder AddDatabaseShellsConfigurationIfAvailable(
/// If set to <see langword="true"/> the settings coming from the configuration provider will override the ones set
/// up from the admin UI.
/// </param>
[Obsolete("The email configuration has changed in OC 2.0, see https://docs.orchardcore.net/en/latest/releases/2.0.0/#email-module.")]
public static OrchardCoreBuilder ConfigureSmtpSettings(
this OrchardCoreBuilder builder,
bool overrideAdminSettings = true)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OrchardCore.ContentManagement.GraphQL.Queries;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using YesSql.Indexes;

namespace Lombiq.HelpfulLibraries.OrchardCore.GraphQL;
Expand All @@ -13,7 +14,7 @@ namespace Lombiq.HelpfulLibraries.OrchardCore.GraphQL;
public class PartIndexAliasProvider<TIndex> : IIndexAliasProvider
where TIndex : class, IIndex
{
private static readonly IndexAlias[] _aliases =
private static readonly IEnumerable<IndexAlias> _aliases =
[
new()
{
Expand All @@ -29,5 +30,5 @@ public class PartIndexAliasProvider<TIndex> : IIndexAliasProvider
/// <summary>
/// Gets indexes with a name ending in <c>PartIndex</c>.
/// </summary>
public IEnumerable<IndexAlias> GetAliases() => _aliases;
public ValueTask<IEnumerable<IndexAlias>> GetAliasesAsync() => ValueTask.FromResult(_aliases);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public TotalOfContentTypeBuilder(IStringLocalizer<TotalOfContentTypeBuilder> str
/// <param name="contentItemType">
/// The content item type to be extended with the <c>totalOfContentType</c> integer field.
/// </param>
public void Build(FieldType contentQuery, ContentTypeDefinition contentTypeDefinition, ContentItemType contentItemType)
public void Build(ISchema schema, FieldType contentQuery, ContentTypeDefinition contentTypeDefinition, ContentItemType contentItemType)
{
var name = contentTypeDefinition.Name;

Expand Down
Loading

0 comments on commit 2a3dee8

Please sign in to comment.