1
0
-1

Scenario:

  • configure local connection between any project (SOURCE) and a service desk project (DESTINATION)

  • instead of the standard 

    issue.comments = commentHelper.mergeComments(issue, replica)

    put

    if (! firstSync && replica.project.key == "SOURCE") {
      issue.comments     = commentHelper.mergeComments(issue, replica, {
        comment ->
        
        comment.executor = issue.reporter
        
        comment
      })} else {
        issue.comments = commentHelper.mergeComments(issue, replica)
    }
  • sync an issue from the SOURCE project


Expected:
The comment is created on behalf of the reporter


Actual:
An error, claiming permission problems with the reporter

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hello, Serhiy Onyshchenko 
      CC: Jonathon Irwin
      I was able to reproduce the permissions problem, and I'll pass it on to the dev team.
      As a work-around you may use the Jira's API like this:

      incoming sync script
      if (firstSync && replica.project.key == "DESTINATION") {
         issue.projectKey   = "SOURCE"
         issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"
      }
      if (firstSync && replica.project.key == "SOURCE") {
         issue.projectKey   = "DESTINATION"
         issue.reporter = nodeHelper.getUserByEmail("ziohimself@gmail.com")
         issue.typeName     = "IT Help"
         issue.customFields."Customer Request Type".value = "IT help"
      }
      
      issue.summary      = replica.summary
      issue.description  = replica.description
      
      import com.atlassian.jira.component.ComponentAccessor
      import com.atlassian.jira.util.json.JSONObject
      import com.exalate.basic.domain.BasicNonPersistentTrace
      if (!firstSync && replica.project.key == "SOURCE") {
          replica.addedComments.each {
              
              remoteComment ->
              
              final SD_PUBLIC_COMMENT = "sd.public.comment"
              
              def isInternal = remoteComment.internal || remoteComment.roleLevel != null || remoteComment.groupLevel != null
              def properties = [(SD_PUBLIC_COMMENT): new JSONObject(["internal": isInternal ])]
              //def commentUserId = nodeHelper.getUserByEmail(remoteComment.author.email)?.key
              def commentUserId = nodeHelper.getUserByEmail("ziohimself@gmail.com")?.key
              def commentUser = ComponentAccessor.userManager.getUserByKey(commentUserId)
              def commentManager = ComponentAccessor.getCommentManager()
              def authContext = ComponentAccessor.jiraAuthenticationContext
              
              
              authContext.setLoggedInUser(commentUser);
              def curIssue = ComponentAccessor.getIssueManager().getIssueObject(issue.key as String)
              try {
                  def comment = commentManager.create(curIssue,commentUser,remoteComment.body,null,null,new Date(),properties,false)
                  def trace = new com.exalate.basic.domain.BasicNonPersistentTrace(
                      com.exalate.api.domain.twintrace.TraceType.COMMENT, //TraceType type, 
                      comment.id as String, //String localId, 
                      remoteComment.remoteId as String, //String remoteId, 
                      com.exalate.api.domain.twintrace.TraceAction.NONE, //TraceAction action,
                      true //boolean toSynchronize
                  )
                  traces.add(trace);
              } catch (e) {
                  log.error("#comments failed to create a comment `${remoteComment.body}` as `${commentUserId}`", e)
                  throw e
              }
          }   
      } else {
          issue.comments = commentHelper.mergeComments(issue, replica)
      }
      issue.attachments  = attachmentHelper.mergeAttachments(issue, replica)
      issue.labels       = replica.labels

      Note, how I use "ziohimself@gmail.com" for both the reporter and the comment author (hardcoded).

      there were 2 tricks made:

      1. create the comment using the Jira API
      2. make Exalate aware of the comment that was just created so that updates would arrive to the right place


      And here's the video showcasing the entire exchange:


      Happy Exalating!

        CommentAdd your comment...