How to update comments restriction in Jira through the REST API

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問


プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

要約

On Jira Service Management (JSM), comments on issues are either internal or shared with customer.
See Editing and collaborating on issues for more information on how comments relate to JSM issues.

As with other Jira project types, there's no option for JSM projects to use roles to restrict comments in an issue.
This is reported as a feature in JSDSERVER-829 - Getting issue details... STATUS .


Moving issues from JSM to other projects' types (Business or Software) turns all comments into public (no restrictions) by default and there's no option in the move issue wizard to assign internal comments to a specific role in the target project.
There's a feature request about it in JSDSERVER-7119 - Getting issue details... STATUS .


Sometimes there may be a requirement to move all (or a set of) issues from a JSM project to another from a different type and internal comments should be restricted to a specific project role.
Changing the comments' restrictions from the UI for each comment and issue might be an obstacle.

This document describes the steps needed to modify comments' restrictions through the Jira REST API.

ソリューション

The following procedure is based on comments executed in the Linux Shell.
You may adapt it to run on your preferred coding language.


  1. Determine the combination of Issue ID and Comment ID for all target internal comments that should be restricted to a specific project role.
    • If moving all issues in a specific project, the following query helps collecting this information.

      Expand to see the SQL query...
      select jiraaction.issueid as ISSUE_ID,
             jiraaction.id as COMMENT_ID
      from jiraaction 
      inner join entity_property on jiraaction.id=entity_property.entity_id 
      inner join jiraissue on jiraaction.issueid=jiraissue.id
      inner join project on project.id=jiraissue.project
      where jiraaction.actiontype = 'comment'
      and entity_property.json_value='{"internal":true}'
      and entity_property.entity_name='sd.comment.property'
      and project.pkey = '<PROJECT_KEY>'
      ;
  2. Move the target issues to the new project.
    • While the next steps aren't executed, the comments will be public to the new project.
  3. For each comment (combination of Issue ID and Comment ID), run the following commands to change the comment's restriction.
    1. Define values for some environment variables.

      JIRA_ADMIN_USERNAME=admin
      JIRA_ADMIN_PASSWORD=admin
      JIRA_BASE_URL=https://mycompany.com/jira
      ROLE_NAME=Administrators
      ISSUE_ID=10142
      COMMENT_ID=10106
    2. Get current comment data and metadata.

      REST_CONTENT_FULL_OUTPUT=$(curl -u ${JIRA_ADMIN_USERNAME}:${JIRA_ADMIN_PASSWORD} -X GET -H "Accept: application/json" ${JIRA_BASE_URL}'/rest/api/2/issue/'${ISSUE_ID}'/comment/'${COMMENT_ID} 2>/dev/null)
    3. Modify comment's visibility and temporarily save it in a file.

      echo -E ${REST_CONTENT_FULL_OUTPUT} | \
          jq '{body: .body, visibility: { type: ("role"), value: ("'${ROLE_NAME}'")}}' \
          > modified-comment-data.json
    4. Update the comment with the new restriction to a project role.

      curl -u ${JIRA_ADMIN_USERNAME}:${JIRA_ADMIN_PASSWORD} -X PUT -H "Content-Type: application/json" ${JIRA_BASE_URL}'/rest/api/2/issue/'${ISSUE_ID}'/comment/'${COMMENT_ID} --data @modified-comment-data.json


参考情報

Restricted comments disappear after moving an issue to a new project

Jira Service Management で内部または外部コメントを取得する方法




Last modified on Mar 15, 2021

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.