Skip to content

Add baseline_score attribute to Article with admin UI and one-click set to min indexing#23605

Merged
benhalpern merged 1 commit into
forem:mainfrom
benhalpern:feature/add-baseline-score-to-articles
Jul 14, 2026
Merged

Add baseline_score attribute to Article with admin UI and one-click set to min indexing#23605
benhalpern merged 1 commit into
forem:mainfrom
benhalpern:feature/add-baseline-score-to-articles

Conversation

@benhalpern

@benhalpern benhalpern commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

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.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Copilot AI review requested due to automatic review settings July 14, 2026 17:38
@benhalpern
benhalpern requested review from a team as code owners July 14, 2026 17:38
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for opening this PR! We appreciate you!

For all pull requests coming from third-party forks we will need to
review the PR before we can process it through our CI pipelines.

A Forem Team member will review this contribution and get back to
you as soon as possible!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_score column to articles and model validation.
  • Update Article#update_score to 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_score behavior 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 thread app/models/article.rb
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
@benhalpern
benhalpern force-pushed the feature/add-baseline-score-to-articles branch from 6868f64 to a94e690 Compare July 14, 2026 17:51
@benhalpern
benhalpern merged commit 434882a into forem:main Jul 14, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants