Files
Umbraco-CMS/src/Umbraco.Web.BackOffice/Trees/LogViewerTreeController.cs
Andy Butland 96d33201aa Few more NRT tweaks (#12323)
* Amended GetAll() on IDataTypeService to return an empty collection rather than null.

* Added a ClearSessionValue method to ISessionManager (given you can no longer set a value to null).

* Allow for null values in a StatefulNotification.

* Removed obsoletion of synchronous messages on TreeControllerBase.

* Fixed further CS8620 warnings in core project.

* Further fix to nullable warning.

* Aligned nullablility of retreiving tree nodes and menus, synchronously or asynchronously (such that we no longer can get null values, always empty collection objects).
2022-05-01 08:18:09 +02:00

70 lines
2.7 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Trees;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Cms.Web.Common.Authorization;
using Constants = Umbraco.Cms.Core.Constants;
namespace Umbraco.Cms.Web.BackOffice.Trees
{
[Authorize(Policy = AuthorizationPolicies.TreeAccessLogs)]
[Tree(Constants.Applications.Settings, Constants.Trees.LogViewer, SortOrder= 9, TreeGroup = Constants.Trees.Groups.Settings)]
[PluginController(Constants.Web.Mvc.BackOfficeTreeArea)]
[CoreTree]
public class LogViewerTreeController : TreeController
{
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
public LogViewerTreeController(
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IEventAggregator eventAggregator,
IMenuItemCollectionFactory menuItemCollectionFactory)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory;
}
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
//We don't have any child nodes & only use the root node to load a custom UI
return new TreeNodeCollection();
}
protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
{
//We don't have any menu item options (such as create/delete/reload) & only use the root node to load a custom UI
return _menuItemCollectionFactory.Create();
}
/// <summary>
/// Helper method to create a root model for a tree
/// </summary>
/// <returns></returns>
protected override ActionResult<TreeNode?> CreateRootNode(FormCollection queryStrings)
{
var rootResult = base.CreateRootNode(queryStrings);
if (!(rootResult.Result is null))
{
return rootResult;
}
var root = rootResult.Value;
if (root is not null)
{
// This will load in a custom UI instead of the dashboard for the root node
root.RoutePath = $"{Constants.Applications.Settings}/{Constants.Trees.LogViewer}/overview";
root.Icon = Constants.Icons.LogViewer;
root.HasChildren = false;
root.MenuUrl = null;
}
return root;
}
}
}