forked from umbraco/Umbraco-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User manager related updates (umbraco#9935)
* Only allow not-admins to assign groups they have themselves * Only admins is allowed to change password of other admins * Fixed issue with deep clone of UserGroup. The Allowed sections was not cloned. This resulted in the allowed sections of the object stored in cache was updated, everytime we changed the allowed sections on an object cloned from the cache. Even if we did not save it. * Only Admins are allowed to add sections to a user group, that they don't have access to themselves * Align backend code with UI. User managers that is are not admin, can only assign the same groups new users, that they have themselves. * Make existingGroupAliases and empty array when creating a new user Co-authored-by: Mole <[email protected]>
- Loading branch information
1 parent
4a8a73f
commit 745014a
Showing
10 changed files
with
177 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using Umbraco.Core.Composing; | ||
using Umbraco.Core.Models.Membership; | ||
using Umbraco.Core.Serialization; | ||
using Umbraco.Tests.TestHelpers; | ||
|
||
namespace Umbraco.Tests.Models | ||
{ | ||
[TestFixture] | ||
public class UserGroupTests | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
Current.Reset(); | ||
Current.UnlockConfigs(); | ||
Current.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); | ||
Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); | ||
} | ||
|
||
[Test] | ||
|
||
public void Can_Deep_Clone() | ||
{ | ||
var item = Build(); | ||
|
||
var clone = (UserGroup)item.DeepClone(); | ||
|
||
Assert.AreNotSame(clone, item); | ||
Assert.AreEqual(clone, item); | ||
|
||
Assert.AreEqual(clone.AllowedSections.Count(), item.AllowedSections.Count()); | ||
Assert.AreNotSame(clone.AllowedSections, item.AllowedSections); | ||
|
||
//Verify normal properties with reflection | ||
var allProps = clone.GetType().GetProperties(); | ||
foreach (var propertyInfo in allProps) | ||
{ | ||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Can_Serialize_Without_Error() | ||
{ | ||
var ss = new SerializationService(new JsonNetSerializer()); | ||
|
||
var item = Build(); | ||
|
||
var result = ss.ToStream(item); | ||
var json = result.ResultStream.ToJsonString(); | ||
Debug.Print(json); | ||
} | ||
|
||
private UserGroup Build() | ||
{ | ||
var item = new UserGroup() | ||
{ | ||
Id = 3, | ||
Key = Guid.NewGuid(), | ||
UpdateDate = DateTime.Now, | ||
CreateDate = DateTime.Now, | ||
Name = "Test", | ||
Alias = "alias", | ||
Icon = "icon", | ||
Permissions = new []{"a", "b", "c"}, | ||
DeleteDate = null, | ||
StartContentId = null, | ||
StartMediaId = null, | ||
}; | ||
item.AddAllowedSection("A"); | ||
item.AddAllowedSection("B"); | ||
|
||
return item; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.