How to see that a Topic has earned a badge

I am using Discourse to run online courses ( ). It’s working pretty well, but what I want to do now is to use badges to start to automate how people’s Topics and posts get turned into grades.

I have created an “exemplary solution” badge that is turned on when I use a keyword in a reply to a topic that meets the requirements for the challenge.

    WITH replies AS (
    SELECT user_id, id, topic_id, post_number, reply_to_post_number
    FROM posts
    WHERE raw LIKE '%Looks good!%' AND
    reply_to_post_number IS NOT NULL AND
    user_id IN  (
        SELECT gu.user_id
        FROM group_users gu
        WHERE group_id IN(
            FROM groups g
            WHERE IN ('QuestMasters')
SELECT p.user_id, post_id, p.created_at granted_at,
FROM posts p, replies r
WHERE r.reply_to_post_number = p.post_number AND
r.topic_id = p.topic_id and
(:backfill OR IN (:post_ids) )

(I would also like code to similarly mark a post when a member of a group “likes” the post, but that’s for another topic.)

This code works and I can see the post in the list of badges, but when looking at the post there is no way to see that the badge is connected to it.

See for example:

nice topic from meta that links to this post. You can see that there’s a “nice topic”, but when you see the topic itself, there’s no indication. Is there some way to see that?


This would require a plugin, the info is not shipped to client till likes are expanded.

You would need to amend serialization like the solved plugin does

1 Like

Thanks, @sam.

I’m looking at using Discourse as a MOOC platform. It’s worked well to run my classes this summer. I’d have people reply-as-linked topic to the assignments (aka “quests”). And I’d “like” their topic when they got it right. I think now that with badges, I can not only give them badges when I approve their work, but also have more complicated ones that, e.g., let people who have achieved a badge give it to someone else.

And it looks like the solved plugin will get me moving forward. Thanks!

OK. “solved” looks like a pretty good starting place, though I want sort of the opposite of what it does.

This is the wrong place for this question, I think , but do I have to

./launcher rebuild app

every time I make a code change to see if it works?

No, you should be doing plugin development with a development server.


I’m getting closer. I have set up a development server. It’s working. Mailcatcher is working. I’m logged in as eviltrout and as myself. I have the solved plugin installed, and can mark the “allow solved on all topics” in settings, so I’m sure that it’s installed, but the solved button isn’t showing up (and I’ve tried turning it on for the topic I’m working in too). I’ve installed it on my production server and it does work there, so I think I know how it’s supposed to work.

Does anyone have any hints to offer? This has been a long way to “Hello, world” and the end isn’t yet in sight.

1 Like