views:

247

answers:

1

Hi

On a given state machine workflow, how do we find out the possible transitions for a given role. In my scenario, only certain roles have the permission to perform certain activities. I have to get that list. The helper class StateMachineWorkflowInstance isn't helpful here as it just returns all the possible transitions, ignoring the role of the actor.

Any help here would be appreciated.

Thanks, Socratees.

A: 

Looks like there is no straight forward way to do this. I wrote this method based roughly on the solution at Ruurd Boeke's blog . I'm getting the list of possible events, and then looking if they can be executed by the user role. It's a work around, but still works fine.

public string[] GetTransistions(string strUser)
{
    string[] strRoles = System.Web.Security.Roles.GetRolesForUser(strUser);
    List<string> strActivity = new List<string>();
    ReadOnlyCollection<WorkflowQueueInfo> queues = workflowInstance.GetWorkflowQueueData();
    foreach (WorkflowQueueInfo info in queues)
    {
        if (!info.QueueName.Equals("SetStateQueue"))
        {
            foreach (string subscribedActivity in info.SubscribedActivityNames)
            {
                HandleExternalEventActivity heea = workflowInstance.GetWorkflowDefinition().GetActivityByName(subscribedActivity) as HandleExternalEventActivity;

                #region check roles
                if (heea.Roles != null)
                {
                    foreach (WorkflowRole workflowRole in heea.Roles)
                    {
                        foreach (string strRole in strRoles)
                        {
                            if (workflowRole.Name.Equals(strRole))
                            {
                                strActivity.Add(heea.EventName);
                                //permissionLog += workflowRole.Name + " can perform " + heea.EventName + " Activity. ";
                            }
                        }
                    }
                }
                #endregion
            }
        }
    }
    return strActivity.ToArray();
}