Add script to add user to user group

There is currently a script in the Automation plugin to add users to a group based on a custom field. We would like a script to add users to a group, when they’re added to another group.

The scenario is this: The Discourse Experts plugin expects you to only have one user group designated for “experts”. We are running an ambassador program and have two tiers of ambassadors—both of which are “experts” in this case.

We would like to say, anyone added to “Ambassadors” or “Expert Ambassadors” also gets added to the “Experts” user group.

5 Likes

If you are up to sponsoring this I don’t see it as too complicated, we can quote the work. Contact team.

2 Likes

Also requested in:

2 Likes

Other than the topic @JammyDodger linked to, there have been a few other requests for similar functionality

There have also been requests to be able to display groups in a hierarchical manner:

I’m noting this just to make sure that adding an Automation script is the best way to deal with this, or if it’s functionality that should get added to the core Discourse groups code.

I’ve been fiddling around with this for fun. It’s kind of related to some recent work I’ve been doing with Zapier. Feel free to ignore the rest of this post.

Assuming an Automation script is the right approach, the only stumbling block is that the Automation plugin’s group component only accepts a single group. So either the group component needs to be updated to accept more than one group, or a new groups component needs to be added. I added a groups component to my local dev branch to test it out. With that in place:

Add a user to a parent group when they are added to any of a list of subgroups:

Remove a user from a parent group if they have been removed from all of the listed subgroups:

If it helps, the triggers and scripts are in a plugin: https://github.com/scossar/automation-script-example/blob/main/plugin.rb#L13-L98. Note that this code assumes that a groups component has been added to https://github.com/discourse/discourse-automation/tree/main/assets/javascripts/discourse/components/fields.

3 Likes