Merge branch 'v8/8.6' up into v8/dev
# Conflicts: # src/SolutionInfo.cs # src/Umbraco.Web/Models/Mapping/ContentMapDefinition.cs
This commit is contained in:
@@ -5,6 +5,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Routing;
|
||||
@@ -27,6 +28,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IEntityService _entityService;
|
||||
private readonly TabsAndPropertiesMapper<IContent> _tabsAndPropertiesMapper;
|
||||
private readonly ContentSavedStateMapper<ContentPropertyDisplay> _stateMapper;
|
||||
private readonly ContentBasicSavedStateMapper<ContentPropertyBasic> _basicStateMapper;
|
||||
@@ -34,7 +36,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
|
||||
public ContentMapDefinition(CommonMapper commonMapper, ILocalizedTextService localizedTextService, IContentService contentService, IContentTypeService contentTypeService,
|
||||
IFileService fileService, IUmbracoContextAccessor umbracoContextAccessor, IPublishedRouter publishedRouter, ILocalizationService localizationService, ILogger logger,
|
||||
IUserService userService)
|
||||
IUserService userService, IEntityService entityService)
|
||||
{
|
||||
_commonMapper = commonMapper;
|
||||
_localizedTextService = localizedTextService;
|
||||
@@ -46,7 +48,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
_localizationService = localizationService;
|
||||
_logger = logger;
|
||||
_userService = userService;
|
||||
|
||||
_entityService = entityService;
|
||||
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IContent>(localizedTextService);
|
||||
_stateMapper = new ContentSavedStateMapper<ContentPropertyDisplay>();
|
||||
_basicStateMapper = new ContentBasicSavedStateMapper<ContentPropertyBasic>();
|
||||
@@ -80,7 +82,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
target.Icon = source.ContentType.Icon;
|
||||
target.Id = source.Id;
|
||||
target.IsBlueprint = source.Blueprint;
|
||||
target.IsChildOfListView = DetermineIsChildOfListView(source);
|
||||
target.IsChildOfListView = DetermineIsChildOfListView(source, context);
|
||||
target.IsContainer = source.ContentType.IsContainer;
|
||||
target.IsElement = source.ContentType.IsElement;
|
||||
target.Key = source.Key;
|
||||
@@ -211,13 +213,66 @@ namespace Umbraco.Web.Models.Mapping
|
||||
return source.CultureInfos.TryGetValue(culture, out var name) && !name.Name.IsNullOrWhiteSpace() ? name.Name : $"({source.Name})";
|
||||
}
|
||||
|
||||
private bool DetermineIsChildOfListView(IContent source)
|
||||
/// <summary>
|
||||
/// Checks if the content item is a descendant of a list view
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="context"></param>
|
||||
/// <returns>
|
||||
/// Returns true if the content item is a descendant of a list view and where the content is
|
||||
/// not a current user's start node.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// We must check if it's the current user's start node because in that case we will actually be
|
||||
/// rendering the tree node underneath the list view to visually show context. In this case we return
|
||||
/// false because the item is technically not being rendered as part of a list view but instead as a
|
||||
/// real tree node. If we didn't perform this check then tree syncing wouldn't work correctly.
|
||||
/// </remarks>
|
||||
private bool DetermineIsChildOfListView(IContent source, MapperContext context)
|
||||
{
|
||||
// map the IsChildOfListView (this is actually if it is a descendant of a list view!)
|
||||
var userStartNodes = Array.Empty<int>();
|
||||
|
||||
// In cases where a user's start node is below a list view, we will actually render
|
||||
// out the tree to that start node and in that case for that start node, we want to return
|
||||
// false here.
|
||||
if (context.HasItems && context.Items.TryGetValue("CurrentUser", out var usr) && usr is IUser currentUser)
|
||||
{
|
||||
userStartNodes = currentUser.CalculateContentStartNodeIds(_entityService);
|
||||
if (!userStartNodes.Contains(Constants.System.Root))
|
||||
{
|
||||
// return false if this is the user's actual start node, the node will be rendered in the tree
|
||||
// regardless of if it's a list view or not
|
||||
if (userStartNodes.Contains(source.Id))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var parent = _contentService.GetParent(source);
|
||||
return parent != null && (parent.ContentType.IsContainer || _contentTypeService.HasContainerInPath(parent.Path));
|
||||
|
||||
if (parent == null)
|
||||
return false;
|
||||
|
||||
var pathParts = parent.Path.Split(',').Select(x => int.TryParse(x, out var i) ? i : 0).ToList();
|
||||
|
||||
// reduce the path parts so we exclude top level content items that
|
||||
// are higher up than a user's start nodes
|
||||
foreach (var n in userStartNodes)
|
||||
{
|
||||
var index = pathParts.IndexOf(n);
|
||||
if (index != -1)
|
||||
{
|
||||
// now trim all top level start nodes to the found index
|
||||
for (var i = 0; i < index; i++)
|
||||
{
|
||||
pathParts.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent.ContentType.IsContainer || _contentTypeService.HasContainerInPath(pathParts.ToArray());
|
||||
}
|
||||
|
||||
|
||||
private DateTime? GetScheduledDate(IContent source, ContentScheduleAction action, MapperContext context)
|
||||
{
|
||||
var culture = context.GetCulture() ?? string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user