diff --git a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs index c4654cc6e2..0bdd6e1ee4 100644 --- a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs @@ -176,7 +176,9 @@ namespace Umbraco.Core.Persistence.Repositories } else { - //we need to manually update this record because it has a composite key + //we need to manually update this record because it has a composite key, HOWEVER currently we don't really expose + // a way to update the value so this will never be hit. If a section needs to be 'updated' then the developer needs + // to remove and then add a different one. Database.Update("SET app=@Section WHERE app=@Section AND " + SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName("user") + "=@UserId", new { Section = sectionDto.AppAlias, UserId = sectionDto.UserId }); } diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs index 333c051413..65ce5e9ec5 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs @@ -364,6 +364,30 @@ namespace Umbraco.Tests.Persistence.Repositories Assert.IsTrue(result[1].AllowedSections.Contains("media")); } + [Test] + public void Can_Update_Section_For_User() + { + // Arrange + var provider = new PetaPocoUnitOfWorkProvider(); + var unitOfWork = provider.GetUnitOfWork(); + var repository = RepositoryResolver.Current.ResolveByType(unitOfWork); + var users = CreateAndCommitMultipleUsers(repository, unitOfWork); + + // Act + + users[0].RemoveAllowedSection("content"); + users[0].AddAllowedSection("settings"); + + repository.AddOrUpdate(users[0]); + unitOfWork.Commit(); + + // Assert + var result = repository.Get((int)users[0].Id); + Assert.AreEqual(2, result.AllowedSections.Count()); + Assert.IsTrue(result.AllowedSections.Contains("settings")); + Assert.IsTrue(result.AllowedSections.Contains("media")); + } + private IUser[] CreateAndCommitMultipleUsers(IUserRepository repository, IUnitOfWork unitOfWork) { var user1 = MockedUser.CreateUser(CreateAndCommitUserType(), "1");