Page in Trash Bin

Vote:
 

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?

#117951
Feb 25, 2015 9:35
Vote:
 

Hi, Henrik,

Can you share the code that doesn't filter out the recycled pages?

BR,

Marija

#117980
Feb 25, 2015 12:22
Vote:
 

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

#117983
Feb 25, 2015 13:27
Vote:
 

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?

#117985
Feb 25, 2015 13:52
Vote:
 

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

#117986
Feb 25, 2015 13:55
Vote:
 

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

#118005
Feb 25, 2015 18:04
Vote:
 

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.

#118008
Feb 25, 2015 18:45
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.