discourse/plugins/discourse-gamification/lib/discourse_gamification
Chris Alberti 9706fb8cfb
DEV: Allow multiple solutions in solved plugin (#39806)
Adds a site setting to allow multiple solutions to be accepted in the
solved plugin. Behavior without the setting enabled should remain as
before these changes.

### Model/DB changes

Previously, solutions were stored in a `SolvedTopic` model backed by the
`discourse_solved_solved_topic` table, which pointed to a topic id, a
post id, an accepting user id, and optionally a timer id for a timer to
auto-close the topic after a set amount of time if configured.

Now, the `SolvedTopic` model drops the post id and accepting user id,
but still points to the topic id and the timer id (there will only be
one timer per topic), and adds a has_many relationship to a new
`TopicAnswer` model. The `TopicAnswer` model backed by the
`discourse_solved_topic_answer` table points to a `SolvedTopic` id, a
post id and accepting user id, with one `TopicAnswer` for each accepted
solution post.

References to `topic.accepted_answer` or `topic.solved.accepted_post`
have been changed to `topic.accepted_answers.first` or
`topic.solved.topic_answers.first.post`, etc. Updated all specs/tests
and added new cases for the multiple solutions mode.

Several references in other build-in plugins are also fixed in this PR.

### Allow multiple solutions mode
These changes add the site setting `solved_allow_multiple_solutions`
which is disabled by default.

When disabled, behavior should be as it was before these changes. Users
can not accept multiple solutions for a single topic. If a post in the
topic is already marked as a solution, then the "Solution" button is
hidden, and if a user still accepts a different solution then the
original solution will be unaccepted.

When enabled, users can accept more than one solution for each topic.
Even if a solution is already accepted, other posts still show the
"Solution" button. Users can still unaccept any accepted solutions.

If a topic has multiple solutions, each one is displayed as a summary
under the OP using the existing component to represent the summary. For
displaying the solved checkmark icon, filtering, etc, a topic is
considered solved if it has at least one solution.

### UI

Added a PostExcerptAccordion component which displays post excerpts in
an accordion style with a header and expandable/collapsible items, and
that component is used to render the solution post(s) under the OP. The
first item is displayed expanded while the others are collapsed, by
default. The expanded items are truncated based on a number of lines
calculated from the `solved_quote_length` site setting, with a "read
more" link to view the full post.

Without multiple solutions allowed:
<img width="1606" height="1046" alt="image"
src="https://github.com/user-attachments/assets/5d6229f2-9052-473a-8953-574667761544"
/>

With multiple solutions allowed:
<img width="1594" height="1254" alt="image"
src="https://github.com/user-attachments/assets/6e7b7ac5-23fa-4b0e-b6d6-b8a53cdf2756"
/>

With multiple solutions, after expanding each:
<img width="932" height="1000" alt="image"
src="https://github.com/user-attachments/assets/2a8842b6-040d-44d8-bad4-f61d819789ef"
/>

### QAPage schema

The QAPage schema metadata is updated to include multiple accepted
solutions, which is allowed according to [google's QAPage
doc](https://developers.google.com/search/docs/appearance/structured-data/qapage#question)

---------

Co-authored-by: discourse-patch-triage[bot] <272280883+discourse-patch-triage[bot]@users.noreply.github.com>
Co-authored-by: Manuel Kostka <manuel@discourse.org>
2026-05-28 07:12:28 -05:00
..
scorables DEV: Allow multiple solutions in solved plugin (#39806) 2026-05-28 07:12:28 -05:00
directory_integration.rb FEATURE: Per-leaderboard scorable weights and category filters (#39062) 2026-04-23 11:23:01 -03:00
engine.rb DEV: Clean up scope resolution operators in plugins (#34979) 2025-09-30 14:36:34 +02:00
guardian_extension.rb DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
leaderboard_cached_view.rb DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00
recalculate_scores_rate_limiter.rb
user_extension.rb DEV: Enable Style/RedundantSelf rubocop rule (#40098) 2026-05-19 19:27:45 +02:00