5151 - Added GetProfilesById extension
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ namespace Umbraco.Examine
|
||||
// processing below instead of one by one.
|
||||
using (var scope = _scopeProvider.CreateScope())
|
||||
{
|
||||
creatorIds = content.Select(x => x.CreatorId).Distinct().Select(x => _userService.GetProfileById(x))
|
||||
creatorIds = _userService.GetProfilesById(content.Select(x => x.CreatorId).ToArray())
|
||||
.ToDictionary(x => x.Id, x => x);
|
||||
writerIds = content.Select(x => x.WriterId).Distinct().Select(x => _userService.GetProfileById(x))
|
||||
writerIds = _userService.GetProfilesById(content.Select(x => x.WriterId).ToArray())
|
||||
.ToDictionary(x => x.Id, x => x);
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user