State-machine workflow in youtrack - restrict state changes for certain roles

StackOverflow https://stackoverflow.com/questions/18889883

  •  29-06-2022
  •  | 
  •  

Question

I have created a simple state-machine workflow in youtrack to reflect our process. It uses three State values (Submitted, In Progress, Fixed) and allows to move through them sequentially.

Is it possible to restrict certain state changes for specific roles? For example role Reporter should only be able to create issue and move from 'Fixed' to 'In Progress' if something is wrong.

Was it helpful?

Solution 2

A pretty old question, but I'll try to answer. You can specify a guard expression that will be invoked upon transition to/from a specific state. In this expression you can validate user permissions.

OTHER TIPS

UPDATE: An even better way to do this task is the following right inside the Statemachine:

initial state Submitted { 
  on Approve[always] do { 
    assert loggedInUser.hasRole("Project Admin"): "Only Project Admins can Approve tasks."; 
  } transit to Open 
}

OLD ANSWER: Straighforward way (inside the Statemachine itself):

initial state Submitted { 
  on Approve[loggedInUser.hasRole("Project Admin")] do {<define statements>} transit to Open 
}

Althought it will work, it will fail silently, so user will not know why does it not work.

A much better approach will look like the following (for this you will have to create Stateless Rule):

when State.oldValue == {Submitted} && State.becomes({Open}) { 
  assert loggedInUser.hasRole("Project Admin"): "Only Project Admins can Approve tasks."; 
}

In this case user will get an error message that you specify.

Remember to delete the condition in the Statemachine, since it is checked earlier and you will not have any error messages as assertion will not run at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top