feat: sua added to group invitations
All checks were successful
ci / lint_and_test (push) Successful in 13s
All checks were successful
ci / lint_and_test (push) Successful in 13s
Issue: #23
This commit is contained in:
parent
7809df4c5a
commit
768a3881ef
4 changed files with 110 additions and 3 deletions
|
|
@ -6,11 +6,14 @@ Exports:
|
|||
"""
|
||||
|
||||
from typing import Annotated
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from src.service.models import Service
|
||||
from src.database import db_dependency
|
||||
from src.schemas import ResourceName
|
||||
from src.auth.exceptions import UnauthorizedException
|
||||
from src.utils import send_email, generate_jwt
|
||||
|
||||
|
||||
from fastapi import Request, Depends
|
||||
|
||||
|
|
@ -33,3 +36,28 @@ def valid_service_key(db: db_dependency, request: Request, rn: ResourceName) ->
|
|||
|
||||
|
||||
service_key_dependency = Annotated[bool, Depends(valid_service_key)]
|
||||
|
||||
|
||||
async def send_user_group_invitation(
|
||||
user_email: str, org_name: str, org_id: int, group_id: int, group_name: str
|
||||
):
|
||||
expiry_delta = timedelta(hours=24)
|
||||
expiry = datetime.now(timezone.utc) + expiry_delta
|
||||
claims = {
|
||||
"email": user_email,
|
||||
"org_id": org_id,
|
||||
"group_id": group_id,
|
||||
"group_name": group_name,
|
||||
"exp": expiry,
|
||||
"type": "group_invite",
|
||||
}
|
||||
|
||||
token = await generate_jwt(claims)
|
||||
subject = f"You have been invited to join a group of {org_name}"
|
||||
body = f"You have been invited to join {group_name}.\nClick the link to accept.\nfrontend.capture/send/to/endpoint/{token}"
|
||||
|
||||
await send_email(
|
||||
recipient=user_email,
|
||||
subject=subject,
|
||||
body=body,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue