Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't configure JsonOptions by default #16837

Merged
merged 16 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.Json;
using OrchardCore.Modules;

namespace OrchardCore.Contents.Endpoints.Api;
Expand Down Expand Up @@ -37,6 +39,7 @@ private static async Task<IResult> HandleAsync(
IContentDefinitionManager contentDefinitionManager,
IUpdateModelAccessor updateModelAccessor,
HttpContext httpContext,
IOptions<DocumentJsonSerializerOptions> options,
bool draft = false)
{
if (!await authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.AccessContentApi))
Expand Down Expand Up @@ -123,7 +126,7 @@ private static async Task<IResult> HandleAsync(
await contentManager.SaveDraftAsync(contentItem);
}

return TypedResults.Ok(contentItem);
return Results.Json(contentItem, options.Value.SerializerOptions);
Piedone marked this conversation as resolved.
Show resolved Hide resolved
}

private static void AddValidationErrorsToModelState(ContentValidateResult result, ModelStateDictionary modelState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using OrchardCore.ContentManagement;
using OrchardCore.Json;
using OrchardCore.Modules;

namespace OrchardCore.Contents.Endpoints.Api;
Expand All @@ -23,7 +25,8 @@ private static async Task<IResult> HandleAsync(
string contentItemId,
IContentManager contentManager,
IAuthorizationService authorizationService,
HttpContext httpContext)
HttpContext httpContext,
IOptions<DocumentJsonSerializerOptions> options)
{
if (!await authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.AccessContentApi))
{
Expand All @@ -44,6 +47,6 @@ private static async Task<IResult> HandleAsync(

await contentManager.RemoveAsync(contentItem);

return TypedResults.Ok(contentItem);
return Results.Json(contentItem, options.Value.SerializerOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using OrchardCore.ContentManagement;
using OrchardCore.Json;
using OrchardCore.Modules;

namespace OrchardCore.Contents.Endpoints.Api;
Expand All @@ -23,7 +25,8 @@ private static async Task<IResult> HandleAsync(
string contentItemId,
IContentManager contentManager,
IAuthorizationService authorizationService,
HttpContext httpContext)
HttpContext httpContext,
IOptions<DocumentJsonSerializerOptions> options)
{
if (!await authorizationService.AuthorizeAsync(httpContext.User, CommonPermissions.AccessContentApi))
{
Expand All @@ -42,6 +45,6 @@ private static async Task<IResult> HandleAsync(
return httpContext.ChallengeOrForbid("Api");
}

return TypedResults.Ok(contentItem);
return Results.Json(contentItem, options.Value.SerializerOptions);
Piedone marked this conversation as resolved.
Show resolved Hide resolved
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ private static void AddDefaultServices(OrchardCoreBuilder builder)
services.AddScoped<ICalendarSelector, DefaultCalendarSelector>();

services.AddSingleton<IPoweredByMiddlewareOptions, PoweredByMiddlewareOptions>();

services.AddTransient<IConfigureOptions<Microsoft.AspNetCore.Http.Json.JsonOptions>, JsonOptionsConfigurations>();
services.AddTransient<IConfigureOptions<DocumentJsonSerializerOptions>, DocumentJsonSerializerOptionsConfiguration>();

services.AddScoped<IOrchardHelper, DefaultOrchardHelper>();
Expand Down