2

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.

ballofmud
  • 43
  • 7

2 Answers2

3

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.

Alex Pavlenko
  • 469
  • 3
  • 10
1

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.

Jk1
  • 11,233
  • 9
  • 54
  • 64
Alex.V
  • 2,081
  • 14
  • 13
  • 1
    Can you be more detailed on how to "specify a guard expression"? I can't find any documentation about that. – Andrea Sciamanna Jul 22 '14 at 18:37
  • First, you can define it in 'On enter' block. Second, there's a special placeholder for a guard condition in 'on' or 'in' blocks (in square brackets). When empty, this guard renders as 'always'. – Alex.V Jul 23 '14 at 07:11
  • In "on enter" block, can you make an example on how to block the rule? In the square bracket, what can be put in there? Usual conditions such as issue.State == Whatever? I code example may help, since, again, I can't find any official documentation about this, neither I can see an example showing this kind of restrictions in the workflow repository. – Andrea Sciamanna Jul 23 '14 at 07:24
  • 1
    In 'On enter block' you can, for instance, request a field to be set: Some_Field.required("Message that a user will see"). Another way is to use assert : . Code in the square brackets should have boolean type. Example: issue.is duplicated by.added.isNotEmpty – Alex.V Jul 24 '14 at 06:13