discourse/app/services
Régis Hanol 5cef23ef63
FEATURE: award badges based on topic votes received (#39493)
Adds four tiered badges to discourse-topic-voting so topic authors are
recognized when their ideas get traction:

- Daydreamer (Bronze, 1 vote)
- Brainstormer (Silver, 5 votes)
- Innovator (Silver, 15 votes)
- Visionary (Gold, 25 votes)

Badges are multi-grant and tied to the qualifying topic's first post, so
a user earns each tier once per topic that reaches the threshold.
Self-votes (voting on your own topic) are excluded. All badges are
disabled by default; the Silver and Gold tiers (Brainstormer, Innovator,
Visionary) allow the badge to be used as a title when enabled.

<img width="287" height="216" alt="image"
src="https://github.com/user-attachments/assets/3a84c2b2-6157-4504-b5a5-45e7c660e90c"
/>


### How it is wired

- `Votes::Cast` enqueues a `BackfillBadges` job after a vote is cast.
- `TopicMerger.merge` and `VoteReclaim` also enqueue the job so merged
or reclaimed topics are re-evaluated immediately rather than having to
wait for the daily consistency pass.
- The job calls `BadgeGranter.backfill` scoped to the topic's first
post. Queries join `badge_posts`, which already filters out deleted and
unlisted topics, read-restricted categories, and categories with
`allow_badges` disabled.
- Each query returns `granted_at` as the timestamp of the Nth qualifying
vote (via `ROW_NUMBER()`), so every tier reflects when that threshold
was actually crossed rather than when the most recent vote landed.
- Revocation (vote removed, topic deleted, category changed) runs on the
daily full backfill via `auto_revoke`, consistent with how
discourse-solved handles the same pattern.

### Notification handling

To avoid "granted badge" notification avalanches when the feature is
first enabled on a community with years of existing votes, core now
exposes a `:badge_granter_suppress_notification` modifier. The plugin
registers it and suppresses notifications for its four badges when the
qualifying vote is older than 2 weeks. Combined with the per-tier
`granted_at`, this means only the tier the author just crossed produces
a notification; lower tiers whose threshold was reached long ago stay
silent.

Ref - t/182304
2026-04-28 10:53:06 +10:00
..
admin/search DEV: Refactor admin search index into a service (#38959) 2026-04-01 10:09:10 +10:00
admin_notices FEATURE: Add problem checks page to admin panel and allow ignoring problem checks (#39103) 2026-04-23 08:28:33 +08:00
categories FEATURE: Add "Ideas" category type for Topic Voting plugin (#38794) 2026-04-14 11:27:18 +02:00
category DEV: Replace Ruby numbered parameters by it where applicable (#37810) 2026-02-13 13:59:07 +01:00
discourse_id DEV: Allow new instances to be set up directly with Discourse ID (#36731) 2025-12-23 12:13:36 -05:00
flags FEATURE: allow edit custom flags (#32344) 2025-04-17 12:31:52 +08:00
groups DEV: Replace Ruby numbered parameters by it where applicable (#37810) 2026-02-13 13:59:07 +01:00
nested_topic FIX: Show suggested and related topics on nested replies view (#39473) 2026-04-23 12:05:20 -03:00
notification/action FEATURE: Notify admins of upcoming changes and log events (#37003) 2026-01-21 12:45:54 +10:00
notifications FEATURE: Consolidate link notifications (#26567) 2024-04-09 11:53:37 -06:00
problem_check DEV: Remove enable_upcoming_changes global setting gate (#38360) 2026-03-10 10:08:20 +10:00
site_setting DEV: Fix a SiteSetting::Update leak (#39556) 2026-04-27 02:53:43 +02:00
spam_rule FIX: Moderator notifications when new post auto-silences a user (#35403) 2025-10-15 16:07:56 +08:00
tags UX: Truncate category list in disabled tag reasons (#39315) 2026-04-17 09:03:43 +02:00
themes FIX: Add delete button to themes grid (#34606) 2025-08-29 10:09:23 +08:00
upcoming_changes PERF: Cache has_unseen_features? to avoid per-request git shell-outs (#39532) 2026-04-24 10:16:46 -07:00
user SECURITY: Enforce edit permissions and audit trail in TriggerPostAction 2026-03-19 15:21:28 +00:00
video_conversion FEATURE: Add opt-in IAM role assumption for S3 operations (#39174) 2026-04-15 04:29:50 +08:00
anonymous_shadow_creator.rb UX: Improve naming for anonymous mode settings (#31832) 2025-03-21 04:54:06 +03:00
badge_granter.rb FEATURE: award badges based on topic votes received (#39493) 2026-04-28 10:53:06 +10:00
base_bookmarkable.rb SECURITY: Ensure guardian check when creating QueryGroupBookmark 2026-02-26 12:22:54 +00:00
category_hashtag_data_source.rb FIX: Use unaccent() for category name/slug search (#37622) 2026-02-12 08:43:23 +01:00
color_scheme_revisor.rb FEATURE: Allow editing theme-owned palettes (#34722) 2025-10-06 09:02:39 +03:00
destroy_task.rb FIX: Confirmation prompt breaks when using pipe (#35261) 2025-10-08 11:12:09 +08:00
email_settings_exception_handler.rb DEV: Remove IMAP support in Discourse (#37002) 2026-01-12 10:07:26 +10:00
email_settings_validator.rb DEV: Remove IMAP support in Discourse (#37002) 2026-01-12 10:07:26 +10:00
email_style_updater.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
external_upload_manager.rb FIX: Enforce content disposition on S3 presigned URLs (#38850) 2026-03-27 10:04:00 +08:00
group_action_logger.rb PERF: Add Users to Group Improvements Pt. 2 (#38901) 2026-04-06 09:31:50 -05:00
group_mentions_updater.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
group_message.rb DEV: Don't allow context-free system post destruction (#32523) 2025-05-05 09:58:29 +08:00
handle_chunk_upload.rb DEV: Fix assigned but unused variable Prism warnings (#39436) 2026-04-22 12:42:14 +02:00
hashtag_autocomplete_service.rb DEV: Remove experimental_hashtag_search_result_limit setting (#38009) 2026-02-24 16:31:03 +10:00
heat_settings_updater.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
hub_push_notification_pusher.rb DEV: Centralize push notification delivery into a single job (#39207) 2026-04-14 11:55:45 -03:00
inline_uploads.rb FIX: Escape markdown characters in upload filenames (#39133) 2026-04-14 10:37:41 +02:00
locale_normalizer.rb FIX: Show localization for regionless locale if they exist (#33702) 2025-07-21 15:45:14 +08:00
notification_emailer.rb FIX: Send notification emails for staff-coloured posts (#37712) 2026-02-11 13:26:27 +01:00
post_action_notifier.rb DEV: route bulk tag actions through PostRevisor (#37848) 2026-02-24 14:39:01 +01:00
post_alerter.rb DEV: Centralize push notification delivery into a single job (#39207) 2026-04-14 11:55:45 -03:00
post_bookmarkable.rb FIX: Serialize categories for bookmarks (#26606) 2024-04-17 17:23:47 +03:00
post_owner_changer.rb SECURITY: Ensure moderator can see post/topic before allowing them to change owner 2026-01-28 17:11:14 +00:00
push_notification_pusher.rb FIX: only clear current device push subscription on logout (#39266) 2026-04-15 11:39:42 -03:00
random_topic_selector.rb DEV: Remove Discourse.redis.delete_prefixed (#22103) 2023-06-16 12:44:35 +10:00
registered_bookmarkable.rb FIX: Bookmarkable query placholders (#35935) 2025-11-10 12:36:53 +10:00
search_indexer.rb FEATURE: Add full-text search for chat messages (#34704) 2025-10-22 11:30:35 +02:00
sidebar_section_links_updater.rb DEV: Limit the number of category sidebar links a user can have (#26756) 2024-04-25 13:21:39 -05:00
sidebar_site_settings_backfiller.rb DEV: Drop distributed mutex fromSidebarSiteSettingsBackfiller#backfill! (#25674) 2024-02-15 06:21:03 +08:00
site_setting_update_existing_users.rb FEATURE: Convert watched_precedence_over_muted to default site setting (#35671) 2025-10-30 10:04:18 +10:00
site_settings_task.rb FEATURE: mandatory fields for group site setting (#26612) 2024-04-18 08:53:52 +10:00
staff_action_logger.rb SECURITY: Restrict staff action logs visibility for moderators 2026-01-28 17:11:14 +00:00
tag_hashtag_data_source.rb FIX: Tag search 500 when content_localization is enabled (#37769) 2026-02-12 23:58:03 +08:00
tag_settings_updater.rb DEV: Setup backend for dedicated tag settings page (#37804) 2026-02-13 17:14:49 +08:00
theme_settings_migrations_runner.rb DEV: Add category helper for theme migration (#38816) 2026-03-24 16:50:37 +08:00
themes_install_task.rb FEATURE: Theme settings migrations (#24071) 2023-11-02 08:10:15 +03:00
topic_bookmarkable.rb FIX: Serialize categories for bookmarks (#26606) 2024-04-17 17:23:47 +03:00
topic_status_updater.rb DEV: Add automatically closed topics event trigger and adapt the automation plugin's auto tag_topic_script accordingly (#39235) 2026-04-14 14:50:36 -05:00
topic_timestamp_changer.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
tracked_topics_updater.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
trust_level_granter.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_action_manager.rb FIX: permanent delete of posts by deleted users (#28992) 2024-09-24 12:26:31 +03:00
user_activator.rb DEV: Change authenticated_with_oauth to use key instead of string. (#38381) 2026-03-10 18:31:32 -03:00
user_anonymizer.rb FIX: Block associated account emails on user delete and anonymize (#37638) 2026-02-09 18:26:35 +01:00
user_authenticator.rb DEV: Move more data into the server session (#35145) 2025-10-03 10:20:32 +02:00
user_destroyer.rb FIX: Delete reviewable notes before reviewables during user deletion (#38709) 2026-03-19 16:12:53 +08:00
user_merger.rb FIX: blocks post action merge for duplicated flags (#36265) 2025-11-26 16:17:57 -03:00
user_notification_renderer.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_notification_schedule_processor.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_password_expirer.rb DEV: Migrate user passwords data to UserPassword table (#28746) 2024-10-10 09:23:06 +08:00
user_silencer.rb FIX: Include silence reason for auto-silenced users (#35898) 2025-11-12 07:53:53 +08:00
user_stat_count_updater.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
user_suspender.rb FIX: only clear current device push subscription on logout (#39266) 2026-04-15 11:39:42 -03:00
user_updater.rb DEV: Fix assigned but unused variable Prism warnings (#39436) 2026-04-22 12:42:14 +02:00
username_changer.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
username_checker_service.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
web_hook_emitter.rb DEV: Move webhook event header modifier for redelivery-recalucation (#27177) 2024-05-24 10:37:10 -05:00
wildcard_domain_checker.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
wildcard_url_checker.rb DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
word_watcher.rb FIX: unify watched word boundary regex across Ruby and JS engines (#37965) 2026-02-23 16:30:10 +01:00