This editor only has access to one page in Epi and doesnt't care about the rest of them. Let's help out!
Too long; Didn't read? Gist with full code.
The solution is an adaptation of this helpful post by Mark Hall.
Basics
Epi calls GetContent()
every time content with subcontent is expanded. Only one level expands and by default everything is listed out, with a lock-icon on the restricted content.
We want to override this and put in some filters to check that the current user has access to the content:
FilterAccess.QueryDistinctAccessEdit(content, AccessLevel.Edit)
FilterAccess.QueryDistinctAccessEdit(content, AccessLevel.Create)
Whitelist
Niklas Lords asks what happens if you have access to a child, but not the parent.
This is the real problem. Since only one level expands for each GetContent()
, there is no way to know what's below the next level except doing further calls, which is bad for performance.
We will create a less flexible solution by specifying content types or IDs that should be visible regardless of access level, in this case root (1), startpage and the store page parent.
private List<int> WhiteListedContentIds => new List<int> { 1 };
private List<Type> WhiteListedTypes => new List<Type> { typeof(DemoHomePage), typeof(LocationListPage) };
Blocks / Media / Commerce
The editor should still have read access to content in the assets pane. Let's make a rule that only applies the filter to pages.
The child types of the content you expanded come as parameters, and if none of them are assignable to PageData
we don't need to filter. return base.GetContent()
.
private List<Type> OnlyFilterTheseTypes => new List<Type> { typeof(PageData) };
Add BlockData
, MediaData
or CatalogContentBase
if you want them filtered as well.
Full code can be found in the Gist.