Gets sln building, removes old legacy settings, removes ascx dashboard support

This commit is contained in:
Shannon
2018-12-03 16:14:49 +11:00
parent 953f37f2db
commit 162b90194d
25 changed files with 172 additions and 457 deletions

View File

@@ -3,8 +3,6 @@ using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Mvc;
using System.Linq;
using Umbraco.Core.IO;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
using System.Net.Http;
@@ -27,6 +25,13 @@ namespace Umbraco.Web.Editors
[WebApi.UmbracoAuthorize]
public class DashboardController : UmbracoApiController
{
private readonly DashboardHelper _dashboardHelper;
public DashboardController(DashboardHelper dashboardHelper)
{
_dashboardHelper = dashboardHelper;
}
//we have just one instance of HttpClient shared for the entire application
private static readonly HttpClient HttpClient = new HttpClient();
//we have baseurl as a param to make previewing easier, so we can test with a dev domain from client side
@@ -119,8 +124,7 @@ namespace Umbraco.Web.Editors
[ValidateAngularAntiForgeryToken]
public IEnumerable<Tab<DashboardControl>> GetDashboard(string section)
{
var dashboardHelper = new DashboardHelper(ApplicationContext);
return dashboardHelper.GetDashboard(section, Security.CurrentUser);
return _dashboardHelper.GetDashboard(section, Security.CurrentUser);
}
}
}

View File

