Skip to content

Commit 8d2c1ac

Browse files
authored
Merge pull request #11153 from umbraco/v9/bugfix/persist-isapproved
Fixes persisting the IsApproved for users
2 parents 1b0911f + cbafef2 commit 8d2c1ac

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ private bool UpdateMemberProperties(IUser user, BackOfficeIdentityUser identityU
482482
user.FailedPasswordAttempts = identityUser.AccessFailedCount;
483483
}
484484

485+
if (user.IsApproved != identityUser.IsApproved)
486+
{
487+
anythingChanged = true;
488+
user.IsApproved = identityUser.IsApproved;
489+
}
490+
485491
if (user.IsLockedOut != identityUser.IsLockedOut)
486492
{
487493
anythingChanged = true;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Identity;
7+
using Microsoft.Extensions.Options;
8+
using NUnit.Framework;
9+
using Umbraco.Cms.Core.Configuration.Models;
10+
using Umbraco.Cms.Core.Mapping;
11+
using Umbraco.Cms.Core.Models.Membership;
12+
using Umbraco.Cms.Core.Scoping;
13+
using Umbraco.Cms.Core.Security;
14+
using Umbraco.Cms.Core.Services;
15+
using Umbraco.Cms.Tests.Common.Testing;
16+
using Umbraco.Cms.Tests.Integration.Testing;
17+
18+
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Security
19+
{
20+
[TestFixture]
21+
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
22+
public class BackOfficeUserStoreTests : UmbracoIntegrationTest
23+
{
24+
private IUserService UserService => GetRequiredService<IUserService>();
25+
private IEntityService EntityService => GetRequiredService<IEntityService>();
26+
private IExternalLoginService ExternalLoginService => GetRequiredService<IExternalLoginService>();
27+
private IUmbracoMapper UmbracoMapper => GetRequiredService<IUmbracoMapper>();
28+
private ILocalizedTextService TextService => GetRequiredService<ILocalizedTextService>();
29+
30+
private BackOfficeUserStore GetUserStore()
31+
=> new BackOfficeUserStore(
32+
ScopeProvider,
33+
UserService,
34+
EntityService,
35+
ExternalLoginService,
36+
Options.Create(GlobalSettings),
37+
UmbracoMapper,
38+
new BackOfficeErrorDescriber(TextService),
39+
AppCaches);
40+
41+
[Test]
42+
public async Task Can_Persist_Is_Approved()
43+
{
44+
var userStore = GetUserStore();
45+
var user = new BackOfficeIdentityUser(GlobalSettings, 1, new List<IReadOnlyUserGroup>())
46+
{
47+
Name = "Test",
48+
Email = "[email protected]",
49+
UserName = "[email protected]"
50+
};
51+
IdentityResult createResult = await userStore.CreateAsync(user);
52+
Assert.IsTrue(createResult.Succeeded);
53+
Assert.IsFalse(user.IsApproved);
54+
55+
// update
56+
user.IsApproved = true;
57+
var saveResult = await userStore.UpdateAsync(user);
58+
Assert.IsTrue(saveResult.Succeeded);
59+
Assert.IsTrue(user.IsApproved);
60+
61+
// get get
62+
user = await userStore.FindByIdAsync(user.Id);
63+
Assert.IsTrue(user.IsApproved);
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)