Skip to content
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

Fix AllRoles field #2045

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/ContentRepository/Fields/AllRolesField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using SenseNet.Configuration;
using SenseNet.ContentRepository.Schema;
using SenseNet.ContentRepository.Storage;
using SenseNet.ContentRepository.Storage.Security;
using Node = SenseNet.ContentRepository.Storage.Node;

namespace SenseNet.ContentRepository.Fields
{
Expand All @@ -20,9 +20,21 @@ protected override void ImportData(XmlNode fieldNode, ImportContext context)

public override object GetData()
{
// this method will load only containers that the current user has permissions for
return Node.LoadNodes(Providers.Instance.SecurityHandler.SecurityContext
var thisPath = this.Content.Path;
var orgUnitNodeType = Providers.Instance.StorageSchema.NodeTypes[nameof(OrganizationalUnit)];

// loads only containers that the current user has permissions for
var allParents = Node.LoadNodes(Providers.Instance.SecurityHandler.SecurityContext
.GetParentGroups(this.Content.Id, false)).ToArray();

// valid item is all ancestors or any node that is not an OrganizationalUnit
var filtered = allParents
.Where(n => !n.NodeType.IsInstaceOfOrDerivedFrom(orgUnitNodeType) ||
RepositoryPath.IsInTree(thisPath, n.Path))
.ToArray();

return filtered;

}
}
}