I want to make Piranha CMS manager screen to list pages which are created by the logged-in user only. I thought I should use PageListModelLoaded hook to achieve this and wrote this code in global.asax.
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
Hooks.Manager.PageListModelLoaded += (controller, menu, model) =>
{
Guid user_id = controller.User.GetProfile().Id;
model.Pages = model.Pages.Where(p => p.CreatedBy == user_id).ToList();
};
}
Unfortunately this doesn't work as I expected, Manager lists all pages even if I see that count of model.Pages is equal to zero through debugging step by step. I appreciate if someone help me see what my fault is.
Regards, Umit
The authentication manager of Piranha CMS uses FormsAuthentication, so the correct way of getting the user id of the logged in user is:
var user_id = new Guid(controller.User.Identity.Name);
Best regards!
EDIT 2015-01-16
Ok, so I took a closer look at your question. The page list view is actually fed two collections through its view model. One flat list of pages model.Pages
and one hierarchical collection model.SiteMap
. You can see the call here for the rendering of the tree-structure:
https://github.com/PiranhaCMS/Piranha/blob/2.2.4/Piranha/Areas/Manager/Views/Page/Index.cshtml#L178
The reason for this is that pages are displayed in a tree-structure (SiteMap), but when you type something in the search-field a flat list is returned (Pages). In order to filter the view you need to filter both collections.
/Håkan