From 6acf5fca5f95d0c9bd0b0d1e6f8ddc4f788cef52 Mon Sep 17 00:00:00 2001 From: Stan Girard Date: Sat, 6 Apr 2024 19:34:46 -0700 Subject: [PATCH] fix: Add integration brain to subscription route (#2410) # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate): --- backend/routes/subscription_routes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/routes/subscription_routes.py b/backend/routes/subscription_routes.py index 785226e43..1b50075f3 100644 --- a/backend/routes/subscription_routes.py +++ b/backend/routes/subscription_routes.py @@ -21,7 +21,13 @@ from repository.brain_subscription import ( SubscriptionInvitationService, resend_invitation_email, ) +from modules.brain.repository import ( + IntegrationBrain, +) from routes.headers.get_origin_header import get_origin_header +from logger import get_logger + +logger = get_logger(__name__) subscription_router = APIRouter() subscription_service = SubscriptionInvitationService() @@ -30,6 +36,7 @@ prompt_service = PromptService() brain_user_service = BrainUserService() brain_service = BrainService() api_brain_definition_service = ApiBrainDefinitionService() +integration_brains_repository = IntegrationBrain() @subscription_router.post( @@ -249,7 +256,18 @@ async def accept_invitation( rights=invitation["rights"], is_default_brain=False, ) + shared_brain = brain_service.get_brain_by_id(brain_id) + integration_brain = integration_brains_repository.get_integration_brain( + brain_id=brain_id, + ) + integration_brains_repository.add_integration_brain( + brain_id=brain_id, + user_id=current_user.id, + integration_id=integration_brain.integration_id, + settings=integration_brain.settings, + ) except Exception as e: + logger.error(f"Error adding user to brain: {e}") raise HTTPException(status_code=400, detail=f"Error adding user to brain: {e}") try: