An 'add to group' script for the Discourse Automation

In Discourse Automation, it would be really useful to be able to add a user to a group automatically, and be removed from a group automatically.

Use cases:

  1. To have the function and access of a group apply to those who have completed a specific task
  2. To enable functional sub-groups. For example, if a user is put in a group of Data Scientists, they are also put in the broader group of IT Professionals. If removed from the IT Professionals group, they are also removed from the Data Scientists group.
  3. To allow the membership of groups to be granted and revoked via SQL (from Badges - this really expands the scope)
10 Likes

Greetings! Very good suggestion, I was just looking for a similar solution, but unfortunately, as I understand Discourse Automation does not support such a function(

We do have this one now. :+1:

Have a look for the ‘User Group Membership through Badge’ script when you create an Automation.

There’s also the ‘Add user to group through User Custom Field’ too, if that’s any use:

5 Likes

That is handy, and meets my 1. and 3. with aplomb!

All that remains is 2. - which I note has recently been requested by someone else:

This of course could be worked around by having a badge with SQL that picks up on the group membership, and then a script that then assigns the other. But that is a bit messy / clunky and results in a collection of redundant badges.

2 Likes

A somewhat related request that I think has come up a few times is to have some way of dealing with AND logic for category security permissions: Identifying users in multiple groups using AND rather than OR?. In the topic I linked to, they want to create a group for people who are in the trust_level_3 and year_2 groups. This could be accomplished with the Automation plugin now with a custom badge query, but as was noted by Nathan, that’s a messy way of solving the problem. It’s also limited to sites that are able to add custom badge SQL.

I’m posting this here because it might be useful to have requests for scripts related to the user_added_to_group and user_removed_from_group triggers in one topic.

Nice spot. :+1: Let’s close this topic off as two of the three have been implemented and we can track the remaining one better in the dedicated feature request.

1 Like

Remaining item tracked in Add script to add user to user group