diff --git a/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs b/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs index 2498e1f70e..876b22d0c2 100644 --- a/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs @@ -7,6 +7,7 @@ namespace Umbraco.Core.Models.Membership /// public interface IReadOnlyUserGroup { + int Id { get; } int StartContentId { get; } int StartMediaId { get; } diff --git a/src/Umbraco.Core/Models/Membership/ReadOnlyUserGroup.cs b/src/Umbraco.Core/Models/Membership/ReadOnlyUserGroup.cs index 68c2f094b9..927bec41fe 100644 --- a/src/Umbraco.Core/Models/Membership/ReadOnlyUserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/ReadOnlyUserGroup.cs @@ -5,14 +5,16 @@ namespace Umbraco.Core.Models.Membership { public class ReadOnlyUserGroup : IReadOnlyUserGroup, IEquatable { - public ReadOnlyUserGroup(int startContentId, int startMediaId, string @alias, IEnumerable allowedSections) + public ReadOnlyUserGroup(int id, int startContentId, int startMediaId, string @alias, IEnumerable allowedSections) { + Id = id; StartContentId = startContentId; StartMediaId = startMediaId; Alias = alias; AllowedSections = allowedSections; } + public int Id { get; private set; } public int StartContentId { get; private set; } public int StartMediaId { get; private set; } public string Alias { get; private set; } diff --git a/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs b/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs index ec39fb0bf4..a7237932f9 100644 --- a/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs +++ b/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs @@ -7,12 +7,12 @@ namespace Umbraco.Core.Models.Membership { public static IReadOnlyUserGroup ToReadOnlyGroup(this IUserGroup group) { - return new ReadOnlyUserGroup(group.StartContentId, group.StartMediaId, group.Alias, group.AllowedSections); + return new ReadOnlyUserGroup(group.Id, group.StartContentId, group.StartMediaId, group.Alias, group.AllowedSections); } public static IReadOnlyUserGroup ToReadOnlyGroup(this UserGroupDto group) { - return new ReadOnlyUserGroup(group.StartContentId, group.StartMediaId, group.Alias, group.UserGroup2AppDtos.Select(x => x.AppAlias).ToArray()); + return new ReadOnlyUserGroup(group.Id, group.StartContentId, group.StartMediaId, group.Alias, group.UserGroup2AppDtos.Select(x => x.AppAlias).ToArray()); } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs index bfa66bfd20..7d4c94d2f7 100644 --- a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs @@ -50,10 +50,10 @@ namespace Umbraco.Web.Models.Mapping }); config.CreateMap() - .ConstructUsing(invite => new User(invite.Name, invite.Email, invite.Email, Guid.NewGuid().ToString("N"))) + .ConstructUsing(invite => new User(invite.Name, invite.Email, invite.Email, Guid.NewGuid().ToString("N"))) //generate a token for the invite - .ForMember(user => user.SecurityStamp, expression => expression.MapFrom(x => (DateTime.Now + x.Email).ToSHA1())) - //all invited users will not be approved, completing the invite will approve the user + .ForMember(user => user.SecurityStamp, expression => expression.MapFrom(x => (DateTime.Now + x.Email).ToSHA1())) + //all invited users will not be approved, completing the invite will approve the user .ForMember(user => user.IsApproved, expression => expression.UseValue(false)) .ForMember(user => user.Id, expression => expression.Ignore()) .ForMember(user => user.Avatar, expression => expression.Ignore()) @@ -84,24 +84,53 @@ namespace Umbraco.Web.Models.Mapping { user.AddGroup(group.ToReadOnlyGroup()); } - }); + }); - config.CreateMap() - .ForMember(detail => detail.Sections, opt => opt.MapFrom(x => x.AllowedSections)) - .ForMember(detail => detail.StartContentId, opt => opt.MapFrom(x => applicationContext.Services.EntityService.Get(x.StartContentId, false))) - .ForMember(detail => detail.StartMediaId, opt => opt.MapFrom(x => applicationContext.Services.EntityService.Get(x.StartMediaId, false))) - .ForMember(detail => detail.Notifications, opt => opt.Ignore()) + config.CreateMap() + .ForMember(detail => detail.StartContentId, opt => opt.Ignore()) + .ForMember(detail => detail.StartMediaId, opt => opt.Ignore()) + .ForMember(detail => detail.Sections, opt => opt.Ignore()) + .ForMember(detail => detail.Notifications, opt => opt.Ignore()) .ForMember(detail => detail.Udi, opt => opt.Ignore()) .ForMember(detail => detail.Trashed, opt => opt.Ignore()) .ForMember(detail => detail.ParentId, opt => opt.UseValue(-1)) - .ForMember(detail => detail.Path, opt => opt.MapFrom(user => "-1," + user.Id)) - .ForMember(detail => detail.AdditionalData, opt => opt.Ignore()); + .ForMember(detail => detail.Path, opt => opt.MapFrom(userGroup => "-1," + userGroup.Id)) + .ForMember(detail => detail.AdditionalData, opt => opt.Ignore()) + .AfterMap((group, display) => + { + var allSections = applicationContext.Services.SectionService.GetSections(); + display.Sections = allSections.Where(x => group.Alias == x.Alias).Select(Mapper.Map); + + //applicationContext.Services.EntityService.Get(x.StartContentId, false)) + //applicationContext.Services.EntityService.Get(x.StartMediaId, false)) + + }); + + config.CreateMap() + .ForMember(detail => detail.StartContentId, opt => opt.Ignore()) + .ForMember(detail => detail.StartMediaId, opt => opt.Ignore()) + .ForMember(detail => detail.Sections, opt => opt.Ignore()) + .ForMember(detail => detail.Notifications, opt => opt.Ignore()) + .ForMember(detail => detail.Udi, opt => opt.Ignore()) + .ForMember(detail => detail.Trashed, opt => opt.Ignore()) + .ForMember(detail => detail.ParentId, opt => opt.UseValue(-1)) + .ForMember(detail => detail.Path, opt => opt.MapFrom(userGroup => "-1," + userGroup.Id)) + .ForMember(detail => detail.AdditionalData, opt => opt.Ignore()) + .AfterMap((group, display) => + { + var allSections = applicationContext.Services.SectionService.GetSections(); + display.Sections = allSections.Where(x => group.Alias == x.Alias).Select(Mapper.Map); + + //applicationContext.Services.EntityService.Get(x.StartContentId, false)) + //applicationContext.Services.EntityService.Get(x.StartMediaId, false)) + + }); 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.LastLoginDate, opt => opt.MapFrom(user => user.LastLoginDate == default(DateTime) ? null : (DateTime?) user.LastLoginDate)) - .ForMember(detail => detail.UserGroups, opt => opt.MapFrom(user => user.Groups.Select(x => x.Alias).ToArray())) + .ForMember(detail => detail.UserGroups, opt => opt.Ignore()) .ForMember(detail => detail.StartContentIds, opt => opt.Ignore()) .ForMember(detail => detail.StartMediaIds, opt => opt.Ignore()) .ForMember(detail => detail.Culture, opt => opt.MapFrom(user => user.GetUserCulture(applicationContext.Services.TextService))) @@ -126,6 +155,9 @@ namespace Umbraco.Web.Models.Mapping var mediaItems = applicationContext.Services.EntityService.GetAll(UmbracoObjectTypes.Document, user.StartContentIds.ToArray()); display.StartContentIds = Mapper.Map, IEnumerable>(contentItems); display.StartMediaIds = Mapper.Map, IEnumerable>(mediaItems); + + display.UserGroups = Mapper.Map, IEnumerable>(user.Groups); + }); config.CreateMap()