How can I restrict a transition in the workflow to

2020-03-03 22:32发布

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.

3条回答
疯言疯语
2楼-- · 2020-03-03 22:56

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.

查看更多
家丑人穷心不美
3楼-- · 2020-03-03 23:11

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.
查看更多
可以哭但决不认输i
4楼-- · 2020-03-03 23:12

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.

查看更多
登录 后发表回答