2023-05-09 08:38:07 +02:00
|
|
|
|
using Asp.Versioning;
|
2023-12-11 08:25:29 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-05-09 08:38:07 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-12-11 08:25:29 +01:00
|
|
|
|
using Umbraco.Cms.Api.Management.Security.Authorization.Content;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
using Umbraco.Cms.Core;
|
2023-12-11 08:25:29 +01:00
|
|
|
|
using Umbraco.Cms.Core.Actions;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
|
using Umbraco.Cms.Core.Security;
|
2024-02-29 09:41:56 +00:00
|
|
|
|
using Umbraco.Cms.Core.Security.Authorization;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
2023-12-11 08:25:29 +01:00
|
|
|
|
using Umbraco.Cms.Web.Common.Authorization;
|
|
|
|
|
|
using Umbraco.Extensions;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Document;
|
|
|
|
|
|
|
2023-05-09 08:38:07 +02:00
|
|
|
|
[ApiVersion("1.0")]
|
2023-02-20 11:08:22 +01:00
|
|
|
|
public class MoveToRecycleBinDocumentController : DocumentControllerBase
|
|
|
|
|
|
{
|
2023-12-11 08:25:29 +01:00
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
private readonly IContentEditingService _contentEditingService;
|
|
|
|
|
|
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
|
|
|
|
|
|
|
2023-12-11 08:25:29 +01:00
|
|
|
|
public MoveToRecycleBinDocumentController(
|
|
|
|
|
|
IAuthorizationService authorizationService,
|
|
|
|
|
|
IContentEditingService contentEditingService,
|
|
|
|
|
|
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
|
2023-02-20 11:08:22 +01:00
|
|
|
|
{
|
2023-12-11 08:25:29 +01:00
|
|
|
|
_authorizationService = authorizationService;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
_contentEditingService = contentEditingService;
|
|
|
|
|
|
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-14 10:07:08 +02:00
|
|
|
|
[HttpPut("{id:guid}/move-to-recycle-bin")]
|
2023-02-20 11:08:22 +01:00
|
|
|
|
[MapToApiVersion("1.0")]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2023-09-14 10:07:08 +02:00
|
|
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
2023-08-04 10:51:20 +02:00
|
|
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
2024-04-09 08:18:45 +02:00
|
|
|
|
public async Task<IActionResult> MoveToRecycleBin(CancellationToken cancellationToken, Guid id)
|
2023-02-20 11:08:22 +01:00
|
|
|
|
{
|
2023-12-11 08:25:29 +01:00
|
|
|
|
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
|
|
|
|
|
|
User,
|
|
|
|
|
|
ContentPermissionResource.WithKeys(ActionDelete.ActionLetter, id),
|
|
|
|
|
|
AuthorizationPolicies.ContentPermissionByResource);
|
|
|
|
|
|
|
|
|
|
|
|
if (!authorizationResult.Succeeded)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Forbidden();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-04 13:20:29 +02:00
|
|
|
|
Attempt<IContent?, ContentEditingOperationStatus> result = await _contentEditingService.MoveToRecycleBinAsync(id, CurrentUserKey(_backOfficeSecurityAccessor));
|
2023-02-20 11:08:22 +01:00
|
|
|
|
return result.Success
|
|
|
|
|
|
? Ok()
|
|
|
|
|
|
: ContentEditingOperationStatusResult(result.Status);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|