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):
This commit is contained in:
Stan Girard 2024-04-06 19:34:46 -07:00 committed by GitHub
parent 68db4e0361
commit 6acf5fca5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: