Skip to content

feat: Add admin-managed global connector toggle#1749

Closed
edwinjosechittilappilly wants to merge 3 commits into
feat-update-rbacfrom
feat-add-connector-toggle
Closed

feat: Add admin-managed global connector toggle#1749
edwinjosechittilappilly wants to merge 3 commits into
feat-update-rbacfrom
feat-add-connector-toggle

Conversation

@edwinjosechittilappilly

Copy link
Copy Markdown
Collaborator

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.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 505aaa52-ef4f-406f-a5f2-715beee03aca

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-add-connector-toggle

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.

@github-actions github-actions Bot added frontend 🟨 Issues related to the UI/UX backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) tests enhancement 🔵 New feature or request and removed enhancement 🔵 New feature or request labels Jun 3, 2026
edwinjosechittilappilly and others added 2 commits June 3, 2026 18:13
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.
@github-actions github-actions Bot added enhancement 🔵 New feature or request and removed enhancement 🔵 New feature or request labels Jun 3, 2026
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.
@edwinjosechittilappilly
edwinjosechittilappilly marked this pull request as ready for review June 3, 2026 23:22
Copilot AI review requested due to automatic review settings June 3, 2026 23:22
@github-actions github-actions Bot added enhancement 🔵 New feature or request and removed enhancement 🔵 New feature or request labels Jun 3, 2026

Copilot AI 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.

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:global permission (seed + migration) and wire an admin-only PUT /connectors/{connector_type}/enabled endpoint to persist enablement in workspace config.
  • Backend: introduce connector enablement helpers, add enabled to list_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.

Comment thread src/api/connectors.py
Comment on lines +33 to +37
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()}
Comment thread src/api/connectors.py
Comment on lines 565 to +571
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)

Comment on lines 16 to 20
# 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")

Comment on lines 33 to 37
selectedFiles?: GoogleDriveFile[] | OneDriveFile[];
available?: boolean;
/** Admin-managed workspace toggle. Absent is treated as enabled. */
enabled?: boolean;
}
@github-actions
github-actions Bot deleted the branch feat-update-rbac June 4, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) enhancement 🔵 New feature or request frontend 🟨 Issues related to the UI/UX tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants