Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I restrict a transition in the workflow to only the user that created the work item in TFS?

This is part of a larger restriction, but the part that is tripping me up is being able to allow only the user that created a work item (the value of the "System.CreatedBy" field) to transition a work item to the Closed state. I am aware of how to restrict the transition using the "For" and "Not" clauses, but those are limited to groups. I want to restrict it to the specific creator of THIS work item. VALIDUSERS is also limited to groups (either TFS or AD). Thanks for your help.

like image 490
Scott Avatar asked Sep 24 '14 19:09

Scott


2 Answers

I was able to find a suitable solution last night.

This solution actually works perfectly for my need as it allows me to add a group as exempt from the rule so that members of the group, say QA, as well as the Creator are able to close the work item, while other members of the team are not.

Reference: here (web archive link)

As referenced:

  1. Create ClosedByValidation field and add the following rules
<FIELD name="Closed By Validation" refname="Demo.ClosedByValidation" type="String">
    <COPY from="currentuser" /> 
    <FROZEN not="[project]\Project Administrators"/> 
</FIELD>
  1. Add the following rules to Closed state
<STATE value="Closed"> 
   <FIELDS> 
      <FIELD refname="Demo.ClosedByValidation"> 
          <COPY from="currentuser" /> 
       </FIELD> 
   </FIELDS> 
</STATE>
  1. Add the ClosedByValidation field to the form, so it looks like this. Note how I’ve displayed both the “Created By” field and the “ClosedByValidation” field

How it works

  • The ClosedByValidation field copies the “Created By” value into itself right when the work item is created.
  • It then immediately freezes the field (with the FROZEN) rule, which states that it cannot change.
    • NOTE: The FROZEN rule is conditioned to NOT apply to project administrators, giving them an override capability.
  • When the work item is Closed, then the current user is copied into the ClosedByValidation field.
  • If the ClosedByValidation’s value remains the same (the original Created By) then all is well.
  • If the ClosedByValidation’s value has changed, then the FROZEN rule displays a violation as you see in the screenshot above.
like image 195
Scott Avatar answered Nov 14 '22 04:11

Scott


This is not possible afaik.

However the opposite idea is possible "Restrict a transition when currentUser is not same as CreatedBy" with "NOTSAMEAS" rule. (I still don't know why MS didn't implement a "SAMEAS" rule)

So, since there is no "SAMEAS" rule, you can not do it using xml modifications.

Btw, I hope I'm wrong but it's also not available to interrupt work item save event and cancel it (As @MrHinsh suggested). Work Item Save event is just a Notification event and not a DecisionPoint event and also it happens after the work item save operation completed as name suggests (WorkItemChangedEvent).

Details about the NotificationType can be read here.

like image 1
Beytan Kurt Avatar answered Nov 14 '22 04:11

Beytan Kurt