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

This is part of a larger restriction, but the part that disables me allows only the user to create a work item (the value of the "System.CreatedBy" field) for the work item to go to the Closed state. I know how to restrict the transition using the "For" and "No" sentences, but they are limited to groups. I want to limit it to the specific creator of THIS work item. VALIDUSERS is also limited to groups (either TFS or AD). Thank you for your help.

+5
source share
3 answers

I was able to find a suitable solution last night.

This solution really works fine for my need, because it allows me to add the group as exempt from the rule, so that the members of the group, say QA, as well as the Creator can close the work item while the other members of the team do not.

Link: here

As stated:

  • Create a ClosedByValidation field and add the following rules.
<FIELD name="Closed By Validation" refname="Demo.ClosedByValidation" type="String"> <OPY from="currentuser" /> <FROZEN not="[project]\Project Administrators"/> </FIELD> 
  1. Add the following rules to the 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 that it looks like this. Notice how Ive displayed the Created field and the ClosedByValidation field.

How it works

  • The ClosedByValidation field copies the Created value to directly when the work item is created.
  • Then it immediately freezes the field rule (using FROZEN), which states that it cannot change.
    • NOTE. The FROZEN rule is due to the fact that it does NOT apply to the project administrators, giving them the opportunity to redefine.
  • When the item is closed, then the current user is copied to the Closed field.
  • If the value of ClosedByValidations remains the same (original Created By), then all is well.
  • If the ClosedByValidations value has changed, then the FROZEN violation rule will be displayed, as you see in the screenshot above.
+7
source

It's impossible.

However, the opposite idea is possible to restrict the transition when currentUser is not the same as CreatedBy "with" NOTSAMEAS ". (I still do not know why MS did not apply the" SAMEAS "rule)

So, since there are no "SAMEAS" rules, you cannot do this with xml changes.

Btw, I hope I'm wrong, but also cannot interrupt the work item save event and cancel it (as @MrHinsh suggested). The Save Work Item event is the Notification event, not the DecisionPoint event, and it also occurs after the operation to save the work item with the name (WorkItemChangedEvent) is completed.

Read more about NotificationType here .

+1
source

This configuration is not possible with the current rule engine.

Possible alternatives:

  • Create a server-side event handler that intercepts thesave and rejects it based on a custom business rule.
  • No ... I'm fresh ...

It should be noted that TFS is not intended for enforcement, and your business rules imply a dysfunctional organizational implementation.

0
source

Source: https://habr.com/ru/post/1203325/


All Articles