Fix up for V9
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Web.Common.Attributes;
|
||||
using Umbraco.Core.Help;
|
||||
using Umbraco.Cms.Web.Common.DependencyInjection;
|
||||
using Constants = Umbraco.Cms.Core.Constants;
|
||||
|
||||
namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
@@ -14,21 +20,35 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
public class HelpController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
private readonly ILogger<HelpController> _logger;
|
||||
private readonly IHelpPageSettings _helpPageSettings;
|
||||
private readonly HelpPageSettings _helpPageSettings;
|
||||
|
||||
public HelpController(ILogger<HelpController> logger,
|
||||
IHelpPageSettings helpPageSettings)
|
||||
[Obsolete("Use constructor that takes IOptions<HelpPageSettings>")]
|
||||
public HelpController(ILogger<HelpController> logger)
|
||||
: this(logger, StaticServiceProvider.Instance.GetRequiredService<IOptions<HelpPageSettings>>())
|
||||
{
|
||||
}
|
||||
|
||||
[ActivatorUtilitiesConstructor]
|
||||
public HelpController(
|
||||
ILogger<HelpController> logger,
|
||||
IOptions<HelpPageSettings> helpPageSettings)
|
||||
{
|
||||
_logger = logger;
|
||||
_helpPageSettings = helpPageSettings.Value;
|
||||
}
|
||||
|
||||
private static HttpClient _httpClient;
|
||||
|
||||
public async Task<List<HelpPage>> GetContextHelpForPage(string section, string tree, string baseUrl = "https://our.umbraco.com")
|
||||
{
|
||||
if (IsAllowedUrl(baseUrl) is false)
|
||||
{
|
||||
Logger.Error<HelpController>($"The following URL is not listed in the allowlist for HelpPage in web.config: {baseUrl}");
|
||||
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "HelpPage source not permitted"));
|
||||
_logger.LogError($"The following URL is not listed in the allowlist for HelpPage in web.config: {baseUrl}");
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
|
||||
// Ideally we'd want to return a BadRequestResult here,
|
||||
// however, since we're not returning ActionResult this is not possible and changing it would be a breaking change.
|
||||
return new List<HelpPage>();
|
||||
}
|
||||
|
||||
var url = string.Format(baseUrl + "/Umbraco/Documentation/Lessons/GetContextHelpDocs?sectionAlias={0}&treeAlias={1}", section, tree);
|
||||
@@ -56,7 +76,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
|
||||
private bool IsAllowedUrl(string url)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_helpPageSettings.HelpPageUrlAllowList) ||
|
||||
if (_helpPageSettings.HelpPageUrlAllowList is null ||
|
||||
_helpPageSettings.HelpPageUrlAllowList.Contains(url))
|
||||
{
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user