2024-05-01 12:07:06 +02:00
|
|
|
|
using Asp.Versioning;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
|
|
|
|
|
|
using Umbraco.Cms.Api.Management.Factories;
|
|
|
|
|
|
using Umbraco.Cms.Api.Management.ViewModels.AuditLog;
|
|
|
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Document;
|
|
|
|
|
|
|
|
|
|
|
|
[ApiVersion("1.0")]
|
|
|
|
|
|
public class GetAuditLogDocumentController : DocumentControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
|
|
|
|
|
private readonly IAuditService _auditService;
|
|
|
|
|
|
private readonly IAuditLogPresentationFactory _auditLogPresentationFactory;
|
|
|
|
|
|
|
|
|
|
|
|
public GetAuditLogDocumentController(
|
|
|
|
|
|
IAuthorizationService authorizationService,
|
|
|
|
|
|
IAuditService auditService,
|
|
|
|
|
|
IAuditLogPresentationFactory auditLogPresentationFactory)
|
|
|
|
|
|
{
|
|
|
|
|
|
_authorizationService = authorizationService;
|
|
|
|
|
|
_auditService = auditService;
|
|
|
|
|
|
_auditLogPresentationFactory = auditLogPresentationFactory;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[MapToApiVersion("1.0")]
|
|
|
|
|
|
[HttpGet("{id:guid}/audit-log")]
|
|
|
|
|
|
[ProducesResponseType(typeof(PagedViewModel<AuditLogResponseModel>), StatusCodes.Status200OK)]
|
2024-05-07 08:07:20 +02:00
|
|
|
|
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTimeOffset? sinceDate = null, int skip = 0, int take = 100)
|
2024-05-01 12:07:06 +02:00
|
|
|
|
{
|
|
|
|
|
|
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
|
|
|
|
|
|
User,
|
2024-08-14 10:03:35 +02:00
|
|
|
|
ContentPermissionResource.WithKeys(ActionBrowse.ActionLetter, id),
|
2024-05-01 12:07:06 +02:00
|
|
|
|
AuthorizationPolicies.ContentPermissionByResource);
|
|
|
|
|
|
|
|
|
|
|
|
if (!authorizationResult.Succeeded)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Forbidden();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PagedModel<IAuditItem> result = await _auditService.GetItemsByKeyAsync(id, UmbracoObjectTypes.Document, skip, take, orderDirection, sinceDate);
|
|
|
|
|
|
IEnumerable<AuditLogResponseModel> mapped = _auditLogPresentationFactory.CreateAuditLogViewModel(result.Items);
|
|
|
|
|
|
var viewModel = new PagedViewModel<AuditLogResponseModel>
|
|
|
|
|
|
{
|
|
|
|
|
|
Total = result.Total,
|
|
|
|
|
|
Items = mapped,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(viewModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|