Custom workflow rule to set default comment visibility

873 views Asked by At

I am trying to add a workflow rule in YouTrack, which sets the visibility of newly posted comments that aren't made by a specific user.

Here's what I've tried:

rule set comment visibility to developers 

when comments.added.last.author.login != "special" { 
  comments.last.permittedGroup = {group: Developers}; 
}

This works, in that all newly added comments that are not made by the special user are set as visible only to Developers. The problem is that this rule also prevents the visibility from being overridden; the visibility always reverts back to "Developers", after it is changed manually via the UI.

Obviously the rule in its current form is pretty simple and I guess (hope) there's a way to isolate the creation of a comment, rather than any update to it (which I guess is what it's currently catching).

Is there any way to only have this rule apply to newly created comments, rather than to any that have been updated?

1

There are 1 answers

3
Mariya Davydova On BEST ANSWER

The trick here is that YouTrack Workflow Language supports null-safety. When you add a comment, comments.added.last contains the comment, and a rule works as expected. When you edit something else, comments.added.last is null, thus comments.added.last.author.login is also null, and null != "special", indeed.

What you need is to check that there are newly created comments is this change, e.g.

when comments.added.isNotEmpty && comments.added.last.author.login != "special" {
  comments.last.permittedGroup = {group: Developers};
}