How To Programmatically check permissions on a blog post
I'm building a custom template for the BlogPostList. In codebehind I need to know if a particular blog post is set to deny anonymous users (Note: I'm talking about a blog POST, not the entire blog). If yes then I will display a small lock icon. And if the user is an anonymous user then I will change the href of the links to a javascript alert stating they must log in to view the details of the blog post.
How do I check if a blog post is secured?
Hi,
To check permissions for blog post use the security API and query a single blog post like below.
In the highlighted code specify the single blog post to be checked.
BlogsManager blogsManager = BlogsManager.GetManager(); UserManager usersManager = UserManager.GetManager(); SecurityConfig secConfig = Config.Get<SecurityConfig>(); Telerik.Sitefinity.Security.Configuration.Permission blogsPermSet = secConfig.Permissions[SecurityConstants.Sets.General.SetName]; int actionsMask = blogsPermSet.Actions[SecurityConstants.Sets.General.Create].Value | blogsPermSet.Actions[SecurityConstants.Sets.General.Delete].Value; ISecuredObject securedObject = blogsManager.GetBlogPosts().Where(bp => bp.Title == "MyPost").First(); Guid[] users = new Guid[] usersManager.GetUser(userName).Id ; bool isGranted = securedObject.IsGranted(SecurityConstants.Sets.General.SetName, users, actionsMask);No good.
First I get an the error; Exception has been thrown by the target of an invocation. on the following line.
ISecuredObject securedObject = blogsManager.GetBlogPosts().Where(bp => bp.Title == "MyPost").First();var item = (RadListViewDataItem)e.Item;var post = item.DataItem as BlogPost;ISecuredObject securedObject = post;securedObject.IsGranted(SecurityConstants.Sets.General.SetName, users, actionsMask);Hello Gregg,
Change the permission sets to be
BlogsManager blogsManager = BlogsManager.GetManager(); UserManager usersManager = UserManager.GetManager(); SecurityConfig secConfig = Config.Get<SecurityConfig>(); Telerik.Sitefinity.Security.Configuration.Permission blogsPermSet = secConfig.Permissions["BlogPost"]; int actionsMask = blogsPermSet.Actions["ViewBlogPost"].Value;"ViewBlogPost"ManageBlogPost""ChangeBlogPostOwner""ChangeBlogPostPermissions"