updates user models

This commit is contained in:
Shannon
2017-06-06 00:02:23 +02:00
parent 2ee34d5c48
commit 64975166e7
4 changed files with 50 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ namespace Umbraco.Core.Models.Membership
/// </summary>
public interface IReadOnlyUserGroup
{
int Id { get; }
int StartContentId { get; }
int StartMediaId { get; }

View File

@@ -5,14 +5,16 @@ namespace Umbraco.Core.Models.Membership
{
public class ReadOnlyUserGroup : IReadOnlyUserGroup, IEquatable<ReadOnlyUserGroup>
{
public ReadOnlyUserGroup(int startContentId, int startMediaId, string @alias, IEnumerable<string> allowedSections)
public ReadOnlyUserGroup(int id, int startContentId, int startMediaId, string @alias, IEnumerable<string> 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; }

View File

@@ -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());
}
}
}

View File

@@ -50,10 +50,10 @@ namespace Umbraco.Web.Models.Mapping
});
config.CreateMap<UserInvite, IUser>()
.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<IUserGroup, UserGroupDisplay>()
.ForMember(detail => detail.Sections, opt => opt.MapFrom(x => x.AllowedSections))
.ForMember(detail => detail.StartContentId, opt => opt.MapFrom(x => applicationContext.Services.EntityService.Get<IContent>(x.StartContentId, false)))
.ForMember(detail => detail.StartMediaId, opt => opt.MapFrom(x => applicationContext.Services.EntityService.Get<IMedia>(x.StartMediaId, false)))
.ForMember(detail => detail.Notifications, opt => opt.Ignore())
config.CreateMap<IReadOnlyUserGroup, UserGroupDisplay>()
.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<ContentEditing.Section>);
//applicationContext.Services.EntityService.Get<IContent>(x.StartContentId, false))
//applicationContext.Services.EntityService.Get<IMedia>(x.StartMediaId, false))
});
config.CreateMap<IUserGroup, UserGroupDisplay>()
.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<ContentEditing.Section>);
//applicationContext.Services.EntityService.Get<IContent>(x.StartContentId, false))
//applicationContext.Services.EntityService.Get<IMedia>(x.StartMediaId, false))
});
config.CreateMap<IUser, UserDisplay>()
.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<IUmbracoEntity>, IEnumerable<EntityBasic>>(contentItems);
display.StartMediaIds = Mapper.Map<IEnumerable<IUmbracoEntity>, IEnumerable<EntityBasic>>(mediaItems);
display.UserGroups = Mapper.Map<IEnumerable<IReadOnlyUserGroup>, IEnumerable<UserGroupDisplay>>(user.Groups);
});
config.CreateMap<IUser, UserDetail>()