Restricting Comment Visibility
Using Behaviours, you can restrict a comment’s visibility by setting the field options for the commentLevel
field, alternatively set it to a locked value. This is a particularly useful feature for those who want to ensure that comments added during edit/transition issue can only be seen by certain users.
Set Comment Visibility
This sets the comment to be viewable only by the Administrators role and locks it:
getFieldById('commentLevel')
.setFormValue('role:Administrators')
.setReadOnly(true)
Restrict by Role and/or Group
Imagine that you have a workflow step where you want to require the user to enter a comment in order to move forward with the transition. In addition to requiring a comment, you only want users in the Administrators role or jira-administrators group to be able to see this comment.
By using setFieldOptions
on the commentLevel
field, this can be easily accomplished.
Due to the limitations of behaviours, you can only restrict comment visibility on the Update/Edit Issue, Assign Issue, and Workflow Transition screens. You will not be able to restrict comment visibility if a user adds a comment through the view screen.
Note the use of setFieldOptions
. It has two forms:
Iterable
: pass a List (or any Iterable) of Role or Group objects
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def groupManager = ComponentAccessor.getGroupManager()
def group = groupManager.getGroup("jira-administrators")
def role = projectRoleManager.getProjectRole("Administrators")
def formField = getFieldById("commentLevel")
formField.setRequired(true)
formField.setFieldOptions([group, role])
Alternately, pass a list of strings which have the form group:groupName
or role:roleName
:
def formField = getFieldById("commentLevel")
formField.setRequired(true)
formField.setFieldOptions(['group:jira-administrators', 'role:Administrators'])
Results in: