Developer forum

Forum » Development » Check if user has access to paragraph

Check if user has access to paragraph

Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

What is the fastest and best way to check if a user (by user id) has access to a paragraph (by paragraph id)?
As you understand I dont want to check if the current user has access to the current paragraph, but if a user has access to a paragraph.

Tried something like this, but not sure what to do with the result "permission". I just want a clear true/false if the user has access to the paragraph.

var pService = new Dynamicweb.Content.ParagraphPermissionService();
var permission = pService.GetPermissionForUser(userId, paragraphId, Dynamicweb.Security.UserManagement.PagePermissionLevels.Frontend);

Replies

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply
This post has been marked as an answer

Hi Martin,

The permission will return a PagePermissionAccess (also when requesting paragraph permission) that can be 

  • Inherit (0)
  • Allow (1)
  • Deny (2)

So, if all you're interested in is a true/false, simply evaluate if return value is Allow.
Hope the information is sufficient, otherwise let us hear from you again.

Best regards
Morten Snedker

Votes for this answer: 1
 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

My bad, I did not notice it was an enum.
I will try this, but just to be sure, is this a good way to check or are there other better ways?

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

I believe that the approach you're taking here is the proper one!  :-)

 

/Morten

 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

Looks like it is working, but I have one paragraph that inherits its permissions.
As far as I know this paragraph could be allowed for my user, but how can I know? Is there a way to get only Allow/Deny with inheritance taken into consideration?
Or do I have to make some kind of recursive lookup?

 

You must be logged in to post in the forum