Port 7.7 - WIP

This commit is contained in:
Stephan
2017-09-19 15:51:47 +02:00
parent d54658009c
commit 9ed6576908
126 changed files with 3447 additions and 596 deletions

View File

@@ -3,6 +3,9 @@ using AutoMapper;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Mvc;
using System.Linq;
using Umbraco.Core.Models;
using Umbraco.Web.Trees;
using Section = Umbraco.Web.Models.ContentEditing.Section;
namespace Umbraco.Web.Editors
{
@@ -14,14 +17,58 @@ namespace Umbraco.Web.Editors
{
public IEnumerable<Section> GetSections()
{
var sections = Services.SectionService.GetAllowedSections(Security.GetUserId());
return sections.Select(Mapper.Map<Core.Models.Section, Section>);
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(Services.SectionService);
//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.
var appTreeController = new ApplicationTreeController
{
ControllerContext = ControllerContext
};
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)
{
var hasDashboards = false;
IEnumerable<Tab<DashboardControl>> dashboardsForSection;
if (dashboards.TryGetValue(section.Alias, out dashboardsForSection))
{
if (dashboardsForSection.Any())
hasDashboards = true;
}
if (hasDashboards == false)
{
//get the first tree in the section and get it's root node route path
var sectionTrees = appTreeController.GetApplicationTrees(section.Alias, null, null).Result;
section.RoutePath = sectionTrees.IsContainer == false
? sectionTrees.RoutePath
: sectionTrees.Children[0].RoutePath;
}
}
return sectionModels;
}
/// <summary>
/// Returns all the sections that the user has access to
/// </summary>
/// <returns></returns>
public IEnumerable<Section> GetAllSections()
{
var sections = Services.SectionService.GetSections();
return sections.Select(Mapper.Map<Core.Models.Section, Section>);
var mapped = sections.Select(Mapper.Map<Core.Models.Section, Section>);
if (Security.CurrentUser.IsAdmin())
return mapped;
return mapped.Where(x => Security.CurrentUser.AllowedSections.Contains(x.Alias)).ToArray();
}
}