November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi, Henrik,
Can you share the code that doesn't filter out the recycled pages?
BR,
Marija
This is the code for the specific case we are having problems with. I have exaggerated the filtering just to see if any of these work but no luck so far.
var specifications =
ContentRepository.GetItems(currentspecs.Select(x => x.SpecificationReference).Distinct(),
LanguageSelector.AutoDetect(true)).OfType<FeaturePage>();
FilterForVisitor.Filter(specifications);
var subcategories = ContentRepository.GetItems(specifications.Select(x => x.ParentLink).Distinct(),
LanguageSelector.AutoDetect(true));
FilterForVisitor.Filter(subcategories);
var maincategories = ContentRepository.GetItems(subcategories.Select(x => x.ParentLink).Distinct(),
LanguageSelector.AutoDetect(true));
FilterForVisitor.Filter(maincategories);
I have so far also checked IsDeleted which is False for all, and also compared the ParentLink with the ContentLink for the Waste Basket which differ as described in my first post.
BR,
Henrik
If I understand this correctly, some of the currentspecs were deleted and then when checking if a parent page for, let's say subcategories is compared to a recyclebin reference, it's not filtered out. That's because the parent is still specifications for a subcategory, not the recycle bin.
Are you sure that the code that fetches the currentspecs is not fetching those from the wastebasket? How do you fetch currentspecs?
Some of the current specifications have been moved to the trash bin (not deleted).
And when the page checks for pages related to it (through a property of contentreferences) it picks up the pages in the trash bin and does not filter these out. So the visitors will see the specifications that are in the Trash Bin and should not be viewable by the visitor to the site.
The page that references the specs does not know where these specs are located, it just has a list of contentreferences. But my thought was that these should be filtered out if the specification page is in the trash bin?
Br,
Henrik
Hi, Henrik,
Sorry for not getting back earlier, I got stuck.
FilterForVisitor does not filter out on recycle bin. It checks for access, published and whether a page has a template:
new FilterPublished(contentRepository).Filter(pages);
new FilterAccess().Filter(pages);
new FilterTemplate().Filter(pages);
So, you have three options, as I see it.
1. Restrict the access to recycle bin to editors/admins only (but they would still get these pages).
2. Filter out currentspecs prior to calling filterforvisitor (I prefer this one, since it doesn't depend on any settings), ex. currentspecs = currentspecs.Where(spec => spec.ParentLink != ContentReference.Wastebasket).ToList();
3. Write your own filter, called filterforrecycled and there you combine it with the three above (most time consuming though)
Hope this helps.
Marija
Note also that the filtering code Henrik is presenting is incorrect as he never takes the filtered enumeration and use it.
it should be like:
var allContent = repo.GetItems(...); // filter can't modify the allContent as it is IEnumerable but returns a new filtered IEnumerable (yes under the hood ToList() is called for the allContent) var filteredContent = FilterForVisitor.Filter(allContent);
I did a quick demo like this on alloy site:
var pageType = this._cntTypeRepo.Load<MyDemoPage>(); var pageTypeUsage = this._cntModelUsage.ListContentOfContentType(pageType); var allPages = this._repo.GetItems(pageTypeUsage.Select(ptu => ptu.ContentLink.ToReferenceWithoutVersion()), LanguageSelector.AutoDetect(true)); var filteredPages = FilterForVisitor.Filter(allPages);
I have one page published and one in recycle bin. So now I have 2 pages in the allPages and 1 page in filteredPages. So the filtering works.
The customer has created a tree like structure for multiple pages displaying specifications which is referenced on a product page and when the customer puts on of the specification pages in the trash can these are still displayed for the user. I've tried using FilterForVisitors.Filter() but this doesn't seem to have any effect at all. And debugging and looking at the page that comes from ContentRepository seems to have no knowledge that it is actually in the trash bin.
So my question is, how do you check if a page is in the trash bin and filter that one out?
I've found some old topics regarding this, but the page itself doesn't seem to have any real connection to the wastebasket/trash bin.
ParentLink is still the old page in the tree and not the trash bin. So none of the old solutions to this seems to work.
Am I missing something?