When an issue is commented using the "comment" button, the Issue Commented event is fired and triggers mails to the relevant users. Only the users that are allowed to see the comment due to its visibility get an e-mail. This is all good.
In other cases (such as when an issue is resolved), a mail is sent to the requester. In that template (issueresolved), we've included the comment (coming from the "resolve issue" screen) by using $comment and/or $htmlComment.
However if the comment is restricted so the recipient is not allowed to see it, how do we then avoid outputting it in the template? Is there a method somewhere on the comment that allows us to check its visibility against the current recipient, so we can skip the comment section of the template in that case?
I've had a look at the #visibility macro but it does not give a simple hint to how this is solved.
Community moderators have prevented the ability to post new answers.
Did you try #if (comment)?
How do you throw the event? Do you create an Comment object by yourself and are the roleLevel and groupLevel set?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, generally, but as it shows, not in a special case where I specifically need it. That may have confused me earlier to believe that the problem was another than it actually was.
As it turns out, the problem relates to the fact that we use ScriptRunner to throw an extra event in some cases (as you devised in https://answers.atlassian.com/questions/134606, thanks again), which then triggers a mail. And from within the template of that mail, $comment seems to be filled out always (even if not visible to the recipient). So some information is lost when the second event is thrown. I guess I'll have to dig a bit deeper to find the problem...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've modified some of the built-in listeners in ScriptRunner. I'll look into how roleLevel and groupLevel are set.
Example listener that fires an event when 1) No files are attached, 2) A comment is attached:
Map doScript(Map params) { Map transientVars = params["transientVars"] as Map MutableIssue issue = params["issue"] as MutableIssue IssueEvent event = params["event"]; Boolean doIt = ConditionUtils.processCondition(params[ConditionUtils.FIELD_CONDITION] as String, issue, false, params) if (! doIt) { return [:] } doIt = true; if (event) { // listener List changeItems = event.getChangeLog()?.getRelated("ChildChangeItem") log.debug("changeItems: $changeItems") changeItems.each {GenericValue gv -> if (gv["field"] == "Attachment" && gv["newvalue"]) { // Got attachment doIt = false; } } } if (! doIt) { return [:] } log.debug ("Raising event: " + params[FIELD_EVENT_ID]) Comment comment = event.getComment() GenericValue changeGroup = event.getChangeLog() if (comment != null) IssueEventDispatcher.dispatchEvent(params[FIELD_EVENT_ID] as Long, issue, WorkflowUtils.getUser(params), comment, null, changeGroup, params, true); params }
The comment is taken from the original event as the original listener didn't find the comment if transientvars was not defined.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IssueEventDispatcher is deprecated, did you try IssueEventManager?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I looked into the jira source (com.atlassian.jira.mail.MailingListCompiler)... the event has to have an event source of IssueEventSource.ACTION or IssueEventSource.WORKFLOW, otherwise the comment is not deleted before generating the email for the receipient. The parameter name is "eventsource".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, that is a good explanation - I'll have a look into that within the next few days and get back. Thanks so far!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry about the delay - had a holiday break.
I'm looking into where I find IssueEventSource; cannot find the field on IssueEvent, neither as a parameter to dispatchEvent method (IssueEventDispatcher as well as IssueEventManager). Is it stored in "params" or elsewhere?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, in params with name "eventsource". IssueEventSource is a class which contains the constants for ACTION and WORKFLOW.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perfect - that worked. Setting params["eventsource"] to WORKFLOW had the desired effect so that "comment" is null in the template when the recipient is restricted from seing it. Once again, thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, the difference between ACTION and WORKFLOW is noteworthy:
With event source WORKFLOW, mails are sent even if the comment is not viewable by the recipient (though "comment" variable is null so the comment isn't incuded in the mail).
With event source ACTION, the mail is skipped altogether when the comment is not visible by the recipient.
I ended up using the latter as I only needed to send the comment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is the comment displayed for users which are not able to see it? IMO a message is displayed that the comment is not visible for the user...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The user cannot see the comment in the Jira web interface. But the $htmlComment seems to be filled out anyway. I currently use this code in the template:
#if ($htmlComment) <tr valign="top"> <td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:20px 10px 20px 0;" colspan=2> $commentatorName $i18n.getText("schilling.issue.resolved.c") </td> </tr> <tr valign="top"> <td style="color:${textColour};background-color:#f0f0f0;font-family:${textFontFamily};font-size:${textSize};padding:10px 0px 10px 10px;" colspan=2> <div style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};margin:0 0 0 10px;"> <strong>$htmlComment</strong> </div> </td> </tr> #end
That includes the comment in the mail even if the recipient is not allowed to see it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I take it that the interface method com.atlassian.jira.issue.comments.CommentPermissionManager.hasBrowsePermission can be used to determine whether the comment is viewable. I just need to be able to access that from the template.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.