Skip to content

Commit 7a0da5c

Browse files
skypank-codernorthdpole
authored andcommitted
feat(api): add GET /api/capabilities to expose myopencre feature flag
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.
1 parent 55641bd commit 7a0da5c

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

application/feature_flags.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ def is_cre_import_allowed() -> bool:
1616

1717
def is_health_endpoint_enabled() -> bool:
1818
return os.getenv("CRE_ENABLE_HEALTH", "").strip().lower() in TRUE_VALUES
19+
20+
21+
def is_myopencre_enabled() -> bool:
22+
return os.getenv("CRE_ENABLE_MYOPENCRE", "").strip().lower() in TRUE_VALUES

application/tests/web_main_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,3 +1525,31 @@ def test_health_db_unreachable_returns_503(self) -> None:
15251525
self.assertFalse(body["db_reachable"])
15261526
finally:
15271527
os.environ.pop("CRE_ENABLE_HEALTH", None)
1528+
1529+
def test_capabilities_endpoint_returns_myopencre_key(self) -> None:
1530+
os.environ.pop("CRE_ENABLE_MYOPENCRE", None)
1531+
with self.app.test_client() as client:
1532+
response = client.get("/api/capabilities")
1533+
self.assertEqual(200, response.status_code)
1534+
body = json.loads(response.data.decode())
1535+
self.assertIn("myopencre", body)
1536+
self.assertIsInstance(body["myopencre"], bool)
1537+
1538+
def test_capabilities_myopencre_false_by_default(self) -> None:
1539+
os.environ.pop("CRE_ENABLE_MYOPENCRE", None)
1540+
with self.app.test_client() as client:
1541+
response = client.get("/api/capabilities")
1542+
self.assertEqual(200, response.status_code)
1543+
body = json.loads(response.data.decode())
1544+
self.assertFalse(body["myopencre"])
1545+
1546+
def test_capabilities_myopencre_true_when_flag_set(self) -> None:
1547+
os.environ["CRE_ENABLE_MYOPENCRE"] = "1"
1548+
try:
1549+
with self.app.test_client() as client:
1550+
response = client.get("/api/capabilities")
1551+
self.assertEqual(200, response.status_code)
1552+
body = json.loads(response.data.decode())
1553+
self.assertTrue(body["myopencre"])
1554+
finally:
1555+
os.environ.pop("CRE_ENABLE_MYOPENCRE", None)

application/web/web_main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
from application.cmd import cre_main
2323
from application.defs import cre_defs as defs
2424
from application.defs import cre_exceptions
25-
from application.feature_flags import is_cre_import_allowed, is_health_endpoint_enabled
25+
from application.feature_flags import (
26+
is_cre_import_allowed,
27+
is_health_endpoint_enabled,
28+
is_myopencre_enabled,
29+
)
2630

2731
from application.utils import spreadsheet as sheet_utils
2832
from application.utils import mdutils, redirectors, gap_analysis
@@ -1196,6 +1200,11 @@ def get_config() -> Any:
11961200
return jsonify({"CRE_ALLOW_IMPORT": is_cre_import_allowed()})
11971201

11981202

1203+
@app.route("/api/capabilities", methods=["GET"])
1204+
def get_capabilities() -> Any:
1205+
return jsonify({"myopencre": is_myopencre_enabled()})
1206+
1207+
11991208
@app.route("/admin/imports/rerun", methods=["POST"])
12001209
@login_required
12011210
@admin_imports_enabled_required

0 commit comments

Comments
 (0)