Good afternoon. I have a Buy/Sell/Trade category on my site that I’d like to restrict posting in until a member “likes” the rules topic. I asked the AI Bot, and it did give me some instructions. However, it seems that it requires Discourse Automation that is only available on hosted plans.
Is there a way that I can do this on my self-hosted platform?
add-users-to-group: accepts a single group as input; users who accept the policy will be automatically added into this group (when policy is manually revoked or if the policy version is updated, user(s) gets removed from group)
I had to enable badge sql and then create a badge that is assigned when someone likes the specific post. I then created a group that Discord Automation auto assigns based on a user having the badge. I have the “everyone” group only read access to category so they can only react. I gave the custom group full access.
Just in case anyone else is interested in doing this, here is a short writeup of what I did:
First, you need to enable Badge SQL through your Discourse server’s CLI:
./launcher enter app
rails c
SiteSetting.enable_badge_sql = true
Next, find the ID of the topic that you want the members to interact with in order to get the badge. In my instance, the topic ID is 117
Create your Custom Badge:
Admin>Badges>New
Name the badge whatever you want (ex. B/S/T Rule Reader)
Choose a badge type, icon, and give it a description
If you followed Step 1, you will see a query box where you can type in a SQL query. Paste this query (change p.topic_id = 117 to whatever your topic ID is):
SELECT DISTINCT ON (pa.user_id)
pa.user_id,
pa.post_id,
pa.created_at granted_at
FROM post_actions pa
JOIN posts p ON pa.post_id = p.id AND p.post_number = 1
WHERE pa.post_action_type_id = 2
AND p.topic_id = 117
AND (:backfill OR pa.post_id IN (:post_ids))
Make sure Run revocation query daily and Query targets posts are both checked.
The trigger should be set to When a user acts on post
Now we create the Automation
First create a new group for the members to be added to. Mine is just named bst_rules_agreed, and it is set so only group owners and mods can see the membership. It does not need any kind of Trust Level effects.
Next, go to Plugins>Automation
Add a new automation
Choose User Group Membership Through Badge
Trigger: Recurring
Recurrence: I have mine set to every 1 hour. Choose what makes sense to you.
Choose a start date
Script Options:
Badge: Choose the badge you created above
Group: Choose the group you created above
That’s it. You should now have a system that makes sure members have agreed to the rules of the category before they are able to post in the category.
My next exploration is to see if there is a way to hide all topics except the rules to everyone that isn’t in that group. But, this basic system is good enough for now.
Thanks for this plugin! I was looking for a way to provide a basic ticketing system in our community.
I’m also thinking of using this in my Buy/Sell/Trade category. Right now I have it set where everyone can read topics, but only people in a specific group can reply and create. The current workflow is: Member acknowledges that they read the rules by liking the post. Once they like the post, they are granted a custom badge. Discourse Automate adds them to the group based on the badge.
This stops people that haven’t accepted the rules from posting in the category. However, they can still see/read all of the postings.
So, would it work if I remove everyone from the category and only have that custom group in the security tab? As long as I have posts from the Admin group always visible, would people not in the custom group still be able to see and like the rules? Then, once they like and are added to the group, everything opens for them?
Your use case can be implemented without this plugin, using the Discourse Policy plugin instead, which has the ability to add users who accepted the policy to a group.
I looked at the Policy plugin before I started down the rabbit hole of the way I ended up assigning the group membership. The reason I don’t like the Policy for this is because it has to be applied to a group. I would have to apply it to something like trust_level_1 to make sure everyone that wants to be a part of B/S/T sees it. But, not everyone wants to participate in B/S/T. I don’t want to hound them with another thing to click (even though it is quick) if they aren’t interested in it.
make a group “BST applicants” and a group “BST members”
have “BST applicants” be a group that can be freely joined
have a policy which applies to “BST applicants” and adds to “BST members”
grant “BST members” access to the category
People will join “BST applicants”, accept the policy and become member of “BST members”. Hairy but less hairy than triggering a complete Rube Goldberg machine by liking a post.