Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to restrict comment visibility in an email velocity template

Søren Hansen February 20, 2013

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.

5 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2013

Did you try #if (comment)?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2013

How do you throw the event? Do you create an Comment object by yourself and are the roleLevel and groupLevel set?

Søren Hansen February 20, 2013

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...

Søren Hansen February 21, 2013

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.

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2013

IssueEventDispatcher is deprecated, did you try IssueEventManager?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2013

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".

Søren Hansen February 25, 2013

Ok, that is a good explanation - I'll have a look into that within the next few days and get back. Thanks so far!

Søren Hansen March 24, 2013

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?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 24, 2013

Yes, in params with name "eventsource". IssueEventSource is a class which contains the constants for ACTION and WORKFLOW.

Søren Hansen March 24, 2013

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!

Søren Hansen March 25, 2013

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.

0 votes
Søren Hansen February 20, 2013

Did now - and it worked :-) Thanks!

0 votes
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2013

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...

0 votes
Søren Hansen February 20, 2013

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.

0 votes
Søren Hansen February 20, 2013

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.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events