diff --git a/src/Umbraco.Core/Models/Membership/User.cs b/src/Umbraco.Core/Models/Membership/User.cs index db55622118..b2e380811b 100644 --- a/src/Umbraco.Core/Models/Membership/User.cs +++ b/src/Umbraco.Core/Models/Membership/User.cs @@ -57,7 +57,7 @@ namespace Umbraco.Core.Models.Membership _isLockedOut = false; _startContentIds = new int[] { }; _startMediaIds = new int[] { }; - } + } /// /// Constructor for creating a new User instance for an existing user @@ -68,12 +68,16 @@ namespace Umbraco.Core.Models.Membership /// /// /// - public User(int id, string name, string email, string username, string rawPasswordValue, IEnumerable userGroups) + /// + /// + public User(int id, string name, string email, string username, string rawPasswordValue, IEnumerable userGroups, int[] startContentIds, int[] startMediaIds) : this() { //we allow whitespace for this value so just check null if (rawPasswordValue == null) throw new ArgumentNullException("rawPasswordValue"); if (userGroups == null) throw new ArgumentNullException("userGroups"); + if (startContentIds == null) throw new ArgumentNullException("startContentIds"); + if (startMediaIds == null) throw new ArgumentNullException("startMediaIds"); if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name"); if (string.IsNullOrWhiteSpace(username)) throw new ArgumentException("Value cannot be null or whitespace.", "username"); @@ -85,8 +89,8 @@ namespace Umbraco.Core.Models.Membership _userGroups = new HashSet(userGroups); _isApproved = true; _isLockedOut = false; - _startContentIds = new int[] { }; - _startMediaIds = new int[] { }; + _startContentIds = startContentIds; + _startMediaIds = startMediaIds; } private string _name; diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs index 198c41bd54..4209878116 100644 --- a/src/Umbraco.Core/Models/UserExtensions.cs +++ b/src/Umbraco.Core/Models/UserExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net; @@ -10,7 +11,25 @@ using Umbraco.Core.Services; namespace Umbraco.Core.Models { public static class UserExtensions - { + { + /// + /// Returns all of the user's assigned start node ids based on ids assigned directly to the IUser object and it's groups + /// + /// + public static IEnumerable GetCombinedStartContentIds(this IUser user) + { + return user.StartContentIds.Concat(user.Groups.Select(x => x.StartContentId)).Distinct(); + } + + /// + /// Returns all of the user's assigned start node ids based on ids assigned directly to the IUser object and it's groups + /// + /// + public static IEnumerable GetCombinedMediaContentIds(this IUser user) + { + return user.StartMediaIds.Concat(user.Groups.Select(x => x.StartMediaId)).Distinct(); + } + /// /// Tries to lookup the user's gravatar to see if the endpoint can be reached, if so it returns the valid URL /// @@ -115,7 +134,7 @@ namespace Umbraco.Core.Models { if (user == null) throw new ArgumentNullException("user"); if (content == null) throw new ArgumentNullException("content"); - return HasPathAccess(content.Path, user.StartContentIds, Constants.System.RecycleBinContent); + return HasPathAccess(content.Path, user.GetCombinedStartContentIds().ToArray(), Constants.System.RecycleBinContent); } internal static bool HasPathAccess(string path, int[] startNodeIds, int recycleBinId) @@ -159,7 +178,7 @@ namespace Umbraco.Core.Models { if (user == null) throw new ArgumentNullException("user"); if (media == null) throw new ArgumentNullException("media"); - return HasPathAccess(media.Path, user.StartMediaIds, Constants.System.RecycleBinMedia); + return HasPathAccess(media.Path, user.GetCombinedMediaContentIds().ToArray(), Constants.System.RecycleBinMedia); } /// diff --git a/src/Umbraco.Core/Persistence/Factories/UserFactory.cs b/src/Umbraco.Core/Persistence/Factories/UserFactory.cs index 2915bc570e..cae42191c6 100644 --- a/src/Umbraco.Core/Persistence/Factories/UserFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/UserFactory.cs @@ -13,15 +13,16 @@ namespace Umbraco.Core.Persistence.Factories { var guidId = dto.Id.ToGuid(); - var user = new User(dto.Id, dto.UserName, dto.Email, dto.Login,dto.Password, dto.UserGroupDtos.Select(x => x.ToReadOnlyGroup()).ToArray()); + var user = new User(dto.Id, dto.UserName, dto.Email, dto.Login,dto.Password, + dto.UserGroupDtos.Select(x => x.ToReadOnlyGroup()).ToArray(), + dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Content).Select(x => x.StartNode).ToArray(), + dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Media).Select(x => x.StartNode).ToArray()); try { user.DisableChangeTracking(); user.Key = guidId; - user.StartContentIds = dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Content).Select(x => x.StartNode).ToArray(); - user.StartMediaIds = dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int) UserStartNodeDto.StartNodeTypeValue.Media).Select(x => x.StartNode).ToArray(); user.IsLockedOut = dto.NoConsole; user.IsApproved = dto.Disabled == false; user.Language = dto.UserLanguage; diff --git a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs index 81ac54caae..339de9387e 100644 --- a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs @@ -94,7 +94,7 @@ namespace Umbraco.Web.Models.Mapping config.CreateMap() .ForMember(detail => detail.Avatars, opt => opt.MapFrom(user => user.GetCurrentUserAvatarUrls(applicationContext.Services.UserService, applicationContext.ApplicationCache.RuntimeCache))) .ForMember(detail => detail.Username, opt => opt.MapFrom(user => user.Username)) - .ForMember(detail => detail.UserGroups, opt => opt.MapFrom(user => user.Groups)) + .ForMember(detail => detail.UserGroups, opt => opt.MapFrom(user => user.Groups.Select(x => x.Alias).ToArray())) .ForMember(detail => detail.StartContentIds, opt => opt.MapFrom(user => user.StartContentIds)) .ForMember(detail => detail.StartMediaIds, opt => opt.MapFrom(user => user.StartMediaIds)) .ForMember(detail => detail.Culture, opt => opt.MapFrom(user => user.GetUserCulture(applicationContext.Services.TextService)))