Add baseline_score attribute to Article with admin UI and one-click set to min indexing#23605
Merged
benhalpern merged 1 commit intoJul 14, 2026
Conversation
Contributor
|
Thank you for opening this PR! We appreciate you! For all pull requests coming from third-party forks we will need to A Forem Team member will review this contribution and get back to |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an Article#baseline_score override that admins can set via the moderation UI to ensure an article’s calculated score does not fall below a chosen minimum (e.g., the minimum indexing score).
Changes:
- Add
baseline_scorecolumn toarticlesand model validation. - Update
Article#update_scoreto apply a baseline floor and expose the field through admin strong params + admin article form UI (including a “set to min indexing” button). - Add model specs validating
baseline_scorebehavior and numericality checks.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/models/article_spec.rb | Adds validations + scoring specs for baseline behavior. |
| db/schema.rb | Reflects new articles.baseline_score column. |
| db/migrate/20260714173500_add_baseline_score_to_articles.rb | Introduces the baseline_score column. |
| config/locales/views/moderations/en.yml | Adds admin UI strings for baseline score controls. |
| config/locales/views/moderations/fr.yml | Adds admin UI strings for baseline score controls (FR). |
| config/locales/views/moderations/pt.yml | Adds admin UI strings for baseline score controls (PT file, but locale key issue noted in comments). |
| app/views/admin/articles/_article_item.html.erb | Adds baseline score input + one-click “set to min indexing” button. |
| app/models/article.rb | Validates and applies baseline_score during score recalculation; includes it in limited selects. |
| app/controllers/admin/articles_controller.rb | Permits baseline_score in admin updates. |
Comment on lines
1006
to
+1009
| accepted_max = [max_score, user&.max_score.to_i].min | ||
| accepted_max = [max_score, user&.max_score.to_i].max if accepted_max.zero? | ||
| self.score = accepted_max if accepted_max.positive? && accepted_max < score | ||
| self.score = baseline_score if baseline_score.positive? && score < baseline_score |
Comment on lines
+2360
to
+2381
| context "when baseline_score is set" do | ||
| it "uses the baseline score if the natural score is lower than baseline_score" do | ||
| article.update_column(:baseline_score, 15) | ||
|
|
||
| article.update_score | ||
| expect(article.reload.score).to eq(15) | ||
| end | ||
|
|
||
| it "uses the natural score if it is higher than baseline_score" do | ||
| article.update_column(:baseline_score, 5) | ||
|
|
||
| article.update_score | ||
| expect(article.reload.score).to eq(10) | ||
| end | ||
|
|
||
| it "uses the natural score if baseline_score is 0" do | ||
| article.update_column(:baseline_score, 0) | ||
|
|
||
| article.update_score | ||
| expect(article.reload.score).to eq(10) | ||
| end | ||
| end |
| @@ -0,0 +1,5 @@ | |||
| class AddBaselineScoreToArticles < ActiveRecord::Migration[7.2] | |||
| def change | |||
| add_column :articles, :baseline_score, :integer, default: 0 | |||
| </label> | ||
| <div class="flex gap-2"> | ||
| <input id="baseline_score_<%= article.id %>" class="crayons-textfield" type="number" name="article[baseline_score]" value="<%= article.baseline_score %>"> | ||
| <button type="button" class="c-btn c-btn--secondary" onclick="document.getElementById('baseline_score_<%= article.id %>').value = <%= Settings::UserExperience.index_minimum_score %>"> |
Comment on lines
+158
to
+160
| baseline_score: Pontuação de referência | ||
| no_baseline_if_zero: Sem pontuação de referência se definido para zero | ||
| set_to_min_indexing: Definir para a indexação mínima |
…et to min indexing
benhalpern
force-pushed
the
feature/add-baseline-score-to-articles
branch
from
July 14, 2026 17:51
6868f64 to
a94e690
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this? (check all applicable)
Description
Allow to assign baseline score to an article in case it was flagged as low score wrongly etc. Simple override in case other overrides are over-complicated.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.