Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix: Enhance connector availability checks to be user-scoped by adding user_id parameter

Rico Furtadof05568c630d2
diff --git a/src/api/connectors.py b/src/api/connectors.py
index 6d2431f9b..ea2e50eaa 100644
--- a/src/api/connectors.py
+++ b/src/api/connectors.py
@@ -101,8 +101,8 @@ async def list_connectors(
):
"""List available connector types with metadata"""
try:
- connector_types = (
- connector_service.connection_manager.get_available_connector_types()
+ connector_types = connector_service.connection_manager.get_available_connector_types(
+ user_id=user.user_id
)
return JSONResponse({"connectors": connector_types})
except Exception as e:
diff --git a/src/connectors/connection_manager.py b/src/connectors/connection_manager.py
index c172a93ca..0600b11a3 100644
--- a/src/connectors/connection_manager.py
+++ b/src/connectors/connection_manager.py
@@ -332,43 +332,71 @@ class ConnectionManager:
logger.warning(f"Authentication failed for {connection_id}")
return None
- def get_available_connector_types(self) -> Dict[str, Dict[str, Any]]:
- """Get available connector types with their metadata"""
+ def get_available_connector_types(
+ self, user_id: Optional[str] = None
+ ) -> Dict[str, Dict[str, Any]]:
+ """Get available connector types with their metadata.
+
+ Availability is user-scoped when ``user_id`` is provided:
+ a connector is considered available if either:
+ 1) its required env credentials are present, or
+ 2) the user has an active saved connection with usable credentials.
+ """
return {
"google_drive": {
"name": GoogleDriveConnector.CONNECTOR_NAME,
"description": GoogleDriveConnector.CONNECTOR_DESCRIPTION,
"icon": GoogleDriveConnector.CONNECTOR_ICON,
- "available": self._is_connector_available("google_drive"),
+ "available": self._is_connector_available("google_drive", user_id),
},
"sharepoint": {
"name": SharePointConnector.CONNECTOR_NAME,
"description": SharePointConnector.CONNECTOR_DESCRIPTION,
"icon": SharePointConnector.CONNECTOR_ICON,
- "available": self._is_connector_available("sharepoint"),
+ "available": self._is_connector_available("sharepoint", user_id),
},
"onedrive": {
"name": OneDriveConnector.CONNECTOR_NAME,
"description": OneDriveConnector.CONNECTOR_DESCRIPTION,
"icon": OneDriveConnector.CONNECTOR_ICON,
- "available": self._is_connector_available("onedrive"),
+ "available": self._is_connector_available("onedrive", user_id),
},
"ibm_cos": {
"name": IBMCOSConnector.CONNECTOR_NAME,
"description": IBMCOSConnector.CONNECTOR_DESCRIPTION,
"icon": IBMCOSConnector.CONNECTOR_ICON,
- "available": self._is_connector_available("ibm_cos"),
+ "available": self._is_connector_available("ibm_cos", user_id),
},
"aws_s3": {
"name": S3Connector.CONNECTOR_NAME,
"description": S3Connector.CONNECTOR_DESCRIPTION,
"icon": S3Connector.CONNECTOR_ICON,
- "available": self._is_connector_available("aws_s3"),
+ "available": self._is_connector_available("aws_s3", user_id),
},
}
- def _is_connector_available(self, connector_type: str) -> bool:
- """Check if a connector type is available (has required env vars)"""
+ def _has_saved_credentials_for_user(
+ self, connector_type: str, user_id: Optional[str]
+ ) -> bool:
+ """Check if user has an active saved connection with usable credentials."""
+ for connection in self.connections.values():
+ if connection.connector_type != connector_type or not connection.is_active:
+ continue
+ if user_id is not None and connection.user_id != user_id:
+ continue
+ try:
+ connector = self._create_connector(connection)
+ connector.get_client_id()
+ connector.get_client_secret()
+ return True
+ except (ValueError, NotImplementedError, RuntimeError):
+ continue
+ return False
+
+ def _is_connector_available(
+ self, connector_type: str, user_id: Optional[str] = None
+ ) -> bool:
+ """Check whether connector is available for use by the given user."""
try:
temp_config = ConnectionConfig(
connection_id="temp",
@@ -381,8 +409,9 @@ class ConnectionManager:
connector.get_client_id()
connector.get_client_secret()
return True
- except (ValueError, NotImplementedError):
- return False
+ except (ValueError, NotImplementedError, RuntimeError):
+ # Fallback: saved per-user connection config (e.g. aws_s3 / ibm_cos)
+ return self._has_saved_credentials_for_user(connector_type, user_id)
def _create_connector(self, config: ConnectionConfig) -> BaseConnector:
"""Factory method to create connector instances"""