Skip to content

fix(smartlink): redirect to CRE page directly when only one CRE is linked#906

Open
shreeshtripurwarcomp23-coder wants to merge 1 commit into
OWASP:mainfrom
shreeshtripurwarcomp23-coder:fix/smartlink-single-cre-redirect-486
Open

fix(smartlink): redirect to CRE page directly when only one CRE is linked#906
shreeshtripurwarcomp23-coder wants to merge 1 commit into
OWASP:mainfrom
shreeshtripurwarcomp23-coder:fix/smartlink-single-cre-redirect-486

Conversation

@shreeshtripurwarcomp23-coder

Copy link
Copy Markdown
Contributor

Summary

Fixes #486

What changed

When smartlink resolves to a standard node (e.g. CWE/611) that has
exactly one connected CRE, the user is now redirected directly to
/cre/{id} instead of stopping at the intermediate /node/... page.

The CRE page already contains all the information the node page shows,
so the extra click was unnecessary friction.

If zero or multiple CREs are linked, the existing behavior is preserved.

How it works

In web_main.py → smartlink(), after finding the node, we filter
nodes[0].links for CRE-typed documents. If exactly one is found,
we extract its id and redirect to /cre/{id}.

Tests

  • Updated two existing test_smartlink assertions to expect the new
    /cre/{id} redirect for single-CRE nodes
  • Added a new multi-CRE case: a second CRE is linked to the same node,
    confirming the fallback to the node page still works
  • All 28 web_main tests pass

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 2c63cd40-9155-4ef5-ae0c-77e363ba3f22

📥 Commits

Reviewing files that changed from the base of the PR and between 533b157 and 15207f3.

📒 Files selected for processing (2)
  • application/tests/web_main_test.py
  • application/web/web_main.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • application/tests/web_main_test.py
  • application/web/web_main.py

Summary by CodeRabbit

  • Bug Fixes

    • Improved smartlink redirects: when opening a standard node that has exactly one linked CRE, the app now routes users directly to the CRE page (/cre/<id>) instead of showing an intermediate node view. This covers CWE and ASVS smartlinks. If multiple CREs are linked, the app retains the previous behavior by falling back to the node page.
  • Tests

    • Updated smartlink redirect assertions and expanded coverage for multi-CRE fallback behavior.

Walkthrough

Adds a fast-path in the smartlink route: after a node is found, it extracts all linked CRE documents that have an id. If exactly one such CRE exists, it redirects directly to /cre/<cre_id>; otherwise, existing redirect logic is unchanged. Tests are updated to assert this direct redirect behavior for single-CRE cases and a multi-CRE fixture is added to validate the node-page fallback. The PR also includes mechanical code cleanup: posthog event names are converted to literal strings, unused exception variables are removed, abort messages are reformatted, and an unused database assignment is deleted.

Changes

smartlink Single-CRE Direct Redirect and Code Maintenance

Layer / File(s) Summary
smartlink direct redirect implementation and tests
application/web/web_main.py, application/tests/web_main_test.py
smartlink now extracts linked CREs from nodes[0].links and redirects to /cre/<cre_id> when exactly one CRE with an id is linked. Test expectations for the CWE (sectionID) and ASVS (section) single-CRE cases are updated to assert /cre/222-222 and /cre/333-333 respectively, and an additional CRE is linked to the ASVS node to cover the multi-CRE node-page fallback path.
posthog, exception handling, and formatting cleanup
application/web/web_main.py
Multiple posthog.capture calls are updated to pass literal event name strings instead of f-string expressions, unused exception variables are removed in except handlers, abort(..., description=...) messages are reformatted across multi-line expressions, an unused database = ...with_graph() assignment is removed, and log message f-strings are simplified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: smartlink now redirects directly to CRE page when only one CRE is linked.
Description check ✅ Passed The description clearly explains the change, references the fixed issue, outlines how it works, and confirms tests pass.
Linked Issues check ✅ Passed The PR fully addresses issue #486 by implementing direct CRE redirection for single-CRE smartlink scenarios with proper fallback handling.
Out of Scope Changes check ✅ Passed All changes directly support the smartlink optimization objective; minor refactoring (posthog calls, exception handling) aligns with code quality improvements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@shreeshtripurwarcomp23-coder shreeshtripurwarcomp23-coder force-pushed the fix/smartlink-single-cre-redirect-486 branch from 382e45c to fe2e5ce Compare June 15, 2026 05:49
@shreeshtripurwarcomp23-coder shreeshtripurwarcomp23-coder force-pushed the fix/smartlink-single-cre-redirect-486 branch from 533b157 to 15207f3 Compare June 15, 2026 06:24
@shreeshtripurwarcomp23-coder

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Pa04rth Pa04rth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Image No need of unnecessary concatenation , just stick to the issue and its solution Also remove any other unwanted changes you have made other than that is required

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.

Make smartlink go to CRE directly

2 participants