API
Version 7.x > API > Getting Roles allowed for a particular node and permission View modes: 
User avatar
Certified Developer v6
Certified Developer v6
Dave - 10/25/2013 3:50:19 PM
   
Getting Roles allowed for a particular node and permission
I am trying to get the list of Roles that have a particular permission for a particular Node ID. This is what I have:
        public static IEnumerable<int> GetRolesForPermissions(int nodeId, NodePermissionsEnum permission)
{
var aclProvider = new AclProvider(new TreeProvider());

var items = aclProvider.GetACLItems(nodeId);

if (!DataHelper.IsEmpty(items))
{
var acls = items.Tables[0].Rows;

foreach (DataRow acl in acls)
{
var aclId = (int)acl["AclID"];

var roles = aclProvider.GetAllowedRoles(aclId, permission, "RoleID");

if (!DataHelper.IsEmpty(roles))
{
var allowedRoles = roles.Tables[0].Rows;

foreach (DataRow allowedRole in allowedRoles)
{
yield return (int)allowedRole["RoleID"];
}
}
}
}
}

It works, but it doesn't seem as fast as it could be. Is there a better way?