Discourse Dynamic Groups

:information_source: Summary Automatically manage group membership
:hammer_and_wrench: Repository Link https://github.com/communiteq/discourse-dynamic-groups
:open_book: Install Guide How to install plugins in Discourse

:warning: This plugin should be considered beta :warning:

Features

Discourse communities often need to automate group memberships based on conditions like badge ownership or existing group memberships.

Common use cases include:

  • Users not in the ‘subscribers’ group

  • Users not banned from posting in Marketplace

  • Users at TL0 or TL1, but not TL2

  • Users who have completed the new user tutorial or have been members for over a year

  • Users belonging to client_1, client_2, or client_3 and are not an intern

Previously, solving this required custom scripts that periodically synchronized groups. The Dynamic Groups plugin eliminates that need.

This plugin introduces a boolean expression field to group settings, allowing administrators to define rules that dynamically determine group membership.

Examples:

  • users who are not in the ‘subscribers’ group
    trust_level_0 AND NOT subscribers

  • users who are not banned from posting in Marketplace
    trust_level_2 AND NOT banned_users

  • users who are on TL0 or TL1 but not on TL2
    trust_level_0 AND NOT trust_level_2

  • users who completed the new user tutorial or are member for over a year
    badge:certified OR badge:anniversary

  • users who belong to client 1, 2 or 3 and are not an intern
    (client_1 OR client_2 OR client_3) AND NOT interns

Configuration

Once the plugin is installed and enabled, a new tab will appear in the group admin interface:

When you enter or update the boolean expression, the system will take a few moments to populate the group with matching users. From that point on, group membership will be automatically updated as user status changes.

Important:
When a rule is defined, the group is marked as automatic, disabling manual member changes. To revert the group to manual management, simply clear the expression field. The existing members will remain, and you’ll regain manual control.

27 Likes

Wow! Awesome work, Richard!

This fills a large gap in group management within Discourse. Totally delighted, and looking forward to giving it a good run.

I’ll be primarily using it to enable functional subgroups.

4 Likes

Definitely a welcome addition to Discourse’s features!

2 Likes

7 posts were merged into an existing topic: Only the first entry working with Multiselect fields when User first logged in Trigger used

Hi, thank you for developing this super useful plugin!

I’m currently using Discourse Dynamic Groups to automatically add all non-anonymous users to a special group. My boolean expression is:

NOT anonymous_users
Expected behavior:
When a new user registers (who does not belong to the anonymous_users group), they should be automatically added to this group, without any manual intervention.

Actual behavior:
Newly registered users are not immediately added to the group. They only get added after I manually re-save the boolean expression in the group settings.
This means the group is not updated automatically as users join, unless I trigger a manual sync.

1 Like

Hmm… good catch. And I do agree that this should be expected behavior.

From a technical POV, the plugin will only reevaluate group membership on two different conditions:

  1. When the boolean expression in the group settings is saved
  2. If a user is added or removed for a group mentioned in the boolean expression.

When a new user registers, neither is the case.

Can you try to change the expression to trust_level_0 AND NOT anonymous_users and report back if that resolves the issue?

3 Likes

Hi,

When I try to use the expression

trust_level_0 AND NOT anonymous_users

I get the error:
Unknown keyword, group or badge: 'anonymous_users'

If I change the group name to my actual group, for example:

trust_level_0 AND NOT interns

I still get:
Unknown keyword, group or badge: 'interns'

I have double-checked and I am copying the group’s unique name directly from the group admin page, so there are no typos.
Is there anything I might be missing, or is there something else I need to configure for custom groups to be recognized in the expression?

4 Likes

Thank you for reporting this.

While trying to reproduce, I have identified two bugs and one of them probably hit you.
Can you please update the plugin to the latest version 59640f1 and see if that resolves the issue.

The plugin still does not deal with renaming groups very well. If you rename a group you should save the rules from all groups that depend on it (just enter a space after the boolean expression and remove it again to enable the Save button). This will be addressed in a later version.

3 Likes

Is this using your Category restrictor plugin or thi functions independently from it?

awesome plugin to fill in gaps.

It functions independently.

1 Like

Hi,

I am using the Dynamic Groups plugin and set my criteria as:

trust_level_0 AND NOT anon_group

However, I have noticed that users with trust_level_1 who are not in the anon_group are also being added to this dynamic group.

Could you please confirm if this is the expected behavior, or if this is a bug?

Users with trust level 1 are also members of the trust level 0 group. So the behavior is expected. You could exclude the trust level 1 group to only get TL0 users. Similar to the example from the first post

2 Likes

Thank you for the clarification

I absolutely :heart: this plugin - it is just super helpful for several use-cases. Cudos again to the Communiteq team for sharing and maintaining it!

UX thing - Would it be better to hide the key fields rather than the whole Membership tab?

I note that it hides the Membership tab of Group pages. I mean this one:

While I can understand why, this does cause some problems when you want to muck about with the Default title, Flair, and Effect.

This can be worked around by either revealing the tab in the browser console, or removing the expression in the Dynamic Groups tab, refreshing, making the changes, pasting it back again, and again refreshing.

But I do wonder if it might be better to just hide the fields that aren’t helpful instead, rather than the whole tab. Something more like this:

I do agree with your suggestion, but…

This is core functionality.
A dynamic group is marked as “automatic” and then the Membership tab will disappear.

That won’t work, since Discourse core won’t output the tab at all. It’s not hidden, it’s simply not there.

1 Like

Yeah, I worked that out in the time between posting and you replying!! I hadn’t appreciate that you hook into core functionality with it - slickly done too.

Have crossed out my incorrect suggestion.

I guess the other workaround I outlined is fine then.

It does raise another problem that I hadn’t realised - automatic groups are NOT visible to non-staff users. And that is deeply coded in. Rats!

1 Like

I didn’t realize that either!

We’re going to do a maintenance round on all plugins in the next month or so, maybe we need to revisit the ‘automatic’ flag since as far as I recall it was just a quick way on disabling the add/remove members functionality. All other things are probably unwanted side effects.

1 Like