-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Management API: Add document patch endpoint #22104
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
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
1496282
Document patch, variant name only
Migaroez 90f55f3
Multi variant tests
Migaroez 6e246f1
Change to json-patch instead of merge to target nested properties
Migaroez ab7514e
Fix ManagementApiTest following PR 20820
Migaroez cfc1bd9
Segment suport for properties
Migaroez 6a31bc2
Verify non existing and trashed document patch behaviour
Migaroez f27f536
Mostly working approuch for nested properties
Migaroez 1bff7a3
Fix endpoint route collision (Somehow...)
Migaroez 9d2b26f
Trying a custom way of doing things
Migaroez 07a1c01
Merge branch 'main' into v17/task/document-patch
Migaroez 24eff60
add escape support, more tests and cleanup
Migaroez f615980
remove unnecesary using
Migaroez 1a03c12
Cleanup
Migaroez 83a60bd
Restore things that are breaking
Migaroez 746cece
cleanup
Migaroez 4501d21
Namespace cleanup
Migaroez 9e9fde6
Order cleanup
Migaroez cbec759
More comment updates
Migaroez c2f1eee
Merge branch 'main' into v17/task/document-patch
AndyButland 6e00a16
Add default implementations
Migaroez 7a9847b
Improve modelbinding validation
Migaroez 19ba6de
all string comparison
Migaroez 632954a
Cleanup unused statuses
Migaroez 59175dd
Fix PatchPathResolver Filtering not accepting non string values
Migaroez 54a2edb
Optimize path parsing
Migaroez 2127de8
Improve cookie token rework
Migaroez 5eedb37
more cleanup
Migaroez 03a743c
Put AllowedValues on the correct property 🙈
Migaroez b7321f9
Merge branch 'main' into v17/task/document-patch
AndyButland 8806113
One more default implementation
Migaroez da1cacc
Add link to docs on endpoint swagger info
Migaroez c398646
PR review corrections
Migaroez c2b01b8
Update documentation urls
Migaroez 1cacb39
Apply suggestions from code review
Migaroez 39c266c
Removed affected variance tracking that is nog longer being used
Migaroez ba21767
Extract shared data class
Migaroez 2025951
update claude patching namespace
Migaroez 33f1ef1
Remove no longer valid xml comment
Migaroez 7e1111f
Fix unittests after refactoring patchengine.ApplyOperation(string,...…
Migaroez e8c55ad
Refactor base classes
Migaroez 93a439b
Apply suggestions from code review
Migaroez cf5043c
Optimizations and refactoring of the patcher/engine/parser
Migaroez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/Umbraco.Cms.Api.Management/Controllers/Document/PatchDocumentController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.Factories; | ||
| using Umbraco.Cms.Api.Management.OperationStatus; | ||
| using Umbraco.Cms.Api.Management.Patchers; | ||
| using Umbraco.Cms.Api.Management.ViewModels.Document; | ||
| using Umbraco.Cms.Api.Management.ViewModels.Patching; | ||
| using Umbraco.Cms.Core; | ||
| using Umbraco.Cms.Core.Models.ContentEditing; | ||
| using Umbraco.Cms.Core.Security; | ||
| using Umbraco.Cms.Core.Services; | ||
| using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.Document; | ||
|
|
||
| [ApiVersion("1.0")] | ||
| public class PatchDocumentController : PatchDocumentControllerBase | ||
| { | ||
| private readonly IContentEditingService _contentEditingService; | ||
| private readonly IDocumentPatcher _documentPatcher; | ||
| private readonly IDocumentEditingPresentationFactory _presentationFactory; | ||
| private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|
|
||
| public PatchDocumentController( | ||
| IAuthorizationService authorizationService, | ||
| IContentEditingService contentEditingService, | ||
| IDocumentPatcher documentPatcher, | ||
| IDocumentEditingPresentationFactory presentationFactory, | ||
| IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
| : base(authorizationService) | ||
| { | ||
| _contentEditingService = contentEditingService; | ||
| _documentPatcher = documentPatcher; | ||
| _presentationFactory = presentationFactory; | ||
| _backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
| } | ||
|
|
||
| [HttpPatch("{id:guid}/patch")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status422UnprocessableEntity)] | ||
| [EndpointSummary("Make partial updates to a document. For more information, see the documentation at https://docs.umbraco.com/umbraco-cms/reference/management-api/patching/document-endpoint-guide or https://docs.umbraco.com/umbraco-cms/reference/management-api/patching/document-endpoint-spec")] | ||
|
AndyButland marked this conversation as resolved.
|
||
| [Consumes("application/json-patch+json")] | ||
| public async Task<IActionResult> Patch( | ||
| CancellationToken cancellationToken, | ||
| Guid id, | ||
| PatchDocumentRequestModel requestModel) | ||
| => await HandleRequest(id, async () => | ||
| { | ||
| ContentPatchModel patchModel = _presentationFactory.MapPatchModel(requestModel); | ||
|
|
||
| // Apply PATCH operations to create an update request model | ||
| Attempt<UpdateDocumentRequestModel, ContentPatchingOperationStatus> patchResult = | ||
| await _documentPatcher.ApplyPatchAsync(id, patchModel); | ||
|
|
||
| if (patchResult.Success is false) | ||
| { | ||
| return ContentPatchingOperationStatusResult(patchResult.Status); | ||
| } | ||
|
|
||
| ContentUpdateModel contentUpdateModel = _presentationFactory.MapUpdateModel(patchResult.Result); | ||
|
|
||
| // Use the standard update method to save the patched content | ||
| Attempt<ContentUpdateResult, ContentEditingOperationStatus> updateResult = | ||
| await _contentEditingService.UpdateAsync(id, contentUpdateModel, CurrentUserKey(_backOfficeSecurityAccessor)); | ||
|
|
||
| return updateResult.Success | ||
| ? Ok() | ||
| : ContentEditingOperationStatusResult(updateResult.Status); | ||
| }); | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
src/Umbraco.Cms.Api.Management/Controllers/Document/PatchDocumentControllerBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.OperationStatus; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.Document; | ||
|
|
||
| public abstract class PatchDocumentControllerBase : UpdateDocumentControllerBase | ||
| { | ||
| protected PatchDocumentControllerBase(IAuthorizationService authorizationService) | ||
| : base(authorizationService) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Maps ContentPatchingOperationStatus to appropriate HTTP responses for PATCH operations. | ||
| /// </summary> | ||
| protected IActionResult ContentPatchingOperationStatusResult(ContentPatchingOperationStatus status) | ||
| => OperationStatusResult(status, problemDetailsBuilder => status switch | ||
| { | ||
| ContentPatchingOperationStatus.InvalidOperation => BadRequest(problemDetailsBuilder | ||
| .WithTitle("Invalid operation") | ||
| .WithDetail("One or more PATCH operations were invalid. Check operation structure, path syntax, and operation types.") | ||
| .Build()), | ||
| ContentPatchingOperationStatus.NotFound => NotFound(problemDetailsBuilder | ||
| .WithTitle("The document could not be found") | ||
| .Build()), | ||
| _ => StatusCode(StatusCodes.Status500InternalServerError, problemDetailsBuilder | ||
| .WithTitle("Unknown error") | ||
| .WithDetail("An unexpected error occurred during the PATCH operation.") | ||
| .Build()), | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.