fix: Enhance validation in controllers and filters to handle missing …#1201
fix: Enhance validation in controllers and filters to handle missing …#1201gibahjoe wants to merge 2 commits into
Conversation
…dataset gracefully
|
Warning Review limit reached
More reviews will be available in 54 minutes and 31 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughControllers and filters now consistently validate that ChangesDataset presence validation and session resilience
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/controllers/lpaDetailsController.js`:
- Line 8: The code in lpaDetailsController sets requestId from
req.session?.checkRequestId but falls back only to
req.sessionModel.get('request_id'), while other controllers store/read the
camelCase key; update the fallback logic in lpaDetailsController so requestId is
resolved by checking req.session?.checkRequestId first, then
req.sessionModel.get('requestId') and finally req.sessionModel.get('request_id')
to cover both stored formats; locate the assignment to requestId in
lpaDetailsController and adjust the fallback order accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8fcdaccc-3937-41f4-8f4c-8b80ebc8a8da
📒 Files selected for processing (9)
src/controllers/CheckAnswersController.jssrc/controllers/datasetDetailsController.jssrc/controllers/lpaDetailsController.jssrc/controllers/pageController.jssrc/filters/makeDatasetSlugToReadableNameFilter.jstest/unit/PageController.test.jstest/unit/checkAnswersController.test.jstest/unit/lpaDetailsController.test.jstest/unit/makeDatasetSlugToReadableNameFilter.test.js
| class LpaDetailsController extends PageController { | ||
| async locals (req, res, next) { | ||
| const requestId = req.session?.checkRequestId | ||
| const requestId = req.session?.checkRequestId ?? req.sessionModel.get('request_id') |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find all session-model reads/writes that look like a request id key
rg -nP "sessionModel\.(get|set)\(\s*['\"](request_id|requestId)['\"]" --type=js
echo "----- checkRequestId usages -----"
rg -nP "checkRequestId" --type=js -C2Repository: digital-land/submit
Length of output: 2757
Fix session key fallback in lpaDetailsController (request_id vs requestId)
src/controllers/lpaDetailsController.js reads req.sessionModel.get('request_id') when req.session?.checkRequestId is unset, but it stores requestId in the session model and other controllers use requestId (e.g. datasetDetailsController.js, CheckAnswersController.js, endpointSubmissionFormDeepLinkController.js). If only requestId is present and checkRequestId is not set, requestId will become undefined and the page will not get the expected value (the existing unit test currently only covers the request_id case).
🔧 Proposed fix (read both keys)
- const requestId = req.session?.checkRequestId ?? req.sessionModel.get('request_id')
+ const requestId = req.session?.checkRequestId ?? req.sessionModel.get('requestId') ?? req.sessionModel.get('request_id')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/controllers/lpaDetailsController.js` at line 8, The code in
lpaDetailsController sets requestId from req.session?.checkRequestId but falls
back only to req.sessionModel.get('request_id'), while other controllers
store/read the camelCase key; update the fallback logic in lpaDetailsController
so requestId is resolved by checking req.session?.checkRequestId first, then
req.sessionModel.get('requestId') and finally req.sessionModel.get('request_id')
to cover both stored formats; locate the assignment to requestId in
lpaDetailsController and adjust the fallback order accordingly.
Description
Fixes a submit journey crash where
datasetSlugToReadableNamecould be called with a missing dataset, causingCannot read properties of undefined (reading 'charAt').The submit journey now redirects users back to
/check/urlwhen required session data is missing, and the shared page controller avoids formatting a dataset name unless a dataset exists. The dataset name filter also has a defensive fallback for missing slugs.What type of PR is this? (check all applicable)
Related Tickets & Documents
QA Instructions, Screenshots, Recordings
Run the focused unit tests:
Expected result: all tests pass.
Manual QA:
/submit/lpa-details,/submit/dataset-details, and/submit/check-answersstill render correctly when session data is valid./submit/dataset-detailsor/submit/check-answerswithout a valid submit session./check/urlinstead of seeing a server error.Before
The check answers page could throw:
when
values['dataset']was missing.After
Missing required submit journey data redirects the user to
/check/url, and the dataset name formatter is not called with a missing dataset.Added/updated tests?
QA sign off
[optional] Are there any post-deployment tasks we need to perform?
None.
[optional] Are there any dependencies on other PRs or Work?
None.
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests