Skip to content

Load scratch projects in correct locale - #1010

Merged
zetter-rpf merged 1 commit into
mainfrom
load-scratch-projects-in-correct-locale
Sep 10, 2026
Merged

Load scratch projects in correct locale#1010
zetter-rpf merged 1 commit into
mainfrom
load-scratch-projects-in-correct-locale

Conversation

@zetter-rpf

@zetter-rpf zetter-rpf commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Status

Points for consideration:

In most places in editor we only have one locale per project. One place this isn't true is the new Preview page for Experience CS scratch projects- there are multiple projects that share one identifier with translated content.

Use the existing ProjectLoader to load the project in the correct locale. See commits for more

In most places in editor we only have one locale per project. One place this isn't true is the new Preview page for Experience CS scratch projects- there are multiple projects that share one identifier with translated content.

Elsewhere we are loading projects we use ProjectLoader, make sure we use it here to load Scratch projects too.

Since we have limited ways that we can alter Scratch, we can't easily pass in a param with the locale. Instead use a header. An alternative would be to use a cookie (this is what ExCS currently does).

I received an n plus one warning for loading Scratch Components - putting an include in here causes bullet to warn elsewhere as we don't always need to load the Scratch component. Since this is just a 1+1 query, I think this is fine to ignore.
@cla-bot cla-bot Bot added the cla-signed label Sep 10, 2026
@zetter-rpf
zetter-rpf marked this pull request as ready for review September 10, 2026 15:08
Copilot AI lite review requested due to automatic review settings September 10, 2026 15:08
@github-actions

Copy link
Copy Markdown

Test coverage

93.55% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/34493666369

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.

🟡 Changes recommended

The new locale-based lookup can incorrectly 404 when the preferred-locale record is non-scratch but a scratch project exists for the same identifier in a fallback locale (regression vs the prior scratch-type-scoped lookup).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the Scratch projects API to load projects in the locale requested by the client (via X-Project-Locale), aligning Scratch project loading with the existing ProjectLoader locale-selection behavior used elsewhere in the app (notably for Experience CS preview scenarios).

Changes:

  • Update Scratch load_project to use ProjectLoader + a scratch-type guard instead of a direct find_by!.
  • Add a request spec ensuring the locale header is preferred when multiple translated projects share the same identifier.
  • Extend Bullet safelist configuration (dev/test) to reduce Bullet noise around Project#scratch_component.
File summaries
File Description
spec/features/scratch/showing_a_scratch_project_spec.rb Adds coverage for choosing the project matching X-Project-Locale when multiple locales exist for one identifier.
config/initializers/bullet.rb Adds a dev/test Bullet safelist for Project#scratch_component and refactors the conditional block.
app/controllers/api/scratch/projects_controller.rb Switches Scratch project lookup to use ProjectLoader and a scratch_project? check, enabling locale-aware selection.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread app/controllers/api/scratch/projects_controller.rb
@raspberrypiherokubot
raspberrypiherokubot temporarily deployed to editor-api-p-load-scrat-dhzdlh September 10, 2026 15:13 Inactive
@zetter-rpf
zetter-rpf merged commit 303d210 into main Sep 10, 2026
9 checks passed
@zetter-rpf
zetter-rpf deleted the load-scratch-projects-in-correct-locale branch September 10, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants