-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publishing in the Management API (#14774)
* make CoreScopeProvider available for derived classes * Create publish controller * Add publish functionality * Remove unneeded using * Implement publish for multiple cultures * support multiple cultures in controler * Dont validate properties * Refactor to use PublishingOperationStatus * refactor to use proper publish async methods * Refactor publish logic into own service * Commit some demo code * Add notes about what errors can happen when publishing * Rework ContentPublishingService and introduce explicit Publish and PublishBranch methods in ContentService * Fix merge * Allow the publishing strategy to do its job * Improved check for unsaved changes * Make the old content controller work (as best possible) * Remove SaveAndPublish (SaveAndPublishBranch) from all tests * Proper guards for invalid cultures when publishing * Fix edge cases for property validation and content unpublishing + add unpublishing to ContentPublishingService * Clear out a few TODOs - we'll accept the behavior for now * Unpublish controller * Fix merge * Fix branch publish notifications * Added extra test for publishing unpublished cultures and added FIXME comments for when we fix the state of published cultures in content --------- Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Co-authored-by: Zeegaan <nge@umbraco.dk>
- Loading branch information
1 parent
42dd2da
commit 012b43a
Showing
41 changed files
with
2,012 additions
and
562 deletions.
There are no files selected for viewing
This file contains 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
38 changes: 38 additions & 0 deletions
38
src/Umbraco.Cms.Api.Management/Controllers/Document/PublishDocumentController.cs
This file contains 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,38 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.Document; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Document; | ||
|
||
public class PublishDocumentController : DocumentControllerBase | ||
{ | ||
private readonly IContentPublishingService _contentPublishingService; | ||
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|
||
public PublishDocumentController(IContentPublishingService contentPublishingService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
{ | ||
_contentPublishingService = contentPublishingService; | ||
_backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
} | ||
|
||
[HttpPut("{id:guid}/publish")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> Publish(Guid id, PublishDocumentRequestModel requestModel) | ||
{ | ||
Attempt<ContentPublishingOperationStatus> attempt = await _contentPublishingService.PublishAsync( | ||
id, | ||
requestModel.Cultures, | ||
CurrentUserKey(_backOfficeSecurityAccessor)); | ||
return attempt.Success | ||
? Ok() | ||
: ContentPublishingOperationStatusResult(attempt.Result); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...braco.Cms.Api.Management/Controllers/Document/PublishDocumentWithDescendantsController.cs
This file contains 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,43 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.Document; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Document; | ||
|
||
public class PublishDocumentWithDescendantsController : DocumentControllerBase | ||
{ | ||
private readonly IContentPublishingService _contentPublishingService; | ||
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|
||
public PublishDocumentWithDescendantsController(IContentPublishingService contentPublishingService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
{ | ||
_contentPublishingService = contentPublishingService; | ||
_backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
} | ||
|
||
[HttpPut("{id:guid}/publish-with-descendants")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> PublishWithDescendants(Guid id, PublishDocumentWithDescendantsRequestModel requestModel) | ||
{ | ||
Attempt<IDictionary<Guid, ContentPublishingOperationStatus>> attempt = await _contentPublishingService.PublishBranchAsync( | ||
id, | ||
requestModel.Cultures, | ||
requestModel.IncludeUnpublishedDescendants, | ||
CurrentUserKey(_backOfficeSecurityAccessor)); | ||
|
||
// FIXME: when we get to implement proper validation handling, this should return a collection of status codes by key (based on attempt.Result) | ||
return attempt.Success | ||
? Ok() | ||
: ContentPublishingOperationStatusResult( | ||
attempt.Result?.Values.FirstOrDefault(r => r is not ContentPublishingOperationStatus.Success) | ||
?? throw new NotSupportedException("The attempt was not successful - at least one result value should be unsuccessful too")); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Umbraco.Cms.Api.Management/Controllers/Document/UnpublishDocumentController.cs
This file contains 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,38 @@ | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Umbraco.Cms.Api.Management.ViewModels.Document; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
||
namespace Umbraco.Cms.Api.Management.Controllers.Document; | ||
|
||
public class UnpublishDocumentController : DocumentControllerBase | ||
{ | ||
private readonly IContentPublishingService _contentPublishingService; | ||
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|
||
public UnpublishDocumentController(IContentPublishingService contentPublishingService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
{ | ||
_contentPublishingService = contentPublishingService; | ||
_backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
} | ||
|
||
[HttpPut("{id:guid}/unpublish")] | ||
[MapToApiVersion("1.0")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
public async Task<IActionResult> Unpublish(Guid id, UnpublishDocumentRequestModel requestModel) | ||
{ | ||
Attempt<ContentPublishingOperationStatus> attempt = await _contentPublishingService.UnpublishAsync( | ||
id, | ||
requestModel.Culture, | ||
CurrentUserKey(_backOfficeSecurityAccessor)); | ||
return attempt.Success | ||
? Ok() | ||
: ContentPublishingOperationStatusResult(attempt.Result); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Umbraco.Cms.Api.Management/ViewModels/Document/PublishDocumentRequestModel.cs
This file contains 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,6 @@ | ||
namespace Umbraco.Cms.Api.Management.ViewModels.Document; | ||
|
||
public class PublishDocumentRequestModel | ||
{ | ||
public required IEnumerable<string> Cultures { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
...raco.Cms.Api.Management/ViewModels/Document/PublishDocumentWithDescendantsRequestModel.cs
This file contains 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,6 @@ | ||
namespace Umbraco.Cms.Api.Management.ViewModels.Document; | ||
|
||
public class PublishDocumentWithDescendantsRequestModel : PublishDocumentRequestModel | ||
{ | ||
public bool IncludeUnpublishedDescendants { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Umbraco.Cms.Api.Management/ViewModels/Document/UnpublishDocumentRequestModel.cs
This file contains 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,6 @@ | ||
namespace Umbraco.Cms.Api.Management.ViewModels.Document; | ||
|
||
public class UnpublishDocumentRequestModel | ||
{ | ||
public string? Culture { get; set; } | ||
} |
This file contains 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 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.