2013-10-03 19:00:31 +10:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Configuration;
|
2013-09-02 15:40:14 +02:00
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
|
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Editors
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The API controller used for getting entity objects, basic name, icon, id representation of any umbraco object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[PluginController("UmbracoApi")]
|
|
|
|
|
|
public class DashboardController : UmbracoAuthorizedJsonController
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2013-10-03 17:59:23 +10:00
|
|
|
|
public IEnumerable<Tab<DashboardControl>> GetDashboard(string section)
|
2013-09-02 15:40:14 +02:00
|
|
|
|
{
|
2013-10-03 17:59:23 +10:00
|
|
|
|
var tabs = new List<Tab<DashboardControl>>();
|
2013-10-03 19:00:31 +10:00
|
|
|
|
var i = 1;
|
2013-11-14 10:23:21 +01:00
|
|
|
|
|
|
|
|
|
|
// The dashboard config can contain more than one area inserted by a package.
|
|
|
|
|
|
foreach( var dashboardSection in UmbracoConfig.For.DashboardSettings().Sections.Where(x => x.Areas.Contains(section)))
|
2013-09-02 15:40:14 +02:00
|
|
|
|
{
|
2013-11-14 10:23:21 +01:00
|
|
|
|
//we need to validate access to this section
|
|
|
|
|
|
if (DashboardSecurity.AuthorizeAccess(dashboardSection, Security.CurrentUser, Services.SectionService))
|
2013-09-02 15:40:14 +02:00
|
|
|
|
{
|
2013-11-14 10:23:21 +01:00
|
|
|
|
//User is authorized
|
|
|
|
|
|
foreach (var dashTab in dashboardSection.Tabs)
|
2013-09-02 15:40:14 +02:00
|
|
|
|
{
|
2013-11-14 10:23:21 +01:00
|
|
|
|
//we need to validate access to this tab
|
|
|
|
|
|
if (DashboardSecurity.AuthorizeAccess(dashTab, Security.CurrentUser, Services.SectionService))
|
2013-09-02 15:40:14 +02:00
|
|
|
|
{
|
2013-11-14 10:23:21 +01:00
|
|
|
|
var props = new List<DashboardControl>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var dashCtrl in dashTab.Controls)
|
2013-10-03 19:00:31 +10:00
|
|
|
|
{
|
2013-11-14 10:23:21 +01:00
|
|
|
|
if (DashboardSecurity.AuthorizeAccess(dashCtrl, Security.CurrentUser,
|
|
|
|
|
|
Services.SectionService))
|
|
|
|
|
|
{
|
|
|
|
|
|
var ctrl = new DashboardControl();
|
|
|
|
|
|
var controlPath = dashCtrl.ControlPath.Trim(' ', '\r', '\n');
|
|
|
|
|
|
ctrl.Path = IOHelper.FindFile(controlPath);
|
|
|
|
|
|
if (controlPath.ToLower().EndsWith(".ascx"))
|
|
|
|
|
|
{
|
|
|
|
|
|
ctrl.ServerSide = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
props.Add(ctrl);
|
|
|
|
|
|
}
|
2013-10-03 19:00:31 +10:00
|
|
|
|
}
|
2013-11-14 10:23:21 +01:00
|
|
|
|
|
|
|
|
|
|
tabs.Add(new Tab<DashboardControl>
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = i,
|
|
|
|
|
|
Alias = dashTab.Caption.ToSafeAlias(),
|
|
|
|
|
|
IsActive = i == 1,
|
|
|
|
|
|
Label = dashTab.Caption,
|
|
|
|
|
|
Properties = props
|
|
|
|
|
|
});
|
|
|
|
|
|
i++;
|
2013-09-02 15:40:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-10-03 19:00:31 +10:00
|
|
|
|
|
2013-11-14 10:23:21 +01:00
|
|
|
|
//In case there are no tabs or a user doesn't have access the empty tabs list is returned
|
2013-10-03 19:00:31 +10:00
|
|
|
|
return tabs;
|
|
|
|
|
|
|
2013-09-02 15:40:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|