mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-29 19:35:20 +02:00
BE-2: Remove duplicate-check logic and enable user-friendly auto-naming for Airtable and Confluence connector OAuth flows
This commit is contained in:
parent
c58a3fba55
commit
d75df7e5b2
2 changed files with 44 additions and 66 deletions
|
|
@ -23,6 +23,7 @@ from app.db import (
|
||||||
from app.schemas.airtable_auth_credentials import AirtableAuthCredentialsBase
|
from app.schemas.airtable_auth_credentials import AirtableAuthCredentialsBase
|
||||||
from app.users import current_active_user
|
from app.users import current_active_user
|
||||||
from app.utils.oauth_security import OAuthStateManager, TokenEncryption
|
from app.utils.oauth_security import OAuthStateManager, TokenEncryption
|
||||||
|
from app.utils.connector_naming import generate_unique_connector_name, extract_identifier_from_credentials
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -297,39 +298,27 @@ async def airtable_callback(
|
||||||
credentials_dict = credentials.to_dict()
|
credentials_dict = credentials.to_dict()
|
||||||
credentials_dict["_token_encrypted"] = True
|
credentials_dict["_token_encrypted"] = True
|
||||||
|
|
||||||
# Check if connector already exists for this search space and user
|
# Extract unique identifier from connector credentials
|
||||||
existing_connector_result = await session.execute(
|
connector_identifier = extract_identifier_from_credentials(
|
||||||
select(SearchSourceConnector).filter(
|
SearchSourceConnectorType.AIRTABLE_CONNECTOR, credentials_dict
|
||||||
SearchSourceConnector.search_space_id == space_id,
|
)
|
||||||
SearchSourceConnector.user_id == user_id,
|
# Generate a unique, user-friendly connector name from credentials/account info
|
||||||
SearchSourceConnector.connector_type
|
connector_name = generate_unique_connector_name(
|
||||||
== SearchSourceConnectorType.AIRTABLE_CONNECTOR,
|
SearchSourceConnectorType.AIRTABLE_CONNECTOR, connector_identifier
|
||||||
)
|
)
|
||||||
|
# Create new connector
|
||||||
|
new_connector = SearchSourceConnector(
|
||||||
|
name=connector_name,
|
||||||
|
connector_type=SearchSourceConnectorType.AIRTABLE_CONNECTOR,
|
||||||
|
is_indexable=True,
|
||||||
|
config=credentials_dict,
|
||||||
|
search_space_id=space_id,
|
||||||
|
user_id=user_id,
|
||||||
|
)
|
||||||
|
session.add(new_connector)
|
||||||
|
logger.info(
|
||||||
|
f"Created new Airtable connector for user {user_id} in space {space_id}"
|
||||||
)
|
)
|
||||||
existing_connector = existing_connector_result.scalars().first()
|
|
||||||
|
|
||||||
if existing_connector:
|
|
||||||
# Update existing connector
|
|
||||||
existing_connector.config = credentials_dict
|
|
||||||
existing_connector.name = "Airtable Connector"
|
|
||||||
existing_connector.is_indexable = True
|
|
||||||
logger.info(
|
|
||||||
f"Updated existing Airtable connector for user {user_id} in space {space_id}"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# Create new connector
|
|
||||||
new_connector = SearchSourceConnector(
|
|
||||||
name="Airtable Connector",
|
|
||||||
connector_type=SearchSourceConnectorType.AIRTABLE_CONNECTOR,
|
|
||||||
is_indexable=True,
|
|
||||||
config=credentials_dict,
|
|
||||||
search_space_id=space_id,
|
|
||||||
user_id=user_id,
|
|
||||||
)
|
|
||||||
session.add(new_connector)
|
|
||||||
logger.info(
|
|
||||||
f"Created new Airtable connector for user {user_id} in space {space_id}"
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
|
@ -350,7 +339,7 @@ async def airtable_callback(
|
||||||
await session.rollback()
|
await session.rollback()
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=409,
|
status_code=409,
|
||||||
detail=f"Integrity error: A connector with this type already exists. {e!s}",
|
detail=f"Database integrity error: {e!s}",
|
||||||
) from e
|
) from e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to create search source connector: {e!s}")
|
logger.error(f"Failed to create search source connector: {e!s}")
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ from app.db import (
|
||||||
from app.schemas.atlassian_auth_credentials import AtlassianAuthCredentialsBase
|
from app.schemas.atlassian_auth_credentials import AtlassianAuthCredentialsBase
|
||||||
from app.users import current_active_user
|
from app.users import current_active_user
|
||||||
from app.utils.oauth_security import OAuthStateManager, TokenEncryption
|
from app.utils.oauth_security import OAuthStateManager, TokenEncryption
|
||||||
|
from app.utils.connector_naming import generate_unique_connector_name, extract_identifier_from_credentials
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -288,39 +289,27 @@ async def confluence_callback(
|
||||||
"_token_encrypted": True,
|
"_token_encrypted": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if connector already exists for this search space and user
|
# Extract unique identifier from connector credentials
|
||||||
existing_connector_result = await session.execute(
|
connector_identifier = extract_identifier_from_credentials(
|
||||||
select(SearchSourceConnector).filter(
|
SearchSourceConnectorType.CONFLUENCE_CONNECTOR, connector_config
|
||||||
SearchSourceConnector.search_space_id == space_id,
|
)
|
||||||
SearchSourceConnector.user_id == user_id,
|
# Generate a unique, user-friendly connector name from credentials/account info
|
||||||
SearchSourceConnector.connector_type
|
connector_name = generate_unique_connector_name(
|
||||||
== SearchSourceConnectorType.CONFLUENCE_CONNECTOR,
|
SearchSourceConnectorType.CONFLUENCE_CONNECTOR, connector_identifier
|
||||||
)
|
)
|
||||||
|
# Create new connector
|
||||||
|
new_connector = SearchSourceConnector(
|
||||||
|
name=connector_name,
|
||||||
|
connector_type=SearchSourceConnectorType.CONFLUENCE_CONNECTOR,
|
||||||
|
is_indexable=True,
|
||||||
|
config=connector_config,
|
||||||
|
search_space_id=space_id,
|
||||||
|
user_id=user_id,
|
||||||
|
)
|
||||||
|
session.add(new_connector)
|
||||||
|
logger.info(
|
||||||
|
f"Created new Confluence connector for user {user_id} in space {space_id}"
|
||||||
)
|
)
|
||||||
existing_connector = existing_connector_result.scalars().first()
|
|
||||||
|
|
||||||
if existing_connector:
|
|
||||||
# Update existing connector
|
|
||||||
existing_connector.config = connector_config
|
|
||||||
existing_connector.name = "Confluence Connector"
|
|
||||||
existing_connector.is_indexable = True
|
|
||||||
logger.info(
|
|
||||||
f"Updated existing Confluence connector for user {user_id} in space {space_id}"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# Create new connector
|
|
||||||
new_connector = SearchSourceConnector(
|
|
||||||
name="Confluence Connector",
|
|
||||||
connector_type=SearchSourceConnectorType.CONFLUENCE_CONNECTOR,
|
|
||||||
is_indexable=True,
|
|
||||||
config=connector_config,
|
|
||||||
search_space_id=space_id,
|
|
||||||
user_id=user_id,
|
|
||||||
)
|
|
||||||
session.add(new_connector)
|
|
||||||
logger.info(
|
|
||||||
f"Created new Confluence connector for user {user_id} in space {space_id}"
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
|
@ -340,7 +329,7 @@ async def confluence_callback(
|
||||||
await session.rollback()
|
await session.rollback()
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=409,
|
status_code=409,
|
||||||
detail=f"Integrity error: A connector with this type already exists. {e!s}",
|
detail=f"Database integrity error: {e!s}",
|
||||||
) from e
|
) from e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to create search source connector: {e!s}")
|
logger.error(f"Failed to create search source connector: {e!s}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue