Skip to content

Commit

Permalink
Merge branch 'v14/dev' of github.com:umbraco/Umbraco-CMS into v14/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
iOvergaard committed Aug 29, 2024
2 parents 590b281 + c277005 commit 9321774
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.ViewModels.Content;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.ContentEditing.Validation;
using Umbraco.Cms.Core.Services.OperationStatus;
Expand All @@ -9,6 +11,7 @@ namespace Umbraco.Cms.Api.Management.Controllers.Content;

public abstract class ContentControllerBase : ManagementApiControllerBase
{

protected IActionResult ContentEditingOperationStatusResult(ContentEditingOperationStatus status)
=> OperationStatusResult(status, problemDetailsBuilder => status switch
{
Expand Down Expand Up @@ -96,7 +99,8 @@ protected IActionResult ContentEditingOperationStatusResult<TContentModelBase, T
}

var errors = new SortedDictionary<string, string[]>();
var missingPropertyAliases = new List<string>();

var missingPropertyModels = new List<PropertyValidationResponseModel>();
foreach (PropertyValidationError validationError in validationResult.ValidationErrors)
{
TValueModel? requestValue = requestModel.Values.FirstOrDefault(value =>
Expand All @@ -105,7 +109,7 @@ protected IActionResult ContentEditingOperationStatusResult<TContentModelBase, T
&& value.Segment == validationError.Segment);
if (requestValue is null)
{
missingPropertyAliases.Add(validationError.Alias);
missingPropertyModels.Add(MapMissingProperty(validationError));
continue;
}

Expand All @@ -119,7 +123,16 @@ protected IActionResult ContentEditingOperationStatusResult<TContentModelBase, T
.WithTitle("Validation failed")
.WithDetail("One or more properties did not pass validation")
.WithRequestModelErrors(errors)
.WithExtension("missingProperties", missingPropertyAliases.ToArray())
.WithExtension("missingValues", missingPropertyModels.ToArray())
.Build()));
}

private PropertyValidationResponseModel MapMissingProperty(PropertyValidationError source) =>
new()
{
Alias = source.Alias,
Segment = source.Segment,
Culture = source.Culture,
Messages = source.ErrorMessages,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Umbraco.Cms.Api.Management.ViewModels.Content;

public class PropertyValidationResponseModel
{
public string[] Messages { get; set; } = Array.Empty<string>();

public string Alias { get; set; } = string.Empty;

public string? Culture { get; set; }

public string? Segment { get; set; }
}

0 comments on commit 9321774

Please sign in to comment.