Render All Comments from Issue
By default, $context.issue.fields.comment.comments
contains all issue comments, regardless of comment visibility restrictions. This means, by default, custom templates relying on the $context.issue
comments can show all comments to recipients that may otherwise not be able to view these comments.
If you do not want to expose all comments, you must use $jemhUtils.filterRestrictedComments($context.issue.fields.comment.comments)
to remove comments the current recipient should not be able to view.
This script will gather and render all comments that the recipient has permission to view. e.g. Internal Comments are not rendered for Customers.
$jemhUtils has online javadoc: https://jemhcloud.thepluginpeople.com/app/static/javadoc/com/thepluginpeople/jemhod/api/ITemplateUtils.html
HTML Render
#set ( $comments = $jemhUtils.filterRestrictedComments($context.issue.fields.comment.comments) )
#if ( $comments.size() > 0 )
$jemhUtils.setCommentRendered()
#end
#foreach ($aComment in $comments)
<strong>$jemhUtils.getUserDescription($aComment.author)</strong>
<em>$aComment.updated.asText():</em>
<p>$jemhUtils.wikiToHtml($aComment.body.asText())</p>
#end
Screenshot of how the comments would appear within the notification
Text only?
In the code above instead of calling wikiToHtml
just use:
$aComment.body.asText()
Previous Comments with a Reference to an attachment
Please see How to verify comment visibility applies | Limitations of retrieving restricted visibility comments for more information regarding historic comment references for Software projects.
If the previous comments contain a reference to an attachment, then it could result in those attachments being sent multiple times, as JEMHC will attach all attachments that have been referenced within the email body. This will then result in your data usage being used more quickly as it will increase the email size.
Solution 1 - break the markup syntax
The solution would be to remove the occurrence of “^” from the previous comment’s attachment reference, as this would mean that JEMHC will treat it as a reference and will not attach the referred attachment. Below is an example that does this:
#set ( $comments = $jemhUtils.filterRestrictedComments($context.issue.fields.comment.comments) )
#if ( $comments.size() > 0 )
$jemhUtils.setCommentRendered()
#end
#foreach ($aComment in $comments)
<strong>$jemhUtils.getUserDescription($aComment.author)</strong>
<em>$aComment.updated.asText():</em>
#set ($updatedCommentBody = $aComment.body.textValue().replace("[^", "[")) ## Remove the occurrence of "^"
<p>$jemhUtils.wikiToHtml($updatedCommentBody)</p>
#end
Solution 2 - full linked file markup removal
This is more complex, the regexp ‘must’ match all combos, those with international chars in filenames need more work:
#set ( $comments = $jemhUtils.filterRestrictedComments($context.issue.fields.comment.comments) )
#if ( $comments.size() > 0 )
$jemhUtils.setCommentRendered()
#end
<h3>Historic Comments</h3>
#foreach ($aComment in $comments)
<strong>$jemhUtils.getUserDescription($aComment.author)</strong>
#set ($strippedComment = $aComment.body.asText().replaceAll("\[\^[a-z0-9 -]+\.[a-z]+\]","(attachment excluded)"))
<p>$jemhUtils.wikiToHtml($strippedComment)</p>
#end