From f9dce4b7847296e17b2bbe2fe8bf3c544072ec0b Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 2 Dec 2024 15:53:22 +0100 Subject: [PATCH] Add mail endpoint for sending test emails Introduced a new API endpoint to send test emails to curators. A new `TestMail` model was added to handle the email payload. Updated the API router to include routes for the mailing functionality. --- app/api/api.py | 3 +++ app/api/endpoints/mail.py | 25 +++++++++++++++++++++++++ app/api/models/setup/project.py | 9 ++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/api/endpoints/mail.py diff --git a/app/api/api.py b/app/api/api.py index 4215ba2..f6079d3 100644 --- a/app/api/api.py +++ b/app/api/api.py @@ -6,6 +6,7 @@ from app.api.endpoints import publish from app.api.endpoints import info from app.api.endpoints import order +from app.api.endpoints import Mail api_router = APIRouter(prefix="/api/v1") @@ -18,3 +19,5 @@ api_router.include_router(publish.router, prefix="/publish", tags=["Publish"]) api_router.include_router(publish.router, prefix="/auth", tags=["Auth"]) api_router.include_router(order.router, prefix="/order", tags=["Order"]) + +api_router.include_router(order.router, prefix="/mail", tags=["Mail"]) diff --git a/app/api/endpoints/mail.py b/app/api/endpoints/mail.py new file mode 100644 index 0000000..76cafa7 --- /dev/null +++ b/app/api/endpoints/mail.py @@ -0,0 +1,25 @@ +from fastapi import APIRouter, Body, Depends, HTTPException, status, Response, Request, BackgroundTasks +from fastapi.responses import JSONResponse +from fastapi.encoders import jsonable_encoder + +from app.api.middlewares.http_basic_auth import * +from app.api.models.setup.project import TestMail +from app.tasks.email.send_mail import send_curator_mail + +router = APIRouter() + +@router.post("/send_test_curator_mail", summary="Send test mail", status_code=status.HTTP_201_CREATED, + response_class=Response, dependencies=[Depends(basic_auth)], + description="Send Curator Test Mail") +async def send_test_mail(request: Request, payload: TestMail, background_tasks: BackgroundTasks): + + username = payload.username + project_name = payload.projectname + submission_url = payload.submission_url + + curator_mail = os.environ.get("CURATOR_MAIL", None) + curator_mail = curator_mail.split(',') + + + background_tasks.add_task(send_curator_mail, curator_mail, username, project_name, submission_url) + return Response(status_code=status.HTTP_201_CREATED) \ No newline at end of file diff --git a/app/api/models/setup/project.py b/app/api/models/setup/project.py index 13fbf46..adf7a52 100644 --- a/app/api/models/setup/project.py +++ b/app/api/models/setup/project.py @@ -1,7 +1,8 @@ from __future__ import annotations from pydantic import BaseModel -from typing import Optional +from typing import Optional, List + class Project(BaseModel): project_id: int @@ -9,3 +10,9 @@ class Project(BaseModel): class Projects(BaseModel): overwrite: Optional[bool] = False + +class TestMail(BaseModel): + receiver: List[str] + username: str + projectname: str + submission_url: str \ No newline at end of file