@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Security;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
@@ -116,5 +117,17 @@ namespace Umbraco.Core.Services
|
||||
var permissionCollection = userService.GetPermissions(user, nodeId);
|
||||
return permissionCollection.SelectMany(c => c.AssignedPermissions).Distinct().ToArray();
|
||||
}
|
||||
|
||||
internal static IEnumerable<IProfile> GetProfilesById(this IUserService userService, params int[] ids)
|
||||
{
|
||||
var fullUsers = userService.GetUsersById(ids);
|
||||
|
||||
return fullUsers.Select(user =>
|
||||
{
|
||||
var asProfile = user as IProfile;
|
||||
return asProfile ?? new UserProfile(user.Id, user.Name);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
using Examine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
@@ -16,20 +20,46 @@ namespace Umbraco.Examine
|
||||
{
|
||||
private readonly UrlSegmentProviderCollection _urlSegmentProviders;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IScopeProvider _scopeProvider;
|
||||
|
||||
[Obsolete("Use the other ctor instead")]
|
||||
public ContentValueSetBuilder(PropertyEditorCollection propertyEditors,
|
||||
UrlSegmentProviderCollection urlSegmentProviders,
|
||||
IUserService userService,
|
||||
bool publishedValuesOnly)
|
||||
: this(propertyEditors, urlSegmentProviders, userService, Current.ScopeProvider, publishedValuesOnly)
|
||||
{
|
||||
}
|
||||
|
||||
public ContentValueSetBuilder(PropertyEditorCollection propertyEditors,
|
||||
UrlSegmentProviderCollection urlSegmentProviders,
|
||||
IUserService userService,
|
||||
IScopeProvider scopeProvider,
|
||||
bool publishedValuesOnly)
|
||||
: base(propertyEditors, publishedValuesOnly)
|
||||
{
|
||||
_urlSegmentProviders = urlSegmentProviders;
|
||||
_userService = userService;
|
||||
_scopeProvider = scopeProvider;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<ValueSet> GetValueSets(params IContent[] content)
|
||||
{
|
||||
Dictionary<int, IProfile> creatorIds;
|
||||
Dictionary<int, IProfile> writerIds;
|
||||
|
||||
// We can lookup all of the creator/writer names at once which can save some
|
||||
// processing below instead of one by one.
|
||||
using (var scope = _scopeProvider.CreateScope())
|
||||
{
|
||||
creatorIds = _userService.GetProfilesById(content.Select(x => x.CreatorId).ToArray())
|
||||
.ToDictionary(x => x.Id, x => x);
|
||||
writerIds = _userService.GetProfilesById(content.Select(x => x.WriterId).ToArray())
|
||||
.ToDictionary(x => x.Id, x => x);
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
// TODO: There is a lot of boxing going on here and ultimately all values will be boxed by Lucene anyways
|
||||
// but I wonder if there's a way to reduce the boxing that we have to do or if it will matter in the end since
|
||||
// Lucene will do it no matter what? One idea was to create a `FieldValue` struct which would contain `object`, `object[]`, `ValueType` and `ValueType[]`
|
||||
@@ -58,8 +88,8 @@ namespace Umbraco.Examine
|
||||
{"urlName", urlValue?.Yield() ?? Enumerable.Empty<string>()}, //Always add invariant urlName
|
||||
{"path", c.Path?.Yield() ?? Enumerable.Empty<string>()},
|
||||
{"nodeType", c.ContentType.Id.ToString().Yield() ?? Enumerable.Empty<string>()},
|
||||
{"creatorName", (c.GetCreatorProfile(_userService)?.Name ?? "??").Yield() },
|
||||
{"writerName",(c.GetWriterProfile(_userService)?.Name ?? "??").Yield() },
|
||||
{"creatorName", (creatorIds.TryGetValue(c.CreatorId, out var creatorProfile) ? creatorProfile.Name : "??").Yield() },
|
||||
{"writerName", (writerIds.TryGetValue(c.WriterId, out var writerProfile) ? writerProfile.Name : "??").Yield() },
|
||||
{"writerID", new object[] {c.WriterId}},
|
||||
{"templateID", new object[] {c.TemplateId ?? 0}},
|
||||
{UmbracoContentIndex.VariesByCultureFieldName, new object[] {"n"}},
|
||||
|
||||
@@ -924,6 +924,24 @@ namespace Umbraco.Tests.Services
|
||||
Assert.AreEqual(user.Id, profile.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_By_Profile_Id_Must_return_null_if_user_not_exists()
|
||||
{
|
||||
var profile = ServiceContext.UserService.GetProfileById(42);
|
||||
|
||||
// Assert
|
||||
Assert.IsNull(profile);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProfilesById_Must_empty_if_users_not_exists()
|
||||
{
|
||||
var profiles = ServiceContext.UserService.GetProfilesById(42);
|
||||
|
||||
// Assert
|
||||
CollectionAssert.IsEmpty(profiles);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_User_By_Username()
|
||||
{
|
||||
|
||||
@@ -30,16 +30,22 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
/// </summary>
|
||||
internal static class IndexInitializer
|
||||
{
|
||||
public static ContentValueSetBuilder GetContentValueSetBuilder(PropertyEditorCollection propertyEditors, bool publishedValuesOnly)
|
||||
public static ContentValueSetBuilder GetContentValueSetBuilder(PropertyEditorCollection propertyEditors, IScopeProvider scopeProvider, bool publishedValuesOnly)
|
||||
{
|
||||
var contentValueSetBuilder = new ContentValueSetBuilder(propertyEditors, new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }), GetMockUserService(), publishedValuesOnly);
|
||||
var contentValueSetBuilder = new ContentValueSetBuilder(
|
||||
propertyEditors,
|
||||
new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }),
|
||||
GetMockUserService(),
|
||||
scopeProvider,
|
||||
publishedValuesOnly);
|
||||
|
||||
return contentValueSetBuilder;
|
||||
}
|
||||
|
||||
public static ContentIndexPopulator GetContentIndexRebuilder(PropertyEditorCollection propertyEditors, IContentService contentService, ISqlContext sqlContext, bool publishedValuesOnly)
|
||||
public static ContentIndexPopulator GetContentIndexRebuilder(PropertyEditorCollection propertyEditors, IContentService contentService, IScopeProvider scopeProvider, bool publishedValuesOnly)
|
||||
{
|
||||
var contentValueSetBuilder = GetContentValueSetBuilder(propertyEditors, publishedValuesOnly);
|
||||
var contentIndexDataSource = new ContentIndexPopulator(true, null, contentService, sqlContext, contentValueSetBuilder);
|
||||
var contentValueSetBuilder = GetContentValueSetBuilder(propertyEditors, scopeProvider, publishedValuesOnly);
|
||||
var contentIndexDataSource = new ContentIndexPopulator(true, null, contentService, scopeProvider.SqlContext, contentValueSetBuilder);
|
||||
return contentIndexDataSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Index_Property_Data_With_Value_Indexer()
|
||||
{
|
||||
var contentValueSetBuilder = IndexInitializer.GetContentValueSetBuilder(Factory.GetInstance<PropertyEditorCollection>(), false);
|
||||
var contentValueSetBuilder = IndexInitializer.GetContentValueSetBuilder(Factory.GetInstance<PropertyEditorCollection>(), ScopeProvider, false);
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir,
|
||||
@@ -121,7 +121,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Rebuild_Index()
|
||||
{
|
||||
var contentRebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider.SqlContext, false);
|
||||
var contentRebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, false);
|
||||
var mediaRebuilder = IndexInitializer.GetMediaIndexRebuilder(Factory.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockMediaService());
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
@@ -149,7 +149,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Index_Protected_Content_Not_Indexed()
|
||||
{
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider.SqlContext, false);
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, false);
|
||||
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
@@ -274,7 +274,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Index_Reindex_Content()
|
||||
{
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider.SqlContext, false);
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, false);
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir,
|
||||
validator: new ContentValueSetValidator(false)))
|
||||
@@ -315,7 +315,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
public void Index_Delete_Index_Item_Ensure_Heirarchy_Removed()
|
||||
{
|
||||
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider.SqlContext, false);
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, false);
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
allRecs);
|
||||
|
||||
var propertyEditors = Factory.GetInstance<PropertyEditorCollection>();
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(propertyEditors, contentService, ScopeProvider.SqlContext, true);
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(propertyEditors, contentService, ScopeProvider, true);
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
|
||||
|
||||
@@ -4,6 +4,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Examine;
|
||||
@@ -36,12 +37,14 @@ namespace Umbraco.Web.Search
|
||||
factory.GetInstance<PropertyEditorCollection>(),
|
||||
factory.GetInstance<UrlSegmentProviderCollection>(),
|
||||
factory.GetInstance<IUserService>(),
|
||||
factory.GetInstance<IScopeProvider>(),
|
||||
true));
|
||||
composition.RegisterUnique<IContentValueSetBuilder>(factory =>
|
||||
new ContentValueSetBuilder(
|
||||
factory.GetInstance<PropertyEditorCollection>(),
|
||||
factory.GetInstance<UrlSegmentProviderCollection>(),
|
||||
factory.GetInstance<IUserService>(),
|
||||
factory.GetInstance<IScopeProvider>(),
|
||||
false));
|
||||
composition.RegisterUnique<IValueSetBuilder<IMedia>, MediaValueSetBuilder>();
|
||||
composition.RegisterUnique<IValueSetBuilder<IMember>, MemberValueSetBuilder>();
|
||||
|
||||
Reference in New Issue
Block a user