-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix pagination for users restricted by start nodes #18907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
74d43a3
Fix pagination for users restricted by start nodes
kjac 2607a58
Default implementation to avoid breakage
kjac 56e1d68
Merge branch 'v15/dev' into v15/fix/start-nodes-pagination
kjac 2af7aec
Review comments
kjac 2b119a2
Fix failing test
kjac 642ccf7
Add media start node tests
kjac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
85 changes: 85 additions & 0 deletions
85
...n/ManagementApi/Services/UserStartNodeEntitiesServiceMediaTests.RootUserAccessEntities.cs
This file contains hidden or 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,85 @@ | ||
using NUnit.Framework; | ||
using Umbraco.Cms.Core.Models; | ||
|
||
namespace Umbraco.Cms.Tests.Integration.ManagementApi.Services; | ||
|
||
public partial class UserStartNodeEntitiesServiceMediaTests | ||
{ | ||
[Test] | ||
public async Task RootUserAccessEntities_FirstAndLastRoot_YieldsBoth_AsAllowed() | ||
{ | ||
var contentStartNodeIds = await CreateUserAndGetStartNodeIds(_mediaByName["1"].Id, _mediaByName["5"].Id); | ||
|
||
var roots = UserStartNodeEntitiesService | ||
.RootUserAccessEntities( | ||
UmbracoObjectTypes.Media, | ||
contentStartNodeIds) | ||
.ToArray(); | ||
|
||
// expected total is 2, because only two items at root ("1" amd "10") are allowed | ||
Assert.AreEqual(2, roots.Length); | ||
Assert.Multiple(() => | ||
{ | ||
// first and last content items are the ones allowed | ||
Assert.AreEqual(_mediaByName["1"].Key, roots[0].Entity.Key); | ||
Assert.AreEqual(_mediaByName["5"].Key, roots[1].Entity.Key); | ||
|
||
// explicitly verify the entity sort order, both so we know sorting works, | ||
// and so we know it's actually the first and last item at root | ||
Assert.AreEqual(0, roots[0].Entity.SortOrder); | ||
Assert.AreEqual(4, roots[1].Entity.SortOrder); | ||
|
||
// both are allowed (they are the actual start nodes) | ||
Assert.IsTrue(roots[0].HasAccess); | ||
Assert.IsTrue(roots[1].HasAccess); | ||
}); | ||
} | ||
|
||
[Test] | ||
public async Task RootUserAccessEntities_ChildrenAsStartNode_YieldsChildRoots_AsNotAllowed() | ||
{ | ||
var contentStartNodeIds = await CreateUserAndGetStartNodeIds(_mediaByName["1-3"].Id, _mediaByName["3-3"].Id, _mediaByName["5-3"].Id); | ||
|
||
var roots = UserStartNodeEntitiesService | ||
.RootUserAccessEntities( | ||
UmbracoObjectTypes.Media, | ||
contentStartNodeIds) | ||
.ToArray(); | ||
|
||
Assert.AreEqual(3, roots.Length); | ||
Assert.Multiple(() => | ||
{ | ||
// the three start nodes are the children of the "1", "3" and "5" roots, respectively, so these are expected as roots | ||
Assert.AreEqual(_mediaByName["1"].Key, roots[0].Entity.Key); | ||
Assert.AreEqual(_mediaByName["3"].Key, roots[1].Entity.Key); | ||
Assert.AreEqual(_mediaByName["5"].Key, roots[2].Entity.Key); | ||
|
||
// all are disallowed - only the children (the actual start nodes) are allowed | ||
Assert.IsTrue(roots.All(r => r.HasAccess is false)); | ||
}); | ||
} | ||
|
||
[Test] | ||
public async Task RootUserAccessEntities_GrandchildrenAsStartNode_YieldsGrandchildRoots_AsNotAllowed() | ||
{ | ||
var contentStartNodeIds = await CreateUserAndGetStartNodeIds(_mediaByName["1-2-3"].Id, _mediaByName["2-3-4"].Id, _mediaByName["3-4-5"].Id); | ||
|
||
var roots = UserStartNodeEntitiesService | ||
.RootUserAccessEntities( | ||
UmbracoObjectTypes.Media, | ||
contentStartNodeIds) | ||
.ToArray(); | ||
|
||
Assert.AreEqual(3, roots.Length); | ||
Assert.Multiple(() => | ||
{ | ||
// the three start nodes are the grandchildren of the "1", "2" and "3" roots, respectively, so these are expected as roots | ||
Assert.AreEqual(_mediaByName["1"].Key, roots[0].Entity.Key); | ||
Assert.AreEqual(_mediaByName["2"].Key, roots[1].Entity.Key); | ||
Assert.AreEqual(_mediaByName["3"].Key, roots[2].Entity.Key); | ||
|
||
// all are disallowed - only the grandchildren (the actual start nodes) are allowed | ||
Assert.IsTrue(roots.All(r => r.HasAccess is false)); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.