quivr/backend/routes/subscription_routes.py
Zineb El Bachiri f837a6e9b9
Feat/shareable brains send link be (#599)
* 🗃️ new table for invitations to subscribe to brain

*  new BrainSubscription class

*  new subscription router

* 👽️ add RESEND_API_KEY to .env in BE

* 📦 add 'resend' lib to requirements

* ♻️ fix some stanGPT
2023-07-11 18:20:31 +02:00

26 lines
1.0 KiB
Python

from typing import List
from uuid import UUID
from auth.auth_bearer import get_current_user
from fastapi import APIRouter, Depends, HTTPException
from models.brains_subscription_invitations import BrainSubscription
from models.users import User
subscription_router = APIRouter()
@subscription_router.post("/brain/{brain_id}/subscription")
async def invite_user_to_brain(brain_id: UUID, users: List[dict], current_user: User = Depends(get_current_user)):
# TODO: Ensure the current user has permissions to invite users to this brain
for user in users:
subscription = BrainSubscription(brain_id=brain_id, email=user['email'], rights=user['rights'], inviter_email=current_user.email or "Quivr")
try:
subscription.create_or_update_subscription_invitation()
subscription.resend_invitation_email()
except Exception as e:
raise HTTPException(status_code=400, detail=f"Error inviting user: {e}")
return {"message": "Invitations sent successfully"}