2023-07-05 14:56:51 +02:00
|
|
|
|
using Asp.Versioning;
|
2023-12-11 08:25:29 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-07-05 14:56:51 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-12-11 08:25:29 +01:00
|
|
|
|
using Umbraco.Cms.Api.Management.Security.Authorization.Content;
|
2024-01-29 12:58:03 +01:00
|
|
|
|
using Umbraco.Cms.Core;
|
2023-12-11 08:25:29 +01:00
|
|
|
|
using Umbraco.Cms.Core.Actions;
|
2023-07-05 14:56:51 +02:00
|
|
|
|
using Umbraco.Cms.Core.Services;
|
2024-01-29 12:58:03 +01:00
|
|
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
2023-12-11 08:25:29 +01:00
|
|
|
|
using Umbraco.Cms.Web.Common.Authorization;
|
|
|
|
|
|
using Umbraco.Extensions;
|
2023-07-05 14:56:51 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Document;
|
|
|
|
|
|
|
2023-11-29 09:23:23 +01:00
|
|
|
|
[ApiVersion("1.0")]
|
2023-07-05 14:56:51 +02:00
|
|
|
|
public class DeletePublicAccessDocumentController : DocumentControllerBase
|
|
|
|
|
|
{
|
2023-12-11 08:25:29 +01:00
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
2023-07-05 14:56:51 +02:00
|
|
|
|
private readonly IPublicAccessService _publicAccessService;
|
|
|
|
|
|
|
2023-12-11 08:25:29 +01:00
|
|
|
|
public DeletePublicAccessDocumentController(IAuthorizationService authorizationService, IPublicAccessService publicAccessService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_authorizationService = authorizationService;
|
|
|
|
|
|
_publicAccessService = publicAccessService;
|
|
|
|
|
|
}
|
2023-07-05 14:56:51 +02:00
|
|
|
|
|
|
|
|
|
|
[MapToApiVersion("1.0")]
|
|
|
|
|
|
[HttpDelete("{id:guid}/public-access")]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2023-08-04 10:51:20 +02:00
|
|
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
2023-07-05 14:56:51 +02:00
|
|
|
|
public async Task<IActionResult> Delete(Guid id)
|
|
|
|
|
|
{
|
2023-12-11 08:25:29 +01:00
|
|
|
|
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
|
|
|
|
|
|
User,
|
|
|
|
|
|
ContentPermissionResource.WithKeys(ActionProtect.ActionLetter, id),
|
|
|
|
|
|
AuthorizationPolicies.ContentPermissionByResource);
|
|
|
|
|
|
|
|
|
|
|
|
if (!authorizationResult.Succeeded)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Forbidden();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-29 12:58:03 +01:00
|
|
|
|
Attempt<PublicAccessOperationStatus> attempt = await _publicAccessService.DeleteAsync(id);
|
2023-07-05 14:56:51 +02:00
|
|
|
|
|
2024-01-29 12:58:03 +01:00
|
|
|
|
return attempt.Success ? Ok() : PublicAccessOperationStatusResult(attempt.Result);
|
2023-07-05 14:56:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|