Commit 79f7bb9
feat(handler): unify ?server= / ?box_id= via resolveActiveBox helper (#134)
* feat(handler): unify ?server= / ?box_id= via resolveActiveBox helper (#112)
Three resolution conventions co-existed pre-#112 Phase 4:
1. `?server=<id>` — gear-settings deep links and the OS-Updates page.
2. `?box_id=<id>` — InjectIntegrationStatus middleware (the
header-pill URL persistence).
3. `gearbox_active_box` cookie — the sticky pill selection.
Handlers that wanted to honor the pill had to write the same
"check ?server=, then cookie, then default" cascade. Handlers that
followed the middleware convention got `?box_id=` for free but lost
gear-settings links. The resolveBoxIDFromRequest helper only knew
`?server=`.
Changes:
- resolveBoxIDFromRequest now accepts BOTH `?server=` and `?box_id=`
as synonyms (precedence: server > box_id > cookie > default).
Handlers can use whichever name fits the surrounding code without
losing pill-aware routing.
- New resolveActiveBox(r) returns the full *models.BoxConfig along
with a presence boolean, so handlers that need an agent URL or
APIKey don't have to chase a separate getServerConfig call. Folds
the "single helper for active box" invariant from the issue
proposal into one call site.
Four tests cover the new contract: ?server= path, ?box_id= path,
precedence when both supplied, and the full-BoxConfig return.
Phase 4 of #112.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(handler): address Copilot review on resolveActiveBox docstring (#112)
Copilot flagged that the docstring for resolveActiveBox claimed
(nil, false) for the "all-boxes / no-box context", but
resolveBoxIDFromRequest falls back to getDefaultServerID() and
getServerConfig accepts entries from the static h.servers list
regardless of DB-enabled state — so any time at least one server
is configured, this helper resolves to one.
Update the docstring to match actual behavior: (nil, false) only
fires when no servers are configured at all OR when an explicit
?server= / ?box_id= references a missing box. Handlers that need
to distinguish "no active box" from "first enabled box" should
consult the auth-context active-box set by InjectIntegrationStatus,
not call this helper.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 99e73f6 commit 79f7bb9
2 files changed
Lines changed: 123 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
291 | 295 | | |
292 | 296 | | |
293 | 297 | | |
294 | 298 | | |
295 | 299 | | |
296 | 300 | | |
297 | 301 | | |
298 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
299 | 306 | | |
300 | 307 | | |
301 | 308 | | |
302 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
303 | 313 | | |
304 | 314 | | |
305 | 315 | | |
| |||
312 | 322 | | |
313 | 323 | | |
314 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
315 | 357 | | |
316 | 358 | | |
317 | 359 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
0 commit comments