docs: Modify security documentation to indicate Cerberus is enabled by default test: Adjust frontend feature flag tests to align with new Cerberus flag feat: Integrate feature flags into Layout component for conditional rendering test: Enhance Layout component tests for feature flag visibility feat: Implement Optional Features section in System Settings page test: Add tests for Optional Features toggles in System Settings fix: Remove unused Cerberus state from System Settings component
3.5 KiB
3.5 KiB
Plan: Refactor Feature Flags to Optional Features
Overview
Refactor the existing "Feature Flags" system into a user-friendly "Optional Features" section in System Settings. This involves renaming, consolidating toggles (Cerberus, Uptime), and enforcing behavior (hiding sidebar items, stopping background jobs) when features are disabled.
User Requirements
- Rename: 'Feature Flags' -> 'Optional Features'.
- Cerberus: Move global toggle to 'Optional Features'.
- Uptime: Add toggle to 'Optional Features'.
- Cleanup: Remove unused flags (
feature.global.enabled,feature.notifications.enabled,feature.docker.enabled). - Behavior:
- Default: Cerberus and Uptime ON.
- OFF State: Hide from Sidebar, stop background jobs, block notifications.
- Persistence: Do NOT delete data when disabled.
Implementation Details
1. Backend Changes
backend/internal/api/handlers/feature_flags_handler.go
- Update
defaultFlagslist:- Keep:
feature.cerberus.enabled,feature.uptime.enabled - Remove:
feature.global.enabled,feature.notifications.enabled,feature.docker.enabled
- Keep:
- Ensure defaults are
trueif not set in DB or Env.
backend/internal/cerberus/cerberus.go
- Update
IsEnabled()to checkfeature.cerberus.enabledinstead ofsecurity.cerberus.enabled. - Maintain backward compatibility or migrate existing setting if necessary (or just switch to the new key).
backend/internal/api/routes/routes.go
- Uptime Background Job:
- In the
go func()that runs the ticker:- Check
feature.uptime.enabledbefore runninguptimeService.CheckAll(). - If disabled, skip the check.
- Check
- In the
- Cerberus Middleware:
- The middleware already calls
IsEnabled(), so updatingcerberus.gois sufficient.
- The middleware already calls
2. Frontend Changes
frontend/src/pages/SystemSettings.tsx
- Rename Card: Change "Feature Flags" to "Optional Features".
- Consolidate Toggles:
- Remove "Enable Cerberus Security" from "General Configuration".
- Render specific toggles for "Cerberus Security" and "Uptime Monitoring" in the "Optional Features" card.
- Use
feature.cerberus.enabledandfeature.uptime.enabledkeys. - Add user-friendly descriptions for each.
- Remove Generic List: Instead of iterating over all keys, explicitly render the supported optional features to control order and presentation.
frontend/src/components/Layout.tsx
- Fetch Flags: Use
getFeatureFlags(or a new hook) to get current state. - Conditional Rendering:
- Hide "Uptime" nav item if
feature.uptime.enabledis false. - Hide "Security" nav group if
feature.cerberus.enabledis false.
- Hide "Uptime" nav item if
3. Migration / Data Integrity
- Existing
security.cerberus.enabledsetting in DB should be migrated tofeature.cerberus.enabledor the code should handle the transition. - Action: We will switch to
feature.cerberus.enabled. The user can re-enable it if it defaults to off, but we'll try to default it to ON in the handler.
Step-by-Step Execution
- Backend: Update
feature_flags_handler.goto clean up flags and set defaults. - Backend: Update
cerberus.goto use new flag key. - Backend: Update
routes.goto gate Uptime background job. - Frontend: Update
SystemSettings.tsxUI. - Frontend: Update
Layout.tsxsidebar logic. - Verify: Test toggling features and checking sidebar/background behavior.