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

泪湿孤枕 提交于 2019-11-30 22:05:58
Scott

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.
Beytan Kurt

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.

This configuration is not possible with the current rules engine.

Possible alternatives:

  1. Create a server side event handler that intercepts thesave and rejects it based on your custom business rule
  2. Nope... I'm fresh out...

It should be noted that TFS is not designed to be an enforcement system and your business rules imply a dysfunctional organisational implementation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!