This guide explains how to add existing users from one or more groups to other groups using a combination of Data Explorer and bulk invites.
Required user level: Administrator
Summary
This guide will show you how to:
- Create a Data Explorer query to select users from specific groups
- Download the query results as a CSV file
- Use the bulk invite feature to add these users to new groups
Requirements
- Data Explorer plugin installed
- Administrator access to your Discourse instance
Always create a backup before performing bulk operations on user groups.
Creating the Data Explorer query
- Go to Admin → Plugins → Data Explorer
- Create a new query
- Name your query (e.g., “Select users for group addition”)
- Paste the following SQL code into the query input:
--[params]
-- string_list :group_name
-- string_list :new_group_names
SELECT ue.email as "address@email", :new_group_names as "new group"
FROM users u
INNER JOIN group_users gu ON u.id = gu.user_id
INNER JOIN groups g on g.id = gu.group_id
INNER JOIN user_emails ue on u.id = ue.user_id
WHERE g.name IN (:group_name)
AND ue.primary = true
- Click “Save Changes”
- Reload the page if the
group_name
andnew_group_names
inputs don’t appear
Your Data Explorer screen should now look like this:
Running the query and downloading results
- Enter the source group name(s) in the
group_name
field - Enter the target group name(s) in the
new_group_names
field - Run the query to verify the output
- Download the results as a CSV file by clicking the CSV button
To select users from multiple groups, separate group names with a comma (,). To add users to multiple groups, separate group names with a semicolon (;).
Bulk inviting users to new groups
- Go to Admin → Send Invites → Bulk Invite
- Select the CSV file you downloaded
- Click “Bulk Invite” to process the file
You may receive an automated message about an invalid email address. This is normal and can be ignored, as it’s due to the CSV header being treated as data.
Verifying group additions
After the bulk invite process, check the target group(s) to ensure that the users have been added correctly.
For example, if you started with these users in the “grapes” group:
And the “fruits” group was initially empty:
After the bulk invite, the “fruits” group should now be populated:
Users added to new groups using this method will not receive any email or notification about being added to the new group(s).
Selecting multiple groups
You can select users from multiple groups and add them to multiple groups:
- To select users from multiple groups, separate group names with a comma (,):
grapes,cherries
- To add users to multiple groups, separate group names with a semicolon (;):
fruits;vegetables
Additional resources
Last edited by @hugh 2024-07-16T03:08:28Z
Last checked by @hugh 2024-07-16T03:08:35Z
Check document
Perform check on document: