API
Version 7.x > API > Need to list what roles have Read permission for a given TreeNode View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
david.gray-matrixres - 4/26/2013 10:17:35 AM
   
Need to list what roles have Read permission for a given TreeNode
I am developing a integration connector for the Integration Bus which subscribes to Document changes. As a part of the information I need to deliver to the external system, I need to provide a list of the Roles which have read permission for a given TreeNode passed to ProcessInternalTaskAsync().

I have looked at the AclProvider class in the API documentation, but it is not clear how I would use it to retrieve the Roles with read permission for the TreeNode.

Is there some example code for listing Roles and Permissions?

User avatar
Member
Member
kentico_sandroj - 4/27/2013 3:20:46 PM
   
RE:Need to list what roles have Read permission for a given TreeNode
Hi David,

We do not have a method to check permissions for a role but we do have a method to check permissions for a user. Following the example below, you could create a fake user on execution, assign it to a role, check the permissions, then delete the user.

private bool CheckDocumentPermissions()
{
// Create an instance of the Tree provider
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

// Get default culture code
string culture = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSDefaultCultureCode");

// Get the API Example document
TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", culture);

if (node != null)
{
// Get the user
UserInfo user = UserInfoProvider.GetUserInfo("Andy");

if (user != null)
{
// Check permissions and perform an action according to the result
if (TreeSecurityProvider.IsAuthorizedPerNode(node, NodePermissionsEnum.ModifyPermissions, user) == AuthorizationResultEnum.Allowed)
{
apiCheckDocumentPermissions.InfoMessage = "User 'Andy' is allowed to modify permissions for document 'API Example'.";
}
else
{
apiCheckDocumentPermissions.InfoMessage = "User 'Andy' is not allowed to modify permissions for document 'API Example'.";
}

return true;
}
}

return false;
}


This example can be found under Site Manager > Support > API Examples.

Please let me know if this approach would work for you.

Thanks,
Sandro