Skip to content

feat(api): add GET /api/capabilities to expose myopencre feature flag#949

Open
skypank-coder wants to merge 2 commits into
OWASP:mainfrom
skypank-coder:feat/api-capabilities-myopencre
Open

feat(api): add GET /api/capabilities to expose myopencre feature flag#949
skypank-coder wants to merge 2 commits into
OWASP:mainfrom
skypank-coder:feat/api-capabilities-myopencre

Conversation

@skypank-coder

Copy link
Copy Markdown
Contributor

Adds the missing GET /api/capabilities endpoint that the frontend useCapabilities hook depends on. Without it the fetch 404s and the whole MyOpenCRE feature stays hidden in every environment.

Changes

  • New route GET /api/capabilities in application/web/web_main.py returning { "myopencre": <bool> }, mirroring the existing /rest/v1/config thin-handler style.
  • New flag is_myopencre_enabled() in application/feature_flags.py, reading CRE_ENABLE_MYOPENCRE via the existing TRUE_VALUES pattern. Defaults to off, so no existing deployment behavior changes.
  • Tests in application/tests/web_main_test.py: key present + boolean, false-by-default, true-when-flag-set.

Why a dedicated flag

MyOpenCRE download/preview is read-only and should be controllable independently of CRE_ALLOW_IMPORT. The new flag decouples its visibility from the import feature.

Verification

  • Frontend already consumes this contract (useCapabilities.tsHeader.tsx, routes.tsx); no FE change needed.
  • Live-tested: flag off → 200 {"myopencre": false} (clean 200, no more 404); flag on → 200 {"myopencre": true}.
  • New tests pass; black 24.4.2 and mypy clean on changed files.

Closes #948

cc @PRAteek-singHWY @Pa04rth @northdpole

MyOpenCRE was fully built but invisible because the frontend
useCapabilities hook calls /api/capabilities, which didn't exist —
the 404 resolved myopencre:false everywhere. Adds the route returning
{myopencre: <bool>} driven by the deployment flag, lighting up the
nav link and /myopencre route.
@coderabbitai

coderabbitai Bot commented Jun 25, 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: c6b826ce-ca66-4dc0-b9da-b6cd4ac31f7b

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb30dd and 8d3bd5e.

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

Summary by CodeRabbit

  • New Features

    • Added a new GET /api/capabilities endpoint that returns capability information, including whether myopencre is enabled.
    • Added an environment-based flag to control the myopencre capability.
  • Bug Fixes

    • Ensures the myopencre field is always present and is a boolean, defaulting to false when unset.
  • Tests

    • Added tests validating /api/capabilities behavior when the flag is unset vs. set (e.g., "1").

Walkthrough

Adds is_myopencre_enabled(), exposes it at GET /api/capabilities as {"myopencre": <bool>}, and adds tests for the default and enabled responses.

Changes

MyOpenCRE capabilities endpoint

Layer / File(s) Summary
Feature-flag helper
application/feature_flags.py
is_myopencre_enabled() reads CRE_ENABLE_MYOPENCRE, normalizes it, and checks it against TRUE_VALUES.
Capabilities route
application/web/web_main.py
application/web/web_main.py imports the helper and adds GET /api/capabilities, which returns {"myopencre": is_myopencre_enabled()}.
Endpoint tests
application/tests/web_main_test.py
TestMain adds coverage for the /api/capabilities response key, the default False case, and the CRE_ENABLE_MYOPENCRE="1" case.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% 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 clearly summarizes the main change: adding GET /api/capabilities for the myopencre feature flag.
Description check ✅ Passed The description is directly related to the PR and accurately describes the backend route, flag, and tests.
Linked Issues check ✅ Passed The changes satisfy #948 by adding the endpoint, feature-flag helper, and tests that return a boolean capability payload.
Out of Scope Changes check ✅ Passed The PR stays within scope; it only adds the route, flag helper, and tests, without touching unrelated frontend or parser logic.

✏️ 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.

@coderabbitai coderabbitai Bot 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.

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 `@application/tests/web_main_test.py`:
- Around line 1529-1555: The capabilities tests mutate the global
CRE_ENABLE_MYOPENCRE environment variable without restoring any preexisting
value, which can make them order-dependent. Update the three test methods in
web_main_test.py to use a scoped environment override (for example via
patch.dict) or save and restore the original value around each test, keeping the
existing assertions in test_capabilities_endpoint_returns_myopencre_key,
test_capabilities_myopencre_false_by_default, and
test_capabilities_myopencre_true_when_flag_set unchanged.
🪄 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: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: c1852a13-57d2-4cd5-84dd-933434ba1d81

📥 Commits

Reviewing files that changed from the base of the PR and between 4485936 and 3bb30dd.

📒 Files selected for processing (3)
  • application/feature_flags.py
  • application/tests/web_main_test.py
  • application/web/web_main.py

Comment thread application/tests/web_main_test.py Outdated
Use patch.dict for CRE_ENABLE_MYOPENCRE in tests so any preexisting value is restored and tests aren't order-dependent. Add docstrings to is_myopencre_enabled, get_capabilities, and the capabilities tests to satisfy docstring coverage.
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.

MyOpenCRE feature invisible in all environments — missing GET /api/capabilities endpoint

1 participant