Attachment Restrictions

Originally asked by Madhu on 03 February 2021 (original question)


We have a Bi Directional Sync for Jira Cloud and Jira Server.

We don’t want all our attachments to be synced with another Jira.

We have restricted External comments to the Other jira, But the attachments added in the Restricted comments are getting synced.

Can we restrict the attachments added on Restricted comments from getting Synced.

Or any suggested way to restrict Attachments, Please Advise.

Thanks in Advance.

Madhu


Answer by André Leroy-Beaulieu Castro on 03 February 2021

Hello Madhu,

Thanks for raising this community question!

With Exalate, you’ll be able to manage the visibility of the comments you send or receive, whether it be by user Role Level, Group Level, or Internal/Public in the case of Service Desk issues.

Here are some examples:

Send only the comments that are not for a specific Role Level:

Outgoing Sync:

replica.comments = issue.comments.findAll { it.roleLevel != "dev" }

Send only the comments that are not for a specific Group Level:

Outgoing Sync:

replica.comments = issue.comments.findAll { it.groupLevel != "jira-developers" }

Send only public comments (Jira Service Desk)

Outgoing Sync:

replica.comments = issue.comments.findAll { !it.internal }

---

Regarding the restriction of attachments, what criteria do you want to use to restrict attachments?

Thanks,

André


Comments:

Madhu commented on 05 February 2021

Hi Andre,

We are able to restrict comments and my question is all about restricting Attachments.

And my criteria is, When we add Attachments to the Jira Comments, Those attachments will be directly added to the Jira Attachments right.

So in that case we want to Restrict the particular attachments which are added to Restricted comments should be restricted.

If I am adding restricted comment we want to restrict the attachments added to that restricted comment.

And If I am adding normal comment, Attachments should not be restricted.

Hope my point is clear now.

Thanks

Madhu

Answer by Ariel Aguilar on 16 February 2021

Hi Madhu,

We tried this and it seems to be working. Could you please give it a try:

replica.attachments = issue.attachments.findAll { a ->
  def isMentionedInPublicComments = replica.comments.any {
    c -> c.body.contains("[^" + a.filename + "]") ||
        (c.body =~ (/!${java.util.regex.Pattern.quote(a.filename)}(\|.*!|!)/.toString())).find()
    }
  isMentionedInPublicComments
}

Kind regards,

Ariel


Answer by Mariia Horbatiuk on 16 February 2021

It seems there was a problem with formatting in the code block, sorry.

Please copy the following as is:

replica.attachments = issue.attachments.findAll { attachment ->
def result = issue.comments.findAll{ comment ->
if(comment.internal == false && comment.body.contains(attachment.filename)){
return true
}
}
return replica.description.contains(attachment.filename) || result
}

Comments:

Madhu commented on 16 February 2021

Hi Mariia,

Even my normal attachments are not getting synced now.

Ariel Aguilar commented on 16 February 2021

Hi Madhu,

Could you please give it a try to add the following code snippet as:

replica.attachments = issue.attachments.findAll { attachment ->
  def result = issue.comments.findAll{ comment ->
    throw new Exception("Comment Body: " + comment.body + " Attachment filename: " + attachment.filename)
    if(comment.internal == false && comment.body.contains(attachment.filename)){
      return true
    }
  }
  return replica.description.contains(attachment.filename) || result
}

The idea here is to throw an error message to see the comment body and the attachment filename, since there is a possibility this logic is evaluating persistently to false. Please share the error information when it’s generated.

Best regards,

Ariel

Answer by Mariia Horbatiuk on 16 February 2021

Hello Madhu,

Could you use this method in the outgoing script:

replica.attachments = issue.attachments.findAll { attachment -> def result = issue.comments.findAll{ comment -> if(comment.internal == false && comment.body.contains(attachment.filename)){ return true } } return replica.description.contains(attachment.filename) || result }

Hope this helps!


Comments:

Madhu commented on 16 February 2021

Hi Mariia,

Below is my Outgoing sync. Getting script error attached the screenshot for your reference. I have highlighted my Comment and Attachment Sync.

replica.key = issue.key
replica.type = issue.type
replica.summary = issue.summary
replica.description = issue.description
replica.comments = issue.comments.findAll { it.roleLevel == “Both Internal & External” }
replica.resolution = issue.resolution
replica.status = issue.status
replica.parentId = issue.parentId
replica.priority = issue.priority
replica.attachments = issue.attachments.findAll { attachment -> def result = issue.comments.findAll{ comment -> if(comment.internal == false && comment.body.contains(attachment.filename)){ return true } } return replica.description.contains(attachment.filename) || result }
replica.project = issue.project