Developer forum

Forum » Development » Get pages filtered by permissions

Get pages filtered by permissions

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

I am trying to use Services to get a list of pages, but I am struggling with filtering by user permissions. This is what I have and it's giving me an empty list



var itemTypes = new List<string> {"IP_Configuration"};
var pages = Dynamicweb.Services.Pages.GetPagesForItems(itemTypes);
return pages.Where(p => p.Published && IsPageActive(p) && IsItemValid(p.Item) && p.UserManagementPermissions.Frontend.ContainsKey(User.GetCurrentUser(PagePermissionLevels.Frontend).GetPermissionIdentifier().GetHashCode())).OrderBy(i => i.Parent.Sort).ThenBy(p => p.MenuText);

 

If I remove the LINQ expression related to permissions (in blue above) I get all pages. I tried a few other thing like the Permission key

In the backend my permissions are accurate. I have basic things such as "Read" for Authenticated Users, and "None" for Anonymous users (attached).

 

Can you tell me what I'm doing wrong?

 

Best Regards,

Nuno Aguiar

2021-09-30_12-05-21.gif

Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Try this one instea:

Dynamicweb.Frontend.SecurityHandler.IsCurrentUserAllowed(page)
Votes for this answer: 1
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

That worked. Thanks.

 

Nuno Aguiar

 

You must be logged in to post in the forum