From 225f657154510ee3b9ff91cc1941fdf4bb94c96e Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 16 May 2017 18:18:10 +1000 Subject: [PATCH] fixes tests for mappings --- src/Umbraco.Web/Editors/UserController.cs | 2 +- .../Models/ContentEditing/UserDisplay.cs | 29 ++++++++++++++----- .../Models/Mapping/UserModelMapper.cs | 21 ++++++++++++-- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Web/Editors/UserController.cs b/src/Umbraco.Web/Editors/UserController.cs index b0da9a3f47..7f24f93d4c 100644 --- a/src/Umbraco.Web/Editors/UserController.cs +++ b/src/Umbraco.Web/Editors/UserController.cs @@ -77,7 +77,7 @@ namespace Umbraco.Web.Editors Id = startId, //UserType = "writer", AllowedSections = new[] {"content", "media"}, - AvailableUserTypes = userTypes, + AvailableUserGroups = userTypes, Email = "test" + startId + "@test.com", Name = "User " + startId, Culture = "en-US", diff --git a/src/Umbraco.Web/Models/ContentEditing/UserDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/UserDisplay.cs index 76a480c80d..1385e395ec 100644 --- a/src/Umbraco.Web/Models/ContentEditing/UserDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/UserDisplay.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.Runtime.Serialization; @@ -20,23 +21,27 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "email", IsRequired = true)] public string Email { get; set; } - - //TODO: Should be user groups! - //[DataMember(Name = "userType")] - //public string UserType { get; set; } + + /// + /// The list of group aliases assigned to the user + /// + [DataMember(Name = "userGroups")] + public IEnumerable UserGroups { get; set; } /// - /// Gets the available user types (i.e. to populate a drop down) - /// The key is the Alias the value is the Name - the Alias is what is used in the UserType property and for persistence + /// Gets the available user groups (i.e. to populate a drop down) + /// The key is the Alias the value is the Name - the Alias is what is used in the UserGroup property and for persistence /// - [DataMember(Name = "availableUserTypes")] - public IDictionary AvailableUserTypes { get; set; } + [DataMember(Name = "availableUserGroups")] + [ReadOnly(true)] + public IDictionary AvailableUserGroups { get; set; } /// /// Gets the available cultures (i.e. to populate a drop down) /// The key is the culture stored in the database, the value is the Name /// [DataMember(Name = "availableCultures")] + [ReadOnly(true)] public IDictionary AvailableCultures { get; set; } [DataMember(Name = "startContentId")] @@ -51,6 +56,14 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "allowedSections")] public IEnumerable AllowedSections { get; set; } + /// + /// Gets the available sections (i.e. to populate a drop down) + /// The key is the Alias the value is the Name - the Alias is what is used in the AllowedSections property and for persistence + /// + [DataMember(Name = "availableSections")] + [ReadOnly(true)] + public IDictionary AvailableSections { get; set; } + /// /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. /// diff --git a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs index ea634ac09a..f58dfe875a 100644 --- a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs @@ -18,13 +18,28 @@ namespace Umbraco.Web.Models.Mapping { config.CreateMap() .ForMember(detail => detail.Id, opt => opt.MapFrom(user => user.Id)) - //.ForMember(detail => detail.UserType, opt => opt.MapFrom(user => user.UserType.Alias)) + .ForMember(detail => detail.UserGroups, opt => opt.MapFrom(user => user.Groups)) .ForMember(detail => detail.StartContentId, opt => opt.MapFrom(user => user.StartContentId)) .ForMember(detail => detail.StartMediaId, opt => opt.MapFrom(user => user.StartMediaId)) .ForMember(detail => detail.Culture, opt => opt.MapFrom(user => user.GetUserCulture(applicationContext.Services.TextService))) .ForMember( - detail => detail.AvailableUserTypes, - opt => opt.MapFrom(user => applicationContext.Services.SectionService.GetSections().ToDictionary(x => x.Alias, x => x.Name))); + detail => detail.AvailableUserGroups, + opt => opt.MapFrom(user => applicationContext.Services.UserService.GetAllUserGroups().ToDictionary(x => x.Alias, x => x.Name))) + .ForMember( + detail => detail.AvailableSections, + opt => opt.MapFrom(user => applicationContext.Services.SectionService.GetSections().ToDictionary(x => x.Alias, x => x.Name))) + .ForMember( + detail => detail.AvailableCultures, + opt => opt.MapFrom(user => applicationContext.Services.TextService.GetSupportedCultures().ToDictionary(x => x.Name, x => x.DisplayName))) + .ForMember(detail => detail.ParentId, opt => opt.UseValue(-1)) + .ForMember(detail => detail.Path, opt => opt.MapFrom(user => "-1," + user.Id)) + .ForMember(detail => detail.Notifications, opt => opt.Ignore()) + .ForMember(detail => detail.Udi, opt => opt.Ignore()) + .ForMember(detail => detail.Icon, opt => opt.Ignore()) + .ForMember(detail => detail.Trashed, opt => opt.Ignore()) + .ForMember(detail => detail.Alias, opt => opt.Ignore()) + .ForMember(detail => detail.Trashed, opt => opt.Ignore()) + .ForMember(detail => detail.AdditionalData, opt => opt.Ignore()); config.CreateMap() .ForMember(detail => detail.UserId, opt => opt.MapFrom(user => GetIntId(user.Id)))