views:

230

answers:

1

I have a MOSS workflow where on the first form, the user can choose a colleague to evaluate him. Say user A selects user B.

After the form is submitted, a new task is created for user B to evaluate user's A.

My problem is that I need to make sure the task is only accessible to user A, and not to user B, nor any other user in the system.

I tried setting the SpecialPermissions property, but the property can be binded when the workflow is instantiated, so I still don't know what user will be choosen by user A (in this case user B), and then can't set the permissions.

I also tried changing the SpecialPermissions property on the MethodInvoking method, but MOSS won't pay attention to the new permissions.

What is the proper way to set permissions on a workflow task?

A: 

Here's how I do it... this is a smattering of code that I have dispersed in multiple functions.

spListItem.BreakRoleInheritance(false);
foreach (SPRoleAssignment spRoleAssignment in spListItem.RoleAssignments)
{
    if (!spRoleAssignment.RoleDefinitionBindings.Contains(this.workflowProperties.Web.RoleDefinitions.GetByType(SPRoleType.Administrator)))
    { // don't remove administrators
                spRoleAssignment.RoleDefinitionBindings.RemoveAll();
                spRoleAssignment.Update();
    }
}
SPRoleDefinition roledefinition = web.RoleDefinitions.GetByType(SPRoleType.Contribute);
SPRoleAssignment myRoleAssignment = new SPRoleAssignment(accountName, "", "", "");
myRoleAssignment.RoleDefinitionBindings.Add(roledefinition);
spListItem.RoleAssignments.Add(myRoleAssignment);
UJ
Thanks for the code. Where should I use it? I have a createTaskActivity, and if I add an onTaskCreated the workflow starts to fail (this is documented in MSDN). If I instead use a code block, I don't have the taskID yet, so I can't set the permissions.
pgb
OnTaskCreated is the right place. If your onTaskChange is not triggering then check your tokens and task id's and make sure they match between the onTaskCreated/CreateTask/CompleteTask objects.
UJ

related questions