-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Content: Reintroduce create/save-and-publish as a single operation (closes #22577) #22812
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
AndyButland
merged 18 commits into
v17/dev
from
v17/improvement/save-and-publish-take-three
Jul 2, 2026
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5384ca8
Reintroduce create/save-and-publish as a single operation
kjac 8eeb100
Merge branch 'v17/dev' into v17/improvement/save-and-publish-take-three
iOvergaard d088da8
Added a truckload on tests.
Migaroez 04c715d
add default implementation
Migaroez 4027f7a
PR review fixes
Migaroez 9137359
Fix XML doc formatting.
AndyButland f976bd8
Move name length check for content in ContentService, now duplicated …
AndyButland 23f1958
Provide a more comprehensive default implementation for save and publ…
AndyButland 8a26c9d
Improved XML doc on the new SaveAndPublish method on IContentService.
AndyButland 4125fd3
Align validation on Publish and SaveAndPublish.
AndyButland 6a3ccd4
Removed region from ContentServiceTests (it's the only one, and test …
AndyButland a5ec965
Add authorization checks for create+publish and update+publish on the…
AndyButland 5801f2c
Added authorization integration tests.
AndyButland 3a86dfb
Merge branch 'v17/dev' into v17/improvement/save-and-publish-take-three
iOvergaard f8fe8b3
Merge branch 'v17/dev' into v17/improvement/save-and-publish-take-three
iOvergaard 5ed6da6
Documents: Use single-transaction create/update-and-publish endpoints…
iOvergaard ded9ac3
Merge branch 'v17/dev' into v17/improvement/save-and-publish-take-three
AndyButland dca89af
Merge branch 'v17/improvement/save-and-publish-take-three' of https:/…
AndyButland 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
88 changes: 88 additions & 0 deletions
88
src/Umbraco.Cms.Api.Management/Controllers/Document/CreateAndPublishDocumentController.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,88 @@ | ||
| 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.ViewModels.Document; | ||
| using Umbraco.Cms.Core; | ||
| using Umbraco.Cms.Core.Actions; | ||
| using Umbraco.Cms.Core.Models.ContentEditing; | ||
| using Umbraco.Cms.Core.Security; | ||
| using Umbraco.Cms.Core.Security.Authorization; | ||
| using Umbraco.Cms.Core.Services; | ||
| using Umbraco.Cms.Core.Services.OperationStatus; | ||
| using Umbraco.Cms.Web.Common.Authorization; | ||
| using Umbraco.Extensions; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.Document; | ||
|
|
||
| /// <summary> | ||
| /// API controller responsible for handling operations related to the creation of content documents in the Umbraco CMS. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class CreateAndPublishDocumentController : CreateDocumentControllerBase | ||
| { | ||
| private readonly IAuthorizationService _authorizationService; | ||
| private readonly IDocumentEditingPresentationFactory _documentEditingPresentationFactory; | ||
| private readonly IContentEditingService _contentEditingService; | ||
| private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="CreateAndPublishDocumentController"/> class. | ||
| /// </summary> | ||
| /// <param name="authorizationService">Service used to authorize access to document creation and publishing operations.</param> | ||
| /// <param name="documentEditingPresentationFactory">Factory for creating document editing presentation models.</param> | ||
| /// <param name="contentEditingService">Service responsible for content editing functionality.</param> | ||
| /// <param name="backOfficeSecurityAccessor">Accessor for back office security context.</param> | ||
| public CreateAndPublishDocumentController( | ||
| IAuthorizationService authorizationService, | ||
| IDocumentEditingPresentationFactory documentEditingPresentationFactory, | ||
| IContentEditingService contentEditingService, | ||
| IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
| : base(authorizationService) | ||
| { | ||
| _authorizationService = authorizationService; | ||
| _documentEditingPresentationFactory = documentEditingPresentationFactory; | ||
| _contentEditingService = contentEditingService; | ||
| _backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new document using the specified request model, and subsequently publishes the document in the cultures provided. | ||
| /// </summary> | ||
| /// <param name="cancellationToken">Token to monitor for cancellation requests.</param> | ||
| /// <param name="requestModel">The details of the document to create.</param> | ||
| /// <returns>An <see cref="IActionResult"/> representing the result of the operation.</returns> | ||
| [HttpPost("create-and-publish")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(StatusCodes.Status201Created)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
| [EndpointSummary("Creates and publishes a new document.")] | ||
| [EndpointDescription("Creates and publishes a new document with the configuration specified in the request model.")] | ||
| public async Task<IActionResult> Create( | ||
|
Migaroez marked this conversation as resolved.
|
||
| CancellationToken cancellationToken, | ||
| CreateAndPublishDocumentRequestModel requestModel) | ||
| => await HandleRequest(requestModel, async () => | ||
| { | ||
| // The base HandleRequest verifies the user can create under the parent. | ||
| // Creating-and-publishing additionally requires publish permission, so we check that here. | ||
| AuthorizationResult publishAuthorizationResult = await _authorizationService.AuthorizeResourceAsync( | ||
| User, | ||
| ContentPermissionResource.WithKeys(ActionPublish.ActionLetter, requestModel.Parent?.Id, requestModel.CulturesToPublish), | ||
| AuthorizationPolicies.ContentPermissionByResource); | ||
|
|
||
| if (publishAuthorizationResult.Succeeded is false) | ||
| { | ||
| return Forbidden(); | ||
| } | ||
|
|
||
| ContentCreateModel model = _documentEditingPresentationFactory.MapCreateModel(requestModel); | ||
| Attempt<ContentCreateResult, ContentEditingOperationStatus> result = | ||
| await _contentEditingService.CreateAndPublishAsync(model, requestModel.CulturesToPublish, CurrentUserKey(_backOfficeSecurityAccessor)); | ||
|
|
||
| return result.Success | ||
| ? CreatedAtId<ByKeyDocumentController>(controller => nameof(controller.ByKey), result.Result.Content!.Key) | ||
| : ContentEditingOperationStatusResult(result.Status); | ||
| }); | ||
| } | ||
90 changes: 90 additions & 0 deletions
90
src/Umbraco.Cms.Api.Management/Controllers/Document/UpdateAndPublishDocumentController.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,90 @@ | ||
| 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.ViewModels.Document; | ||
| using Umbraco.Cms.Core; | ||
| using Umbraco.Cms.Core.Actions; | ||
| using Umbraco.Cms.Core.Models.ContentEditing; | ||
| using Umbraco.Cms.Core.Security; | ||
| using Umbraco.Cms.Core.Security.Authorization; | ||
| using Umbraco.Cms.Core.Services; | ||
| using Umbraco.Cms.Core.Services.OperationStatus; | ||
| using Umbraco.Cms.Web.Common.Authorization; | ||
| using Umbraco.Extensions; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.Document; | ||
|
|
||
| /// <summary> | ||
| /// Controller responsible for handling update-and-publish operations on documents in the management API. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class UpdateAndPublishDocumentController : UpdateDocumentControllerBase | ||
| { | ||
| private readonly IAuthorizationService _authorizationService; | ||
| private readonly IContentEditingService _contentEditingService; | ||
| private readonly IDocumentEditingPresentationFactory _documentEditingPresentationFactory; | ||
| private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="UpdateAndPublishDocumentController"/> class. | ||
| /// </summary> | ||
| /// <param name="authorizationService">Service for verifying user permissions to update and publish.</param> | ||
| /// <param name="contentEditingService">Service for managing content updates.</param> | ||
| /// <param name="documentEditingPresentationFactory">Factory for creating document editing presentation models.</param> | ||
| /// <param name="backOfficeSecurityAccessor">Accessor for the back office user security context.</param> | ||
| public UpdateAndPublishDocumentController( | ||
| IAuthorizationService authorizationService, | ||
| IContentEditingService contentEditingService, | ||
| IDocumentEditingPresentationFactory documentEditingPresentationFactory, | ||
| IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
| : base(authorizationService) | ||
| { | ||
| _authorizationService = authorizationService; | ||
| _contentEditingService = contentEditingService; | ||
| _documentEditingPresentationFactory = documentEditingPresentationFactory; | ||
| _backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Updates the specified document with new details provided in the request model, and subsequently publishes the document in the cultures provided. | ||
| /// </summary> | ||
| /// <param name="cancellationToken">A token to monitor for cancellation requests.</param> | ||
| /// <param name="id">The unique identifier of the document to update.</param> | ||
| /// <param name="requestModel">The model containing the updated document details.</param> | ||
| /// <returns>An <see cref="IActionResult"/> representing the outcome of the update operation.</returns> | ||
| [HttpPut("{id:guid}/update-and-publish")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
| [EndpointSummary("Updates and publishes a document.")] | ||
| [EndpointDescription("Updates and publishes a document identified by the provided Id with the details from the request model.")] | ||
| public async Task<IActionResult> Update( | ||
| CancellationToken cancellationToken, | ||
| Guid id, | ||
| UpdateAndPublishDocumentRequestModel requestModel) | ||
| => await HandleRequest(id, requestModel, async () => | ||
| { | ||
| // The base HandleRequest verifies the user can update the document. | ||
| // Updating-and-publishing additionally requires publish permission, so we check that here. | ||
| AuthorizationResult publishAuthorizationResult = await _authorizationService.AuthorizeResourceAsync( | ||
| User, | ||
| ContentPermissionResource.WithKeys(ActionPublish.ActionLetter, id, requestModel.CulturesToPublish), | ||
| AuthorizationPolicies.ContentPermissionByResource); | ||
|
|
||
| if (publishAuthorizationResult.Succeeded is false) | ||
| { | ||
| return Forbidden(); | ||
| } | ||
|
|
||
| ContentUpdateModel model = _documentEditingPresentationFactory.MapUpdateModel(requestModel); | ||
| Guid currentUserKey = CurrentUserKey(_backOfficeSecurityAccessor); | ||
| Attempt<ContentUpdateResult, ContentEditingOperationStatus> result = await _contentEditingService.UpdateAndPublishAsync(id, model, requestModel.CulturesToPublish, currentUserKey); | ||
|
|
||
| return result.Success | ||
| ? Ok() | ||
| : ContentEditingOperationStatusResult(result.Status); | ||
| }); | ||
| } |
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.