Moved logic from all around into the repository

This commit is contained in:
Bjarke Berg
2023-02-20 14:42:12 +01:00
parent 3587172e02
commit 0d29ad9333
4 changed files with 26 additions and 21 deletions

View File

@@ -20,8 +20,10 @@
@inject IProfilerHtml profilerHtml
@inject IIconService IconService
@inject IBackOfficeExternalLoginProviders externalLogins
@inject IWebProfilerService WebProfilerService
@{
bool.TryParse(Context.Request.Query["umbDebug"], out bool isDebug);
var webProfilingStatus = await WebProfilerService.GetStatus();
var isDebug = (webProfilingStatus.Success && webProfilingStatus.Result) ? true : false;
var backOfficePath = globalSettings.Value.GetBackOfficePath(hostingEnvironment);
}

View File

@@ -130,18 +130,7 @@ public class WebProfiler : IProfiler
return false;
}
if (bool.TryParse(request.Query["umbDebug"], out var umbDebug))
{
return umbDebug;
}
if (bool.TryParse(request.Headers["X-UMB-DEBUG"], out var xUmbDebug))
{
return xUmbDebug;
}
var webProfilerService = _httpContextAccessor.HttpContext?.RequestServices?.GetService<IWebProfilerService>();
IWebProfilerService? webProfilerService = _httpContextAccessor.HttpContext?.RequestServices?.GetService<IWebProfilerService>();
if (webProfilerService is not null)
{

View File

@@ -6,8 +6,11 @@ namespace Umbraco.Cms.Web.Common.Repositories;
internal class WebProfilerRepository : IWebProfilerRepository
{
private readonly IHttpContextAccessor _httpContextAccessor;
private const string CookieName = "UMB-DEBUG";
private const string HeaderName = "X-UMB-DEBUG";
private const string QueryName = "umbDebug";
private readonly IHttpContextAccessor _httpContextAccessor;
public WebProfilerRepository(IHttpContextAccessor httpContextAccessor)
{
@@ -26,5 +29,20 @@ internal class WebProfilerRepository : IWebProfilerRepository
}
}
public bool GetStatus(int userId) => _httpContextAccessor.GetRequiredHttpContext().Request.Cookies.ContainsKey(CookieName);
public bool GetStatus(int userId)
{
var request = _httpContextAccessor.GetRequiredHttpContext().Request;
if (bool.TryParse(request.Query[QueryName], out var umbDebug))
{
return umbDebug;
}
if (bool.TryParse(request.Headers[HeaderName], out var xUmbDebug))
{
return xUmbDebug;
}
return request.Cookies.ContainsKey(CookieName);
}
}

View File

@@ -5,6 +5,7 @@ using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Core.Web;
using Umbraco.Extensions;
@@ -134,12 +135,7 @@ _cleanedUmbracoUrl ??= _uriUtility.UriToUmbraco(OriginalRequestUrl);
return true;
}
if(string.IsNullOrEmpty(_httpContextAccessor.HttpContext?.GetRequestValue("umbdebug")) == false)
{
return true;
}
var webProfilerStatusAttempt = _webProfilerService.GetStatus().GetAwaiter().GetResult();
Attempt<bool, WebProfilerOperationStatus> webProfilerStatusAttempt = _webProfilerService.GetStatus().GetAwaiter().GetResult();
if (webProfilerStatusAttempt.Success)
{