From 917c89cde7825ea92bbcc0f1535b7fd00e7b0754 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> Date: Tue, 29 Jun 2021 11:46:07 +0200 Subject: [PATCH] Ability to configure a remote URL for displaying different content on the content dashboard (#10257) * Enabling configuration of remote URL for fetching content on the content dashboard and adding additional params indicating whether solution is running on Umbraco Cloud * Determining if Umbraco is running on Umbraco Cloud by checking whether Umbraco.Deploy.Cloud.dll is present and making its value more accessible for other contexts. Passing a hosting parameter as string instead of boolean * Changing from Unknown to OnPremises * Updated content dashboard to use hard-coded URL but path derived from configuration. Co-authored-by: Andy Butland --- src/Umbraco.Core/Constants-AppSettings.cs | 7 ++++++- .../Dashboards/ContentDashboardSettings.cs | 10 ++++++++++ .../Dashboards/IContentDashboardSettings.cs | 6 ++++++ src/Umbraco.Web.UI/web.Template.config | 1 + .../Editors/DashboardController.cs | 19 ++++++++++++++++--- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Core/Constants-AppSettings.cs b/src/Umbraco.Core/Constants-AppSettings.cs index 1f096ab9f9..99ea26b4d6 100644 --- a/src/Umbraco.Core/Constants-AppSettings.cs +++ b/src/Umbraco.Core/Constants-AppSettings.cs @@ -109,12 +109,17 @@ namespace Umbraco.Core /// A true or false indicating whether umbraco should force a secure (https) connection to the backoffice. /// public const string UseHttps = "Umbraco.Core.UseHttps"; - + /// /// A true/false value indicating whether the content dashboard should be visible for all user groups. /// public const string AllowContentDashboardAccessToAllUsers = "Umbraco.Core.AllowContentDashboardAccessToAllUsers"; + /// + /// The path to use when constructing the URL for retrieving data for the content dashboard. + /// + public const string ContentDashboardPath = "Umbraco.Core.ContentDashboardPath"; + /// /// TODO: FILL ME IN /// diff --git a/src/Umbraco.Core/Dashboards/ContentDashboardSettings.cs b/src/Umbraco.Core/Dashboards/ContentDashboardSettings.cs index f8fb5c7b06..b370f93eca 100644 --- a/src/Umbraco.Core/Dashboards/ContentDashboardSettings.cs +++ b/src/Umbraco.Core/Dashboards/ContentDashboardSettings.cs @@ -4,6 +4,7 @@ namespace Umbraco.Core.Dashboards { public class ContentDashboardSettings: IContentDashboardSettings { + private const string DefaultContentDashboardPath = "cms"; /// /// Gets a value indicating whether the content dashboard should be available to all users. @@ -20,5 +21,14 @@ namespace Umbraco.Core.Dashboards return value; } } + + /// + /// Gets the path to use when constructing the URL for retrieving data for the content dashboard. + /// + /// The URL path. + public string ContentDashboardPath => + ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.ContentDashboardPath) + ? ConfigurationManager.AppSettings[Constants.AppSettings.ContentDashboardPath] + : DefaultContentDashboardPath; } } diff --git a/src/Umbraco.Core/Dashboards/IContentDashboardSettings.cs b/src/Umbraco.Core/Dashboards/IContentDashboardSettings.cs index 862a28b90e..f5c4e3da78 100644 --- a/src/Umbraco.Core/Dashboards/IContentDashboardSettings.cs +++ b/src/Umbraco.Core/Dashboards/IContentDashboardSettings.cs @@ -10,5 +10,11 @@ /// and the default access rules for that dashboard will be in use. /// bool AllowContentDashboardAccessToAllUsers { get; } + + /// + /// Gets the path to use when constructing the URL for retrieving data for the content dashboard. + /// + /// The URL path. + string ContentDashboardPath { get; } } } diff --git a/src/Umbraco.Web.UI/web.Template.config b/src/Umbraco.Web.UI/web.Template.config index 8c4b421839..c6b1eb686c 100644 --- a/src/Umbraco.Web.UI/web.Template.config +++ b/src/Umbraco.Web.UI/web.Template.config @@ -38,6 +38,7 @@ + diff --git a/src/Umbraco.Web/Editors/DashboardController.cs b/src/Umbraco.Web/Editors/DashboardController.cs index 97db8818f2..aa9691e3dd 100644 --- a/src/Umbraco.Web/Editors/DashboardController.cs +++ b/src/Umbraco.Web/Editors/DashboardController.cs @@ -17,6 +17,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Services; using Umbraco.Core.Dashboards; +using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Web.Services; @@ -32,14 +33,19 @@ namespace Umbraco.Web.Editors public class DashboardController : UmbracoApiController { private readonly IDashboardService _dashboardService; + private readonly IContentDashboardSettings _dashboardSettings; /// /// Initializes a new instance of the with all its dependencies. /// - public DashboardController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, IDashboardService dashboardService, UmbracoHelper umbracoHelper) + public DashboardController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, + ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, + IRuntimeState runtimeState, IDashboardService dashboardService, UmbracoHelper umbracoHelper, + IContentDashboardSettings dashboardSettings) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper) { _dashboardService = dashboardService; + _dashboardSettings = dashboardSettings; } //we have just one instance of HttpClient shared for the entire application @@ -47,7 +53,7 @@ namespace Umbraco.Web.Editors //we have baseurl as a param to make previewing easier, so we can test with a dev domain from client side [ValidateAngularAntiForgeryToken] - public async Task GetRemoteDashboardContent(string section, string baseUrl = "https://dashboard.umbraco.org/") + public async Task GetRemoteDashboardContent(string section, string baseUrl = "https://dashboard.umbraco.com/") { var user = Security.CurrentUser; var allowedSections = string.Join(",", user.AllowedSections); @@ -55,7 +61,14 @@ namespace Umbraco.Web.Editors var version = UmbracoVersion.SemanticVersion.ToSemanticString(); var isAdmin = user.IsAdmin(); - var url = string.Format(baseUrl + "{0}?section={0}&allowed={1}&lang={2}&version={3}&admin={4}", section, allowedSections, language, version, isAdmin); + var url = string.Format("{0}{1}?section={2}&allowed={3}&lang={4}&version={5}&admin={6}", + baseUrl, + _dashboardSettings.ContentDashboardPath, + section, + allowedSections, + language, + version, + isAdmin); var key = "umbraco-dynamic-dashboard-" + language + allowedSections.Replace(",", "-") + section; var content = AppCaches.RuntimeCache.GetCacheItem(key);