How to add all Users of a Group as Watchers of a Page or Blog
プラットフォームについて: Data Center - この記事は、Data Center プラットフォームのアトラシアン製品に適用されます。
このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。
*Fisheye および Crucible は除く
目的
The ability to add an entire group as a watcher of specific content is not available in Confluence at the moment. Please check the following feature requests for more details:
- CONFSERVER-20118 - Getting issue details... STATUS
- CONFSERVER-30644 - Getting issue details... STATUS
With that in mind, you need to add the users one by one, which is a task that can take hours to complete if the list of users is large. As we can see on the requests, customers would like to have the option of adding a group instead of individual users in those situations.
Even though there are some plugins that add this functionality, it may not be reasonable to acquire the add-on if you are only looking to this specific feature.
ソリューション
If your sole purpose is to add multiple users as watchers of a page or blog post, you can achieve that through the remote APIs. We will cover the options available depending on your Confluence version in the next sections:
The scripts below are provided as is and Atlassian do not offer support for them. Make sure to test them in your staging instance before running on production.
For Confluence 5.10.0 and above
On newer versions of Confluence, we can rely on the REST API to achieve that goal. To do so, please follow the steps below:
- Download the Python script that will be used here: rest-add-watchers-script.py
- Edit the script you just downloaded and change the following lines only:
BASE_URL: This should be set to the server base URL of Confluence, as in the example (make sure to include the context path, if it exists):
BASE_URL = "https://mycompany.com"
USER: Set this variable to the username that will connect to Confluence through the REST API. It can be your normal user account.
PASSWD: Set this one to your password used to authenticate with the user above. Unfortunately, Confluence only supports basic auth for REST, so we need to explicitly pass the password.
GROUP_NAME: Set this variable to the group name that holds the users that will be added as watchers. If the group name has spaces, replace the space character with %20 (e.g "this group" should look like "this%20group").
CONTENTID: this variable must hold the content ID of the page or blog that we would like to add watchers. To find the ID, visit the page/blog and go to '... > Page Information'. Once you are in that page, you should see the CONTENT ID in the URL field of your browser as pageId=.
Execute the script as follows:
python rest-add-watchers-script.py
- Once the message "Finished adding users as watchers!" is printed, check the Manage Watchers section of the page in Confluence to see if the users are indeed there.
This script is compatible with both Python 2 and 3 versions.
For Confluence 5.9.14 and below
On those versions, we need to use the deprecated XML RPC APIs as the /group endpoint was not yet available through REST API. Also, the XML RPC API does not include a similar method to list group members, so we need to fetch them from the database. Please follow the steps below to run the script correctly:
Run the following query on your database to fetch all members of a specific group:
SELECT user_name FROM cwd_user WHERE id IN (SELECT m.child_user_id FROM cwd_membership AS m JOIN cwd_group AS g ON m.parent_id = g.id WHERE g.group_name = '<GROUP-NAME-HERE>');
Copy the output, making sure to exclude the headers (column name), and save it on a file called userlist.txt . The file should look like this:
admin anotheradmin user usertwo jdoe
- Download the XML RPC Python script here: xmlrpc-add-watchers-script.py
- Put the script in the same directory as the file userlist.txt that we just created.
- Edit the script you just downloaded and change the following lines only:
BASE_URL: This should be set to the server base URL of the server, as in the example (make sure to include the context path, if it exists):
BASE_URL = "https://mycompany.com"
USER: Set this variable to the username that will connect to Confluence through the REST API. It can be your normal user account.
PASSWD: Set this one to your password used to authenticate with the user above. Unfortunately, Confluence only supports basic auth for REST, so we need to explicitly pass the password.
CONTENTID: this variable must hold the content ID of the page or blog that we would like to add watchers. To find the ID, visit the page/blog and go to '... > Page Information'. Once you are in that page, you should see the CONTENT ID in the URL field of your browser as pageId=.
Execute the script as follows:
python xmlrpc-add-watchers-script.py
- Once the message "Finished adding users as watchers!" is printed, check the Manage Watchers section of the page in Confluence to see if the users are indeed there.
This script is compatible with Python 3 only. Refer to the comments inside the code on how to make it Python 2 compatible if needed.