Adding existing (and inviting new) users to a group

I have a specific use case that I’d like to know if there’s an easier way to do it.

  • Not all of our users (via our SSO) have active forum accounts
  • We regularly need to add users to a forum group, for access to a private forum
  • Whether users have active forum accounts isn’t known before attempting to add them to the group

For example:
Every month a staff member has a list of 100+ accounts that qualify for access to the private forum. Those accounts have SSO usernames and email addresses, but may not have a forum account yet.

:question: Is there a simple way to add people to a group if they already have forum accounts, and invite them to the forum (automatically adding to the group) if they do not?

On the Groups page, the Add Members button allows pasting in a comma-separated list of usernames. When those are valid usernames, and they’ll be added to the group. When a username isn’t valid (i.e. no forum account yet), that fails, and they aren’t added.

Short of manually scanning through the list of users successfully added to the group, identifying which usernames didn’t get added, and then sending those people a forum invitation (e.g. Multiple Use Invite Links) - is there a simple way that we can combine Invite and Add to Group for a mix of current and prospective forum users?

Ideally I’d like to find a one-step way of doing this.

A possible (but still very clunky!) multi step workaround might be something like:

  1. Enter list of names into a Data Explorer query that returns lists of active and inactive usernames
  2. Use “Add to Group” for the list of active usernames
  3. Send a custom Invite link to all the inactive users

If there’s a way of streamlining this, I’m all ears :slight_smile:

You would not be able to use data explorer. It’s a read-only tool.

Something like this would need to be newly created.

Have you looked into adding users to Discourse groups with the add_groups and remove_groups SSO parameters? For users who exist on your SSO provider site, you can create Discourse accounts for them, and add them to Discourse groups by making an API call to the sync_sso route. There are some details about setting that up here: Sync SSO user data with the sync_sso route. We can give you more details about how to set this up if it seems like an approach that could work for you.

1 Like

Thank Simon - that looks promising.

All of our users exist on the SSO site (they’re sellers in our marketplaces), but only a subset of those currently go on to create Discourse accounts to use our forums. That SSO covers both customers and sellers: we wouldn’t want to automatically create Discourse accounts for all the customers (there are way too many of them!), but doing so for all the sellers would simplify things dramatically.

In this case we need to grant access to private forum groups only to specific sellers, when they start to use specific marketplaces or services.

e.g. Seller on Marketplace 1 has an SSO account. They might create a Discourse account at this stage by logging in to the forums.

Later on, that seller gains access to Marketplace 2, and their SSO account will record that change. We have a custom user group (and private forum category) for that marketplace.

  • If they already have a Discourse account by this stage, we’ll need to update their groups so they can see the private forum area.
  • If they don’t have a Discourse account yet, we’d like to create one for them with the relevant groups.

The team currently uses “add to group” with a comma-separated list of usernames. If users already have a Discourse account, they get access to the group… if they aren’t on the forums yet, it does nothing.

To catch users who’ve created their Discourse accounts since the last time a batch was added to the group, the team usually includes all qualifying usernames from the last X months when trying to update the group membership, which is a fairly clunky process.

If you make an API call to the sync_sso route that includes the add_groups SSO parameter, existing users will get added to the group. If the user does not yet have a Discourse account, an account will be created for them and they will be added to the group. You can use the remove_groups SSO parameter in a similar way to remove users from groups. Another benefit of using the sync_sso route for this is that it doesn’t require the user to log out and back into Discourse for the change to have effect.

If looking at some example PHP/WordPress code would be useful for your team, you can see this implemented here: wp-discourse/utilities.php at master · discourse/wp-discourse · GitHub. The file I linked to contains some utility functions that sites can use to extend the WP Discourse plugin. That’s the reason that it uses static functions.

4 Likes

Thanks Simon! That sounds ideal - much better than our current method :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.