diff --git a/src/Umbraco.Core/Models/Membership/IUserGroup.cs b/src/Umbraco.Core/Models/Membership/IUserGroup.cs
index 8e9f862910..336caa4c47 100644
--- a/src/Umbraco.Core/Models/Membership/IUserGroup.cs
+++ b/src/Umbraco.Core/Models/Membership/IUserGroup.cs
@@ -28,5 +28,7 @@ namespace Umbraco.Core.Models.Membership
void RemoveAllowedSection(string sectionAlias);
void AddAllowedSection(string sectionAlias);
+
+ void ClearAllowedSections();
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Models/Membership/UserGroup.cs b/src/Umbraco.Core/Models/Membership/UserGroup.cs
index ea5f891037..885a7cbe55 100644
--- a/src/Umbraco.Core/Models/Membership/UserGroup.cs
+++ b/src/Umbraco.Core/Models/Membership/UserGroup.cs
@@ -93,5 +93,10 @@ namespace Umbraco.Core.Models.Membership
_sectionCollection.Add(sectionAlias);
}
}
+
+ public void ClearAllowedSections()
+ {
+ _sectionCollection.Clear();
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
index 1a544cc32e..0a244d30ef 100644
--- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs
@@ -780,15 +780,15 @@ order by umbracoNode.level, umbracoNode.parentID, umbracoNode.sortOrder";
}
///
- /// Assigns a single permission to the current content item for the specified user ids
+ /// Assigns a single permission to the current content item for the specified user group ids
///
///
///
- ///
- public void AssignEntityPermission(IContent entity, char permission, IEnumerable userIds)
+ ///
+ public void AssignEntityPermission(IContent entity, char permission, IEnumerable groupIds)
{
var repo = new PermissionRepository(UnitOfWork, _cacheHelper, SqlSyntax);
- repo.AssignEntityPermission(entity, permission, userIds);
+ repo.AssignEntityPermission(entity, permission, groupIds);
}
public IEnumerable GetPermissionsForEntity(int entityId)
diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs
index 5f74a21d7a..a0c379666b 100644
--- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs
@@ -48,12 +48,12 @@ namespace Umbraco.Core.Persistence.Repositories
IEnumerable GetByPublishedVersion(IQuery query);
///
- /// Assigns a single permission to the current content item for the specified user ids
+ /// Assigns a single permission to the current content item for the specified user group ids
///
///
///
- ///
- void AssignEntityPermission(IContent entity, char permission, IEnumerable userIds);
+ ///
+ void AssignEntityPermission(IContent entity, char permission, IEnumerable groupIds);
///
/// Gets the list of permissions for the content item
diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs
index 8aa7030a8f..b88678ac73 100644
--- a/src/Umbraco.Core/Services/ContentService.cs
+++ b/src/Umbraco.Core/Services/ContentService.cs
@@ -111,13 +111,13 @@ namespace Umbraco.Core.Services
///
///
///
- ///
- public void AssignContentPermission(IContent entity, char permission, IEnumerable userIds)
+ ///
+ public void AssignContentPermission(IContent entity, char permission, IEnumerable groupIds)
{
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateContentRepository(uow))
{
- repository.AssignEntityPermission(entity, permission, userIds);
+ repository.AssignEntityPermission(entity, permission, groupIds);
}
}
diff --git a/src/Umbraco.Core/Services/IContentService.cs b/src/Umbraco.Core/Services/IContentService.cs
index 6ee384c413..d2f277dfbb 100644
--- a/src/Umbraco.Core/Services/IContentService.cs
+++ b/src/Umbraco.Core/Services/IContentService.cs
@@ -123,12 +123,12 @@ namespace Umbraco.Core.Services
void ReplaceContentPermissions(EntityPermissionSet permissionSet);
///
- /// Assigns a single permission to the current content item for the specified user ids
+ /// Assigns a single permission to the current content item for the specified user group ids
///
///
///
- ///
- void AssignContentPermission(IContent entity, char permission, IEnumerable userIds);
+ ///
+ void AssignContentPermission(IContent entity, char permission, IEnumerable groupIds);
///
/// Gets the list of permissions for the content item
diff --git a/src/Umbraco.Core/Services/IMembershipUserService.cs b/src/Umbraco.Core/Services/IMembershipUserService.cs
index 63dc4db37c..4143a871bf 100644
--- a/src/Umbraco.Core/Services/IMembershipUserService.cs
+++ b/src/Umbraco.Core/Services/IMembershipUserService.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using Umbraco.Core.Models.Membership;
namespace Umbraco.Core.Services
diff --git a/src/Umbraco.Core/Services/SectionService.cs b/src/Umbraco.Core/Services/SectionService.cs
index 02cc3f874b..b12412b5f2 100644
--- a/src/Umbraco.Core/Services/SectionService.cs
+++ b/src/Umbraco.Core/Services/SectionService.cs
@@ -249,7 +249,7 @@ namespace Umbraco.Core.Services
{
//delete the assigned applications
_uowProvider.GetUnitOfWork().Database.Execute(
- "delete from umbracoUser2App where app = @appAlias",
+ "delete from umbracoUserGroup2App where app = @appAlias",
new { appAlias = section.Alias });
//delete the assigned trees
diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs
index 66aad86dbd..45dc0c921d 100644
--- a/src/Umbraco.Core/Services/UserService.cs
+++ b/src/Umbraco.Core/Services/UserService.cs
@@ -878,9 +878,12 @@ namespace Umbraco.Core.Services
var result = new List(explicitPermissions);
// If no permissions are assigned to a particular node then we will fill in those permissions with the group's defaults
- var missingIds = nodeIds.Except(result.Select(x => x.EntityId));
- result.AddRange(missingIds
- .Select(i => new EntityPermission(i, group.Permissions.ToArray())));
+ var missingIds = nodeIds.Except(result.Select(x => x.EntityId)).ToList();
+ if (missingIds.Any())
+ {
+ result.AddRange(missingIds
+ .Select(i => new EntityPermission(i, group.Permissions.ToArray())));
+ }
return result;
}
diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs
index abcb5b3d6a..e9b86ee2d3 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs
@@ -1,27 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text.RegularExpressions;
using System.Xml.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
-using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
-using Umbraco.Core.Persistence;
-
-using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
-using umbraco.editorControls.tinyMCE3;
-using umbraco.interfaces;
-using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
namespace Umbraco.Tests.Persistence.Repositories
@@ -67,6 +59,11 @@ namespace Umbraco.Tests.Persistence.Repositories
return repository;
}
+ private UserGroupRepository CreateUserGroupRepository(IDatabaseUnitOfWork unitOfWork)
+ {
+ return new UserGroupRepository(unitOfWork, CacheHelper, Logger, SqlSyntax);
+ }
+
[Test]
public void Rebuild_Xml_Structures_With_Non_Latest_Version()
{
@@ -299,7 +296,14 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
- ContentTypeRepository contentTypeRepository;
+ using (var repository = CreateUserGroupRepository(unitOfWork))
+ {
+ var userGroup = MockedUserGroup.CreateUserGroup("1");
+ repository.AddOrUpdate(userGroup);
+ unitOfWork.Commit();
+ }
+
+ ContentTypeRepository contentTypeRepository;
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage");
@@ -313,7 +317,7 @@ namespace Umbraco.Tests.Persistence.Repositories
unitOfWork.Commit();
// Act
- repository.AssignEntityPermission(parentPage, 'A', new int[] { 0 });
+ repository.AssignEntityPermission(parentPage, 'A', new [] { 1 });
var childPage = MockedContent.CreateSimpleContent(contentType, "child", parentPage);
repository.AddOrUpdate(childPage);
unitOfWork.Commit();
diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs
index a29aeb8c29..6a2412bc63 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/UserGroupRepositoryTest.cs
@@ -325,18 +325,24 @@ namespace Umbraco.Tests.Persistence.Repositories
// Act
//add and remove a few times, this tests the internal collection
+ groups[0].ClearAllowedSections();
+ groups[0].AddAllowedSection("content");
+ groups[0].AddAllowedSection("media");
+ groups[0].RemoveAllowedSection("content");
+ groups[0].AddAllowedSection("content");
groups[0].AddAllowedSection("settings");
- groups[0].AddAllowedSection("settings");
- groups[0].RemoveAllowedSection("settings");
- groups[0].AddAllowedSection("settings");
-
- groups[1].AddAllowedSection("developer");
//add the same even though it's already there
- groups[2].AddAllowedSection("content");
+ groups[0].AddAllowedSection("content");
+
+ groups[1].ClearAllowedSections();
+ groups[1].AddAllowedSection("developer");
+
+ groups[2].ClearAllowedSections();
repository.AddOrUpdate(groups[0]);
repository.AddOrUpdate(groups[1]);
+ repository.AddOrUpdate(groups[2]);
unitOfWork.Commit();
// Assert
@@ -345,13 +351,9 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.IsTrue(result[0].AllowedSections.Contains("content"));
Assert.IsTrue(result[0].AllowedSections.Contains("media"));
Assert.IsTrue(result[0].AllowedSections.Contains("settings"));
- Assert.AreEqual(3, result[1].AllowedSections.Count());
- Assert.IsTrue(result[1].AllowedSections.Contains("content"));
- Assert.IsTrue(result[1].AllowedSections.Contains("media"));
+ Assert.AreEqual(1, result[1].AllowedSections.Count());
Assert.IsTrue(result[1].AllowedSections.Contains("developer"));
- Assert.AreEqual(2, result[2].AllowedSections.Count());
- Assert.IsTrue(result[1].AllowedSections.Contains("content"));
- Assert.IsTrue(result[1].AllowedSections.Contains("media"));
+ Assert.AreEqual(0, result[2].AllowedSections.Count());
}
}
@@ -390,23 +392,23 @@ namespace Umbraco.Tests.Persistence.Repositories
var unitOfWork = provider.GetUnitOfWork();
using (var repository = CreateRepository(unitOfWork))
{
- var user1 = MockedUserGroup.CreateUserGroup("1", new[] { "media" });
- var user2 = MockedUserGroup.CreateUserGroup("2", new[] { "settings" });
- var user3 = MockedUserGroup.CreateUserGroup("3", new[] { "settings" });
+ var user1 = MockedUserGroup.CreateUserGroup("1", allowedSections: new[] { "test1" });
+ var user2 = MockedUserGroup.CreateUserGroup("2", allowedSections: new[] { "test2" });
+ var user3 = MockedUserGroup.CreateUserGroup("3", allowedSections: new[] { "test1" });
repository.AddOrUpdate(user1);
repository.AddOrUpdate(user2);
repository.AddOrUpdate(user3);
unitOfWork.Commit();
// Act
-
- var groups = repository.GetGroupsAssignedToSection("test");
+ var groups = repository.GetGroupsAssignedToSection("test1");
// Assert
Assert.AreEqual(2, groups.Count());
var names = groups.Select(x => x.Name).ToArray();
- Assert.IsTrue(names.Contains("TestGroup1"));
- Assert.IsTrue(names.Contains("TestGroup3"));
+ Assert.IsTrue(names.Contains("TestUserGroup1"));
+ Assert.IsFalse(names.Contains("TestUserGroup2"));
+ Assert.IsTrue(names.Contains("TestUserGroup3"));
}
}
diff --git a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs
index d3ba021294..45c21e82c3 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs
@@ -30,10 +30,13 @@ namespace Umbraco.Tests.Persistence.Repositories
private UserRepository CreateRepository(IDatabaseUnitOfWork unitOfWork)
{
- var repository = new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax);
- return repository;
+ return new UserRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax);
}
+ private UserGroupRepository CreateUserGroupRepository(IDatabaseUnitOfWork unitOfWork)
+ {
+ return new UserGroupRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of(), SqlSyntax);
+ }
[Test]
public void Can_Perform_Add_On_UserRepository()
@@ -43,7 +46,6 @@ namespace Umbraco.Tests.Persistence.Repositories
var unitOfWork = provider.GetUnitOfWork();
using (var repository = CreateRepository(unitOfWork))
{
-
var user = MockedUser.CreateUser();
// Act
@@ -63,7 +65,6 @@ namespace Umbraco.Tests.Persistence.Repositories
var unitOfWork = provider.GetUnitOfWork();
using (var repository = CreateRepository(unitOfWork))
{
-
var user1 = MockedUser.CreateUser("1");
var use2 = MockedUser.CreateUser("2");
@@ -107,17 +108,14 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
using (var repository = CreateRepository(unitOfWork))
+ using (var userGroupRepository = CreateUserGroupRepository(unitOfWork))
{
- var user = MockedUser.CreateUser();
- repository.AddOrUpdate(user);
- unitOfWork.Commit();
+ var user = CreateAndCommitUserWithGroup(repository, userGroupRepository, unitOfWork);
// Act
var resolved = (User)repository.Get((int)user.Id);
resolved.Name = "New Name";
- //the db column is not used, default permissions are taken from the user type's permissions, this is a getter only
- //resolved.DefaultPermissions = "ZYX";
resolved.Language = "fr";
resolved.IsApproved = false;
resolved.RawPasswordValue = "new";
@@ -134,7 +132,6 @@ namespace Umbraco.Tests.Persistence.Repositories
// Assert
Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id));
Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name));
- //Assert.That(updatedItem.DefaultPermissions, Is.EqualTo(resolved.DefaultPermissions));
Assert.That(updatedItem.Language, Is.EqualTo(resolved.Language));
Assert.That(updatedItem.IsApproved, Is.EqualTo(resolved.IsApproved));
Assert.That(updatedItem.RawPasswordValue, Is.EqualTo(resolved.RawPasswordValue));
@@ -143,7 +140,8 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.That(updatedItem.StartMediaId, Is.EqualTo(resolved.StartMediaId));
Assert.That(updatedItem.Email, Is.EqualTo(resolved.Email));
Assert.That(updatedItem.Username, Is.EqualTo(resolved.Username));
- Assert.That(updatedItem.AllowedSections.Count(), Is.EqualTo(1));
+ Assert.That(updatedItem.AllowedSections.Count(), Is.EqualTo(2));
+ Assert.IsTrue(updatedItem.AllowedSections.Contains("content"));
Assert.IsTrue(updatedItem.AllowedSections.Contains("media"));
}
}
@@ -213,13 +211,12 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
using (var repository = CreateRepository(unitOfWork))
+ using (var userGroupRepository = CreateUserGroupRepository(unitOfWork))
{
- var user = MockedUser.CreateUser();
- repository.AddOrUpdate(user);
- unitOfWork.Commit();
+ var user = CreateAndCommitUserWithGroup(repository, userGroupRepository, unitOfWork);
// Act
- var updatedItem = repository.Get((int) user.Id);
+ var updatedItem = repository.Get((int)user.Id);
// Assert
AssertPropertyValues(updatedItem, user);
@@ -339,6 +336,21 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.IsTrue(updatedItem.AllowedSections.Contains("content"));
}
+ private static User CreateAndCommitUserWithGroup(IUserRepository repository, IUserGroupRepository userGroupRepository, IDatabaseUnitOfWork unitOfWork)
+ {
+ var group = MockedUserGroup.CreateUserGroup();
+ userGroupRepository.AddOrUpdate(@group);
+ unitOfWork.Commit();
+
+ var user = MockedUser.CreateUser();
+ repository.AddOrUpdate(user);
+ unitOfWork.Commit();
+
+ userGroupRepository.AddUsersToGroup(@group.Id, new[] { user.Id });
+ unitOfWork.Commit();
+ return user;
+ }
+
private IUser[] CreateAndCommitMultipleUsers(IUserRepository repository, IUnitOfWork unitOfWork)
{
var user1 = MockedUser.CreateUser("1");
diff --git a/src/Umbraco.Tests/Services/SectionServiceTests.cs b/src/Umbraco.Tests/Services/SectionServiceTests.cs
index a300d76e60..5c51233892 100644
--- a/src/Umbraco.Tests/Services/SectionServiceTests.cs
+++ b/src/Umbraco.Tests/Services/SectionServiceTests.cs
@@ -29,34 +29,20 @@ namespace Umbraco.Tests.Services
ServiceContext.SectionService.MakeNew("Settings", "settings", "icon-settings");
ServiceContext.SectionService.MakeNew("Developer", "developer", "icon-developer");
}
-
[Test]
public void SectionService_Can_Get_Allowed_Sections_For_User()
{
// Arrange
- var user = CreateUser();
+ var user = CreateTestUser();
// Act
var result = ServiceContext.SectionService.GetAllowedSections(user.Id).ToList();
// Assert
- Assert.AreEqual(2, result.Count);
+ Assert.AreEqual(3, result.Count);
}
- [Test]
- public void SectionService_Can_Get_Allowed_Sections_For_User_With_Groups()
- {
- // Arrange
- var user = CreateUser(true);
-
- // Act
- var result = ServiceContext.SectionService.GetAllowedSections(user.Id).ToList();
-
- // Assert
- Assert.AreEqual(4, result.Count);
- }
-
- private IUser CreateUser(bool withGroups = false)
+ private IUser CreateTestUser()
{
var user = new User
{
@@ -66,26 +52,23 @@ namespace Umbraco.Tests.Services
};
ServiceContext.UserService.Save(user, false);
- if (withGroups)
+ var userGroupA = new UserGroup
{
- var userGroupA = new UserGroup
- {
- Alias = "GroupA",
- Name = "Group A"
- };
- userGroupA.AddAllowedSection("media");
- userGroupA.AddAllowedSection("settings");
- ServiceContext.UserService.SaveUserGroup(userGroupA, true, new[] { user.Id }, false);
+ Alias = "GroupA",
+ Name = "Group A"
+ };
+ userGroupA.AddAllowedSection("media");
+ userGroupA.AddAllowedSection("settings");
+ ServiceContext.UserService.SaveUserGroup(userGroupA, true, new[] { user.Id }, false);
- var userGroupB = new UserGroup
- {
- Alias = "GroupB",
- Name = "Group B"
- };
- userGroupB.AddAllowedSection("settings");
- userGroupB.AddAllowedSection("developer");
- ServiceContext.UserService.SaveUserGroup(userGroupB, true, new[] { user.Id }, false);
- }
+ var userGroupB = new UserGroup
+ {
+ Alias = "GroupB",
+ Name = "Group B"
+ };
+ userGroupB.AddAllowedSection("settings");
+ userGroupB.AddAllowedSection("developer");
+ ServiceContext.UserService.SaveUserGroup(userGroupB, true, new[] { user.Id }, false);
return ServiceContext.UserService.GetUserById(user.Id);
}
diff --git a/src/Umbraco.Tests/Services/UserServiceTests.cs b/src/Umbraco.Tests/Services/UserServiceTests.cs
index b8f23cee6c..795088f48f 100644
--- a/src/Umbraco.Tests/Services/UserServiceTests.cs
+++ b/src/Umbraco.Tests/Services/UserServiceTests.cs
@@ -39,7 +39,8 @@ namespace Umbraco.Tests.Services
{
// Arrange
var userService = ServiceContext.UserService;
- var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com");
+ var user = CreateTestUser();
+
var contentType = MockedContentTypes.CreateSimpleContentType();
ServiceContext.ContentTypeService.Save(contentType);
var content = new[]
@@ -65,7 +66,8 @@ namespace Umbraco.Tests.Services
{
// Arrange
var userService = ServiceContext.UserService;
- var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com");
+ var user = CreateTestUser();
+
var contentType = MockedContentTypes.CreateSimpleContentType();
ServiceContext.ContentTypeService.Save(contentType);
var content = new[]
@@ -75,14 +77,12 @@ namespace Umbraco.Tests.Services
MockedContent.CreateSimpleContent(contentType)
};
ServiceContext.ContentService.Save(content);
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionBrowse.Instance.Letter, new int[] { user.Id });
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionDelete.Instance.Letter, new int[] { user.Id });
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionMove.Instance.Letter, new int[] { user.Id });
-
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(1), ActionBrowse.Instance.Letter, new int[] { user.Id });
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(1), ActionDelete.Instance.Letter, new int[] { user.Id });
-
- ServiceContext.ContentService.AssignContentPermission(content.ElementAt(2), ActionBrowse.Instance.Letter, new int[] { user.Id });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionBrowse.Instance.Letter, new int[] { 1 });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionDelete.Instance.Letter, new int[] { 1 });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(0), ActionMove.Instance.Letter, new int[] { 1 });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(1), ActionBrowse.Instance.Letter, new int[] { 1 });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(1), ActionDelete.Instance.Letter, new int[] { 1 });
+ ServiceContext.ContentService.AssignContentPermission(content.ElementAt(2), ActionBrowse.Instance.Letter, new int[] { 1 });
// Act
var permissions = userService.GetPermissions(user, content.ElementAt(0).Id, content.ElementAt(1).Id, content.ElementAt(2).Id);
@@ -346,6 +346,7 @@ namespace Umbraco.Tests.Services
{
Id = 1,
Alias = "Group1",
+ Name = "Group 1"
};
userGroup.AddAllowedSection("content");
userGroup.AddAllowedSection("mediat");
@@ -390,11 +391,13 @@ namespace Umbraco.Tests.Services
{
Id = 1,
Alias = "Group1",
+ Name = "Group 2"
};
var userGroup2 = new UserGroup
{
Id = 2,
Alias = "Group2",
+ Name = "Group 2"
};
ServiceContext.UserService.SaveUserGroup(userGroup1);
ServiceContext.UserService.SaveUserGroup(userGroup2);
@@ -422,16 +425,19 @@ namespace Umbraco.Tests.Services
{
Id = 1,
Alias = "Group1",
+ Name = "Group 1"
};
var userGroup2 = new UserGroup
{
Id = 2,
Alias = "Group2",
+ Name = "Group 2"
};
var userGroup3 = new UserGroup
{
- Id = 2,
+ Id = 3,
Alias = "Group3",
+ Name = "Group 3"
};
ServiceContext.UserService.SaveUserGroup(userGroup1);
ServiceContext.UserService.SaveUserGroup(userGroup2);
@@ -496,7 +502,7 @@ namespace Umbraco.Tests.Services
public void Get_User_By_Username()
{
// Arrange
- var originalUser = (User)ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com");
+ var originalUser = CreateTestUser();
// Act
@@ -516,5 +522,25 @@ namespace Umbraco.Tests.Services
Assert.That(updatedItem.Username, Is.EqualTo(originalUser.Username));
Assert.That(updatedItem.AllowedSections.Count(), Is.EqualTo(2));
}
+
+ private IUser CreateTestUser()
+ {
+ var userGroup = new UserGroup
+ {
+ Id = 1,
+ Alias = "testGroup",
+ Name = "Test Group",
+ Permissions = "ABCDEFGHIJ1234567".ToCharArray().Select(x => x.ToString())
+ };
+ ServiceContext.UserService.SaveUserGroup(userGroup);
+ ServiceContext.UserService.AddSectionToAllUserGroups("content", 1);
+ ServiceContext.UserService.AddSectionToAllUserGroups("media", 1);
+
+ var user = ServiceContext.UserService.CreateUserWithIdentity("test1", "test1@test.com");
+ user.AddGroup(userGroup);
+ user.SetGroupsLoaded();
+ ServiceContext.UserService.Save(user);
+ return user;
+ }
}
}
diff --git a/src/Umbraco.Tests/TestHelpers/Entities/MockedUserGroup.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedUserGroup.cs
index f266f55332..920c84f3c3 100644
--- a/src/Umbraco.Tests/TestHelpers/Entities/MockedUserGroup.cs
+++ b/src/Umbraco.Tests/TestHelpers/Entities/MockedUserGroup.cs
@@ -4,14 +4,29 @@ namespace Umbraco.Tests.TestHelpers.Entities
{
public class MockedUserGroup
{
- internal static UserGroup CreateUserGroup(string suffix = "", string[] permissions = null)
+ internal static UserGroup CreateUserGroup(string suffix = "", string[] permissions = null, string[] allowedSections = null)
{
- return new UserGroup()
+ var group = new UserGroup
+ {
+ Alias = "testUserGroup" + suffix,
+ Name = "TestUserGroup" + suffix,
+ Permissions = permissions ?? new[] { "A", "B", "C" }
+ };
+
+ if (allowedSections == null)
+ {
+ group.AddAllowedSection("content");
+ group.AddAllowedSection("media");
+ }
+ else
+ {
+ foreach (var allowedSection in allowedSections)
{
- Alias = "testUserGroup" + suffix,
- Name = "TestUserGroup" + suffix,
- Permissions = permissions ?? new[]{"A", "B", "C"}
- };
+ group.AddAllowedSection(allowedSection);
+ }
+ }
+
+ return group;
}
}
}
\ No newline at end of file