* Bugfix: MediaCacheRefresher needs to always clear the mediaCache no matter what the publishedState is * fix: check correct permissions for deleteDocumentFromRecycleBin * Fix: ImageCropper propertyValues should not hold invalid values. * Added media delete endpoints * PR comment fix: Do not schedule cleanup if we know the file does not exist. * resolved forward merge build conflicts namespace cleanup --------- Co-authored-by: Sven Geusens <sge@umbraco.dk>
57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
using Asp.Versioning;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Umbraco.Cms.Api.Management.Security.Authorization.Media;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Security;
|
|
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.Media;
|
|
|
|
[ApiVersion("1.0")]
|
|
public class DeleteMediaController : MediaControllerBase
|
|
{
|
|
private readonly IAuthorizationService _authorizationService;
|
|
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
|
|
private readonly IMediaEditingService _mediaEditingService;
|
|
|
|
public DeleteMediaController(
|
|
IAuthorizationService authorizationService,
|
|
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
|
|
IMediaEditingService mediaEditingService)
|
|
{
|
|
_authorizationService = authorizationService;
|
|
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
|
|
_mediaEditingService = mediaEditingService;
|
|
}
|
|
|
|
[HttpDelete("{id:guid}")]
|
|
[MapToApiVersion("1.0")]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> Delete(Guid id)
|
|
{
|
|
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
|
|
User,
|
|
MediaPermissionResource.RecycleBin(),
|
|
AuthorizationPolicies.MediaPermissionByResource);
|
|
|
|
if (!authorizationResult.Succeeded)
|
|
{
|
|
return Forbidden();
|
|
}
|
|
|
|
Attempt<IMedia?, ContentEditingOperationStatus> result = await _mediaEditingService.DeleteAsync(id, CurrentUserKey(_backOfficeSecurityAccessor));
|
|
|
|
return result.Success
|
|
? Ok()
|
|
: ContentEditingOperationStatusResult(result.Status);
|
|
}
|
|
}
|