Add status endpoint

This commit is contained in:
Nikolaj
2022-11-28 14:41:15 +01:00
parent af6b8fc5cb
commit b594ad8ccf
3 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.ManagementApi.ViewModels.RedirectManagement;
using Umbraco.Extensions;
namespace Umbraco.Cms.ManagementApi.Controllers.RedirectManagement;
public class GetEnabledController : RedirectManagementBaseController
{
private readonly IOptionsMonitor<WebRoutingSettings> _webRoutingSettings;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
public GetEnabledController(
IOptionsMonitor<WebRoutingSettings> webRoutingSettings,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
{
_webRoutingSettings = webRoutingSettings;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
}
[HttpGet("status")]
public Task<ActionResult<RedirectStatusViewModel>> GetStatus() =>
Task.FromResult<ActionResult<RedirectStatusViewModel>>(new RedirectStatusViewModel
{
Enabled = _webRoutingSettings.CurrentValue.DisableRedirectUrlTracking is false,
UserIsAdmin = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.IsAdmin() ?? false
});
}

View File

@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Umbraco.New.Cms.Web.Common.Routing;
namespace Umbraco.Cms.ManagementApi.Controllers.RedirectManagement;
[ApiController]
[VersionedApiBackOfficeRoute("redirect-management")]
[ApiExplorerSettings(GroupName = "Redirect Management")]
[ApiVersion("1.0")]
public class RedirectManagementBaseController
{
}

View File

@@ -0,0 +1,8 @@
namespace Umbraco.Cms.ManagementApi.ViewModels.RedirectManagement;
public class RedirectStatusViewModel
{
public bool Enabled { get; set; }
public bool UserIsAdmin { get; set; }
}