feat(api): filter /rest/v1/standards by saved resource selection (#586) - #1001
Conversation
Summary by CodeRabbit
WalkthroughChangesStandards filtering
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
application/web/openapi_registry.py (1)
518-521: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winPrevent duplicate query parameters.
path_namesonly contains path parameters. A custom query parameter can duplicate a parameter generated fromquery_schema. This can generate an invalid OpenAPI operation.Track existing
(name, in)pairs after adding query-schema parameters. Skip duplicate custom parameters. Add a generation test with the same query parameter from both sources.Proposed fix
if path_spec.parameters: - parameters.extend( - [param for param in path_spec.parameters if param["name"] not in path_names] - ) + seen = {(param["name"], param["in"]) for param in parameters} + for param in path_spec.parameters: + key = (param["name"], param["in"]) + if param["name"] not in path_names and key not in seen: + parameters.append(param) + seen.add(key)🤖 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 `@application/web/openapi_registry.py` around lines 518 - 521, Update the parameter assembly logic around path_spec.parameters to track existing (name, in) pairs after adding query-schema parameters, and filter custom parameters against that set instead of path_names alone. Preserve distinct parameters with different locations, and add a generation test covering the same query parameter supplied by both query_schema and custom parameters.
🤖 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.
Nitpick comments:
In `@application/web/openapi_registry.py`:
- Around line 518-521: Update the parameter assembly logic around
path_spec.parameters to track existing (name, in) pairs after adding
query-schema parameters, and filter custom parameters against that set instead
of path_names alone. Preserve distinct parameters with different locations, and
add a generation test covering the same query parameter supplied by both
query_schema and custom parameters.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9bfee594-fc9d-438b-acc4-94760673af46
📒 Files selected for processing (4)
application/tests/resource_filter_test.pyapplication/web/openapi_registry.pyapplication/web/web_main.pydocs/api/openapi.yaml
What & why
Part of #586. This makes a user's saved resource selection (from PR #980 + #981)
actually take effect: a logged-in user with a non-empty selection now sees only
their selected standards when calling
GET /rest/v1/standards. Builds directlyon the merged User persistence (#980) and resource-selection API (#981).
Behaviour
/rest/v1/standardsreturns only the selected standards.
OPENCREis always kept (it's the coregraph, already special-cased).
unfiltered list (same no-op discipline as feat(api): per-user resource selection endpoint — Part of #586 #981 — never narrow results silently
for users who didn't opt in).
?all=truebypasses the filter for a single request, so a user can seeeverything without clearing their saved selection. Documented in OpenAPI.
Design
apply_user_resource_filter(database, names)— noper-endpoint duplication.
_resolve_current_user(feat(api): per-user resource selection endpoint — Part of #586 #981) andget_user_resource_selection(feat(db): persist users + resource selection — Part of #586 #980);gate matches feat(api): per-user resource selection endpoint — Part of #586 #981 (
is_login_enabled()+is_myopencre_enabled()).Scope (deliberately tight)
/rest/v1/standardsonly./rest/v1/ga_standards(filtering it server-sidewithout the paired frontend
?all=truewiring would silently narrowgap-analysis inputs), and graph-node/link pruning for
root_cres/text_search/find_cre(a distinct semantic decision; the clientapplyFiltersalready handles link-level filtering). Single-resource lookups(
/standard/<name>,map_analysis) are intentionally never filtered — the userasked for that resource explicitly.
Testing
application/tests/resource_filter_test.py, verified on real Postgres:selection → {selected}+OPENCRE; empty/anonymous/login-off/myopencre-off → full;
OPENCRE always kept;
?all=truebypass.tests fail, so they genuinely detect an unapplied filter.
?allparam added + spec regenerated; guardrail green(documented-views / freshness / validity / route-coverage).