Fixes up the users login date on the user list view, fixes tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using Moq;
|
||||
@@ -36,7 +37,11 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
u.Id = 1234;
|
||||
});
|
||||
userServiceMock.Setup(service => service.GetAllUserGroups(It.IsAny<int[]>()))
|
||||
.Returns(Enumerable.Empty<IUserGroup>);
|
||||
.Returns(new[] { Mock.Of<IUserGroup>(group => group.Id == 123 && group.Alias == "writers" && group.Name == "Writers") });
|
||||
userServiceMock.Setup(service => service.GetUserGroupsByAlias(It.IsAny<string[]>()))
|
||||
.Returns(new[] { Mock.Of<IUserGroup>(group => group.Id == 123 && group.Alias == "writers" && group.Name == "Writers") });
|
||||
userServiceMock.Setup(service => service.GetUserById(It.IsAny<int>()))
|
||||
.Returns(new User(1234, "Test", "asdf@asdf.com", "test", "", new List<IReadOnlyUserGroup>(), new int[0], new int[0]));
|
||||
|
||||
//we need to manually apply automapper mappings with the mocked applicationcontext
|
||||
InitializeMappers(helper.UmbracoContext.Application);
|
||||
@@ -44,30 +49,32 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
return new UsersController(helper.UmbracoContext);
|
||||
});
|
||||
|
||||
var invite = new UserInvite
|
||||
var userSave = new UserSave
|
||||
{
|
||||
Id = -1,
|
||||
Email = "test@test.com",
|
||||
Message = "Hello test!",
|
||||
Username = "test@test.com",
|
||||
Culture = "en",
|
||||
Name = "Test",
|
||||
UserGroups = new[] { "writers" }
|
||||
};
|
||||
var response = await runner.Execute("Users", "PostSaveUser", HttpMethod.Post,
|
||||
new ObjectContent<UserInvite>(invite, new JsonMediaTypeFormatter()));
|
||||
new ObjectContent<UserSave>(userSave, new JsonMediaTypeFormatter()));
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<UserDisplay>(response.Item2);
|
||||
|
||||
Assert.AreEqual(invite.Name, obj.Name);
|
||||
Assert.AreEqual(userSave.Name, obj.Name);
|
||||
Assert.AreEqual(1234, obj.Id);
|
||||
Assert.AreEqual(invite.Email, obj.Email);
|
||||
foreach (var group in invite.UserGroups)
|
||||
Assert.AreEqual(userSave.Email, obj.Email);
|
||||
foreach (var group in userSave.UserGroups)
|
||||
{
|
||||
Assert.IsTrue(obj.UserGroups.Contains(group));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async void Invite_User()
|
||||
[TestCase("PostInviteUser")]
|
||||
[TestCase("PostCreateUser")]
|
||||
public async void Invite_And_Create(string action)
|
||||
{
|
||||
var runner = new TestRunner((message, helper) =>
|
||||
{
|
||||
@@ -82,7 +89,9 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
u.Id = 1234;
|
||||
});
|
||||
userServiceMock.Setup(service => service.GetAllUserGroups(It.IsAny<int[]>()))
|
||||
.Returns(Enumerable.Empty<IUserGroup>);
|
||||
.Returns(new[] { Mock.Of<IUserGroup>(group => group.Id == 123 && group.Alias == "writers" && group.Name == "Writers") });
|
||||
userServiceMock.Setup(service => service.GetUserGroupsByAlias(It.IsAny<string[]>()))
|
||||
.Returns(new[]{Mock.Of<IUserGroup>(group => group.Id == 123 && group.Alias == "writers" && group.Name == "Writers")});
|
||||
|
||||
//we need to manually apply automapper mappings with the mocked applicationcontext
|
||||
InitializeMappers(helper.UmbracoContext.Application);
|
||||
@@ -98,7 +107,7 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
Name = "Test",
|
||||
UserGroups = new[] {"writers"}
|
||||
};
|
||||
var response = await runner.Execute("Users", "PostInviteUser", HttpMethod.Post,
|
||||
var response = await runner.Execute("Users", action, HttpMethod.Post,
|
||||
new ObjectContent<UserInvite>(invite, new JsonMediaTypeFormatter()));
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<UserDisplay>(response.Item2);
|
||||
|
||||
@@ -160,8 +160,8 @@
|
||||
<div class="umb-package-details__information-item">
|
||||
<div class="umb-package-details__information-item-label">Last login:</div>
|
||||
<div class="umb-package-details__information-item-content">
|
||||
<span ng-if="vm.user.lastLogin">{{ vm.user.lastLogin }}</span>
|
||||
<span ng-if="!vm.user.lastLogin">The user has not logged in yet</span>
|
||||
<span ng-if="vm.user.lastLoginDate">{{ vm.user.lastLoginDate }}</span>
|
||||
<span ng-if="!vm.user.lastLoginDate">The user has not logged in yet</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -285,8 +285,8 @@
|
||||
|
||||
function formatDates(users) {
|
||||
angular.forEach(users, function(user){
|
||||
if(user.lastLogin) {
|
||||
user.formattedLastLogin = moment(user.lastLogin).format("MMMM Do YYYY, HH:mm");
|
||||
if (user.lastLoginDate) {
|
||||
user.formattedLastLogin = moment(user.lastLoginDate).format("MMMM Do YYYY, HH:mm");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
|
||||
<li><a tabindex="-1" href="#" ng-click="vm.setOrderByFilter('lastLogin')" prevent-default>Last login</a></li>
|
||||
<li><a tabindex="-1" href="#" ng-click="vm.setOrderByFilter('lastLoginDate')" prevent-default>Last login</a></li>
|
||||
<li><a tabindex="-1" href="#" ng-click="vm.setOrderByFilter('Name')" prevent-default>Name</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
public string EmailHash { get; set; }
|
||||
|
||||
[DataMember(Name = "lastLoginDate")]
|
||||
public DateTime LastLoginDate { get; set; }
|
||||
public DateTime? LastLoginDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of different size avatars
|
||||
|
||||
@@ -94,6 +94,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
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.StartContentIds, opt => opt.MapFrom(user => user.StartContentIds))
|
||||
.ForMember(detail => detail.StartMediaIds, opt => opt.MapFrom(user => user.StartMediaIds))
|
||||
|
||||
Reference in New Issue
Block a user