Using Templates to control edit of an issue
One of the points of pain with JIRA is trying to control who can edit particular fields of an issue, as discussed in JRA-1330. Various suggestions have been made there, such as using a workflow, but the page How to create a new Custom Field Type gave me the idea of simply changing the velocity template that is used to display a field to control who can edit the field's values. This approach also provides enough flexibility to make other changes such as who is permitted read the contents of a field.
- Decide which field you want to control, e.g. Fix Versions
- Find the template that is used to generate that field in the Edit Issue screen. The template is probably one of the files
versions-edit.vmin this case
If you have the source code, then you can confirm exactly which template is used by looking in
jira/src/java/com/atlassian/jira/issue/fieldsfor the field type you are interested in.
- Note that some templates are used by more than one field, e.g. the
versions-edit.vmis used for both the Affects Versions and Fix Versions fields.
- Find the field id of the field you want to control, e.g. for Fix Versions the field id is
fixVersions. I actually found this out by simply tweaking the template to print out the $field.id, but it's really defined in
- Make the changes and restart JIRA.
This example shows the changes made to
versions-edit.vm to control who can edit the Fix Versions field.
Here is where the changes start:
The following line is part of the original template
but these are the lines that change what is displayed. A "break" command would be useful in Velocity.
All the other lines in this file are unchanged except for the closing
In case that was a bit too detailed, here is the diff for JIRA 3.8.1:
- Simple changes to one .vm file per field to be controlled, no recompilation of source code necessary
- Uses the existing Jira group mechanism
- Need to manually apply changes to updated versions of JIRA. Happily, the changes are cleanly localised.
- Only controls fields edited using the browser, not with the SOAP API
- Need some familiarity with the Velocity template language
If you are having trouble with a hidden value being reset when the issue is edited, you can try passing it back like this:
This may occur when a user with no write-permission for a select field edits the issue.
Was this helpful?
Thanks for your feedback!