feat: Add admin-managed global connector toggle#1749
feat: Add admin-managed global connector toggle#1749edwinjosechittilappilly wants to merge 3 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
98626a7 to
7b29adc
Compare
Introduce an admin-only workspace toggle for connectors.
- Add migration (0007_seed_connectors_manage_global) to create the connectors:manage:global permission and grant it to the admin role.
- Persist per-connector enabled state in workspace config under the "connectors" section (default = enabled) and add the section to WorkspaceConfigRepo.
- Backend: add helpers (is_connector_enabled, get_connector_enabled_map, user_can_manage_connectors, assert_connector_enabled), list_connectors now returns an "enabled" flag and hides disabled connectors from non-admins, add set_connector_enabled endpoint (PUT /connectors/{connector_type}/enabled), and enforce global-disable checks across relevant connector endpoints and sync flows.
- Frontend: include an enabled flag in connector query, add a toggle Switch in connector cards, new useToggleConnectorMutation for optimistic UI updates and API call to flip workspace enablement.
- Tests: add unit tests for connector enablement behavior and update existing tests to include session/rbac mocks.
This implements a workspace-wide "kill switch" for connectors with admin bypass and UI controls to manage and display the state.
96745de to
743932d
Compare
Remove unused typing imports (Union and Optional) and clean up import ordering/whitespace. In src/api/auth.py move logging/telemetry/version imports and logger initialization to group related imports, and remove an unused Optional import in workspace_config_repo.py. Small refactor to reduce lint warnings and improve import organization.
There was a problem hiding this comment.
Pull request overview
This PR adds a workspace-wide “kill switch” for connectors that can be managed by admins via a new RBAC permission, persists per-connector enabled state in workspace config, enforces the state in key connector flows, and exposes the toggle in the Settings UI.
Changes:
- Add
connectors:manage:globalpermission (seed + migration) and wire an admin-onlyPUT /connectors/{connector_type}/enabledendpoint to persist enablement in workspace config. - Backend: introduce connector enablement helpers, add
enabledtolist_connectors, and gate connector operations/sync flows based on global enablement with an admin bypass. - Frontend: fetch and display
enabled, add a per-connector Switch control with an optimistic toggle mutation; update unit tests to include DB/RBAC mocks.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tests/unit/connectors/test_connector_file_type_validation.py |
Updates unit test wiring for new session/RBAC dependencies. |
tests/unit/connectors/test_connector_enablement.py |
Adds focused unit coverage for connector enablement helpers and behaviors. |
tests/unit/api/test_reconcile_orphans_for_connector_type.py |
Updates sync-related tests to pass DB session + RBAC mocks. |
src/db/seed.py |
Adds the new permission to the seed catalog. |
src/db/repositories/workspace_config_repo.py |
Adds "connectors" as a recognized workspace config section and updates typing. |
src/app/routes/internal.py |
Registers the new internal enable/disable endpoint route. |
src/api/connectors.py |
Implements enablement map helpers, enforcement checks, enabled flag in list response, and enablement toggle endpoint. |
src/api/auth.py |
Prevents non-admin OAuth init for globally-disabled connectors (except app_auth). |
frontend/app/settings/_components/connector-cards.tsx |
Wires toggle handler/mutation state into connector cards. |
frontend/app/settings/_components/connector-card.tsx |
Adds admin-only enable/disable Switch and disabled messaging. |
frontend/app/api/queries/useGetConnectorsQuery.ts |
Extends connector shape to include enabled and propagates it into returned connectors. |
frontend/app/api/mutations/useToggleConnectorMutation.ts |
Adds optimistic mutation for toggling connector enablement. |
alembic/versions/0007_seed_connectors_manage_global.py |
Adds an idempotent data migration to seed/grant the new permission. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async def get_connector_enabled_map(session: AsyncSession) -> dict[str, bool]: | ||
| """Return the admin-set ``{connector_type: enabled}`` map from workspace config.""" | ||
| repo = WorkspaceConfigRepo(session) | ||
| value = await repo.get_section(CONNECTORS_CONFIG_SECTION) or {} | ||
| return {str(k): bool(v) for k, v in value.items()} |
| try: | ||
| connector_types = connector_service.connection_manager.get_available_connector_types( | ||
| user_id=user.user_id | ||
| ) | ||
| return JSONResponse({"connectors": connector_types}) | ||
| enabled_map = await get_connector_enabled_map(session) | ||
| is_admin = await user_can_manage_connectors(user, rbac) | ||
|
|
| # Section names recognized by the migration / service. | ||
| SECTIONS = ("providers", "knowledge", "agent", "onboarding", "meta") | ||
| # 'connectors' holds the admin-managed per-connector enable/disable map and is | ||
| # read/written directly by the connectors API (not mapped into OpenRAGConfig). | ||
| SECTIONS = ("providers", "knowledge", "agent", "onboarding", "meta", "connectors") | ||
|
|
| selectedFiles?: GoogleDriveFile[] | OneDriveFile[]; | ||
| available?: boolean; | ||
| /** Admin-managed workspace toggle. Absent is treated as enabled. */ | ||
| enabled?: boolean; | ||
| } |
Introduce an admin-only workspace toggle for connectors.
This implements a workspace-wide "kill switch" for connectors with admin bypass and UI controls to manage and display the state.