@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration.Dashboard;
using Umbraco.Core.IO;
using Umbraco.Core.Manifest;
using Umbraco.Core.Models.Membership;
@@ -13,14 +13,17 @@ using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Editors
{
internal class DashboardHelper
public class DashboardHelper
{
private readonly ApplicationContext _appContext;
private readonly ISectionService _sectionService;
private readonly IDashboardSection _dashboardSection;
private readonly ManifestParser _manifestParser;
public DashboardHelper(ApplicationContext appContext)
public DashboardHelper(ISectionService sectionService, IDashboardSection dashboardSection, ManifestParser manifestParser)
{
if (appContext == null) throw new ArgumentNullException("appContext");
_appContext = appContext;
_sectionService = sectionService ?? throw new ArgumentNullException(nameof(sectionService));
_dashboardSection = dashboardSection;
_manifestParser = manifestParser;
}
/// <summary>
@@ -31,7 +34,7 @@ namespace Umbraco.Web.Editors
public IDictionary<string, IEnumerable<Tab<DashboardControl>>> GetDashboards(IUser currentUser)
{
var result = new Dictionary<string, IEnumerable<Tab<DashboardControl>>>();
foreach (var section in _appContext.Services.SectionService.GetSections())
foreach (var section in _sectionService.GetSections())
{
result[section.Alias] = GetDashboard(section.Alias, currentUser);
}
@@ -87,24 +90,24 @@ namespace Umbraco.Web.Editors
//disable packages section dashboard
if (section == "packages") return tabs;
foreach (var dashboardSection in UmbracoConfig.For.DashboardSettings().Sections.Where(x => x.Areas.Contains(section)))
foreach (var dashboardSection in _dashboardSection.Sections.Where(x => x.Areas.Contains(section)))
{
//we need to validate access to this section
if (DashboardSecurity.AuthorizeAccess(dashboardSection, currentUser, _appContext.Services.SectionService) == false)
if (DashboardSecurity.AuthorizeAccess(dashboardSection, currentUser, _sectionService) == false)
continue;
//User is authorized
foreach (var tab in dashboardSection.Tabs)
{
//we need to validate access to this tab
if (DashboardSecurity.AuthorizeAccess(tab, currentUser, _appContext.Services.SectionService) == false)
if (DashboardSecurity.AuthorizeAccess(tab, currentUser, _sectionService) == false)
continue;
var dashboardControls = new List<DashboardControl>();
foreach (var control in tab.Controls)
{
if (DashboardSecurity.AuthorizeAccess(control, currentUser, _appContext.Services.SectionService) == false)
if (DashboardSecurity.AuthorizeAccess(control, currentUser, _sectionService) == false)
continue;
var dashboardControl = new DashboardControl();
@@ -112,7 +115,7 @@ namespace Umbraco.Web.Editors
dashboardControl.Caption = control.PanelCaption;
dashboardControl.Path = IOHelper.FindFile(controlPath);
if (controlPath.ToLowerInvariant().EndsWith(".ascx".ToLowerInvariant()))
dashboardControl.ServerSide = true;
throw new NotSupportedException("Legacy UserControl (.ascx) dashboards are no longer supported");
dashboardControls.Add(dashboardControl);
}
@@ -138,13 +141,11 @@ namespace Umbraco.Web.Editors
//TODO: Need to integrate the security with the manifest dashboards
var appPlugins = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.AppPlugins));
var parser = new ManifestParser(appPlugins, _appContext.ApplicationCache.RuntimeCache);
var builder = new ManifestBuilder(_appContext.ApplicationCache.RuntimeCache, parser);
var tabs = new List<Tab<DashboardControl>>();
var i = startTabId;
foreach (var sectionDashboard in builder.Dashboards.Where(x => x.Value.Areas.InvariantContains(section)))
foreach (var sectionDashboard in _manifestParser.Manifest.Dashboards.Where(x => x.Value.Areas.InvariantContains(section)))
{
foreach (var tab in sectionDashboard.Value.Tabs)
{
@@ -157,7 +158,7 @@ namespace Umbraco.Web.Editors
dashboardControl.Caption = control.Caption;
dashboardControl.Path = IOHelper.FindFile(controlPath);
if (controlPath.ToLowerInvariant().EndsWith(".ascx".ToLowerInvariant()))
dashboardControl.ServerSide = true;
throw new NotSupportedException("Legacy UserControl (.ascx) dashboards are no longer supported");
dashboardControls.Add(dashboardControl);
}

View File

@@ -17,17 +17,20 @@ namespace Umbraco.Web.Editors
[PluginController("UmbracoApi")]
public class SectionController : UmbracoAuthorizedJsonController
{
private readonly DashboardHelper _dashboardHelper;
public SectionController(DashboardHelper dashboardHelper)
{
_dashboardHelper = dashboardHelper;
}
public IEnumerable<Section> GetSections()
{
var sections = Services.SectionService.GetAllowedSections(Security.GetUserId().ResultOr(0));
var sectionModels = sections.Select(Mapper.Map<Core.Models.Section, Section>).ToArray();
//Check if there are empty dashboards or dashboards that will end up empty based on the current user's access
//and add the meta data about them
var dashboardHelper = new DashboardHelper(ApplicationContext);
// this is a bit nasty since we'll be proxying via the app tree controller but we sort of have to do that
// since tree's by nature are controllers and require request contextual data - and then we have to
// remember to inject properties - nasty indeed
@@ -36,7 +39,7 @@ namespace Umbraco.Web.Editors
Current.Container.InjectProperties(appTreeController);
appTreeController.ControllerContext = ControllerContext;
var dashboards = dashboardHelper.GetDashboards(Security.CurrentUser);
var dashboards = _dashboardHelper.GetDashboards(Security.CurrentUser);
//now we can add metadata for each section so that the UI knows if there's actually anything at all to render for
//a dashboard for a given section, then the UI can deal with it accordingly (i.e. redirect to the first tree)
foreach (var section in sectionModels)

View File

@@ -10,15 +10,6 @@ namespace Umbraco.Web.Models.ContentEditing
[DataContract(Name = "control", Namespace = "")]
public class DashboardControl
{
[DataMember(Name = "showOnce")]
public bool ShowOnce { get; set; }
[DataMember(Name = "addPanel")]
public bool AddPanel { get; set; }
[DataMember(Name = "serverSide")]
public bool ServerSide { get; set; }
[DataMember(Name = "path")]
public string Path { get; set; }

View File

@@ -208,6 +208,8 @@ namespace Umbraco.Web.Runtime
.Append<ListViewContentAppDefinition>()
.Append<ContentEditorContentAppDefinition>()
.Append<ContentInfoContentAppDefinition>();
composition.Container.RegisterSingleton<DashboardHelper>();
}
internal void Initialize(