Refactor content updates to shift responsibility downwards (#15807)

This commit is contained in:
Kenn Jacobsen
2024-03-01 10:45:19 +01:00
committed by GitHub
parent 33c1d4e1fb
commit d8659ca53e
18 changed files with 85 additions and 93 deletions

View File

@@ -1,11 +1,8 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Security.Authorization.Content;
using Umbraco.Cms.Api.Management.ViewModels.Document;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security.Authorization;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.Common.Authorization;
using Umbraco.Extensions;
@@ -14,15 +11,11 @@ namespace Umbraco.Cms.Api.Management.Controllers.Document;
public abstract class UpdateDocumentControllerBase : DocumentControllerBase
{
private readonly IAuthorizationService _authorizationService;
private readonly IContentEditingService _contentEditingService;
protected UpdateDocumentControllerBase(IAuthorizationService authorizationService, IContentEditingService contentEditingService)
{
_authorizationService = authorizationService;
_contentEditingService = contentEditingService;
}
protected UpdateDocumentControllerBase(IAuthorizationService authorizationService)
=> _authorizationService = authorizationService;
protected async Task<IActionResult> HandleRequest(Guid id, UpdateDocumentRequestModel requestModel, Func<IContent, Task<IActionResult>> authorizedHandler)
protected async Task<IActionResult> HandleRequest(Guid id, UpdateDocumentRequestModel requestModel, Func<Task<IActionResult>> authorizedHandler)
{
IEnumerable<string> cultures = requestModel.Variants
.Where(v => v.Culture is not null)
@@ -37,12 +30,6 @@ public abstract class UpdateDocumentControllerBase : DocumentControllerBase
return Forbidden();
}
IContent? content = await _contentEditingService.GetAsync(id);
if (content is null)
{
return DocumentNotFound();
}
return await authorizedHandler(content);
return await authorizedHandler();
}
}