diff --git a/.env.example b/.env.example index e1c39be4..8df49676 100644 --- a/.env.example +++ b/.env.example @@ -10,14 +10,6 @@ DOMAIN=localhost # DOMAIN=localhost.tiangolo.com -# Used by the backend to generate links in emails to the frontend - -FRONTEND_HOST=http://localhost:5173 - -# In staging and production, set this env var to the frontend host, e.g. - -# FRONTEND_HOST=https://dashboard.example.com - # Environment: local, staging, production ENVIRONMENT=local @@ -25,22 +17,11 @@ ENVIRONMENT=local PROJECT_NAME="AI Platform" STACK_NAME=ai-platform -# Backend - -BACKEND_CORS_ORIGINS="http://localhost:5173" +#Backend SECRET_KEY=changethis FIRST_SUPERUSER=superuser@example.com FIRST_SUPERUSER_PASSWORD=changethis - -# Emails - -SMTP_HOST= -SMTP_USER= -SMTP_PASSWORD= -EMAILS_FROM_EMAIL=info@example.com -SMTP_TLS=True -SMTP_SSL=False -SMTP_PORT=587 +EMAIL_TEST_USER="test@example.com" # Postgres @@ -62,6 +43,7 @@ DOCKER_IMAGE_FRONTEND=frontend AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=ap-south-1 +AWS_S3_BUCKET_PREFIX = "bucket-prefix-name" # OpenAI diff --git a/backend/app/core/config.py b/backend/app/core/config.py index 8a2d8019..24779bf3 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -4,8 +4,6 @@ from typing import Annotated, Any, Literal from pydantic import ( - AnyUrl, - BeforeValidator, EmailStr, HttpUrl, PostgresDsn, @@ -40,20 +38,8 @@ class Settings(BaseSettings): SECRET_KEY: str = secrets.token_urlsafe(32) # 60 minutes * 24 hours * 1 days = 1 days ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 1 - FRONTEND_HOST: str = "http://localhost:5173" ENVIRONMENT: Literal["local", "staging", "production"] = "local" - BACKEND_CORS_ORIGINS: Annotated[ - list[AnyUrl] | str, BeforeValidator(parse_cors) - ] = [] - - @computed_field # type: ignore[prop-decorator] - @property - def all_cors_origins(self) -> list[str]: - return [str(origin).rstrip("/") for origin in self.BACKEND_CORS_ORIGINS] + [ - self.FRONTEND_HOST - ] - PROJECT_NAME: str SENTRY_DSN: HttpUrl | None = None POSTGRES_SERVER: str @@ -74,40 +60,21 @@ def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn: path=self.POSTGRES_DB, ) - SMTP_TLS: bool = True - SMTP_SSL: bool = False - SMTP_PORT: int = 587 - SMTP_HOST: str | None = None - SMTP_USER: str | None = None - SMTP_PASSWORD: str | None = None - EMAILS_FROM_EMAIL: EmailStr | None = None - EMAILS_FROM_NAME: EmailStr | None = None - - @model_validator(mode="after") - def _set_default_emails_from(self) -> Self: - if not self.EMAILS_FROM_NAME: - self.EMAILS_FROM_NAME = self.PROJECT_NAME - return self - EMAIL_RESET_TOKEN_EXPIRE_HOURS: int = 48 + EMAIL_TEST_USER: EmailStr - @computed_field # type: ignore[prop-decorator] - @property - def emails_enabled(self) -> bool: - return bool(self.SMTP_HOST and self.EMAILS_FROM_EMAIL) - - EMAIL_TEST_USER: EmailStr = "test@example.com" FIRST_SUPERUSER: EmailStr FIRST_SUPERUSER_PASSWORD: str AWS_ACCESS_KEY_ID: str = "" AWS_SECRET_ACCESS_KEY: str = "" AWS_DEFAULT_REGION: str = "" + AWS_S3_BUCKET_PREFIX: str = "" @computed_field # type: ignore[prop-decorator] @property def AWS_S3_BUCKET(self) -> str: - return f"ai-platform-documents-{self.ENVIRONMENT}" + return f"{self.AWS_S3_BUCKET_PREFIX}-{self.ENVIRONMENT}" LOG_DIR: str = os.path.join(os.path.dirname(os.path.dirname(__file__)), "logs") diff --git a/backend/app/main.py b/backend/app/main.py index 49cc0e9e..0d7a1b0e 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -2,7 +2,6 @@ from fastapi import FastAPI, HTTPException from fastapi.routing import APIRoute -from starlette.middleware.cors import CORSMiddleware from app.api.main import api_router from app.api.deps import http_exception_handler @@ -22,16 +21,6 @@ def custom_generate_unique_id(route: APIRoute) -> str: generate_unique_id_function=custom_generate_unique_id, ) -# Set all CORS enabled origins -if settings.all_cors_origins: - app.add_middleware( - CORSMiddleware, - allow_origins=settings.all_cors_origins, - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], - ) - app.include_router(api_router, prefix=settings.API_V1_STR) app.add_exception_handler(HTTPException, http_exception_handler) diff --git a/backend/app/tests/api/routes/test_login.py b/backend/app/tests/api/routes/test_login.py index 80fa7879..d20998b1 100644 --- a/backend/app/tests/api/routes/test_login.py +++ b/backend/app/tests/api/routes/test_login.py @@ -45,22 +45,6 @@ def test_use_access_token( assert "email" in result -def test_recovery_password( - client: TestClient, normal_user_token_headers: dict[str, str] -) -> None: - with ( - patch("app.core.config.settings.SMTP_HOST", "smtp.example.com"), - patch("app.core.config.settings.SMTP_USER", "admin@example.com"), - ): - email = "test@example.com" - r = client.post( - f"{settings.API_V1_STR}/password-recovery/{email}", - headers=normal_user_token_headers, - ) - assert r.status_code == 200 - assert r.json() == {"message": "Password recovery email sent"} - - def test_recovery_password_user_not_exits( client: TestClient, normal_user_token_headers: dict[str, str] ) -> None: diff --git a/backend/app/tests/api/routes/test_users.py b/backend/app/tests/api/routes/test_users.py index ac518075..e54a3167 100644 --- a/backend/app/tests/api/routes/test_users.py +++ b/backend/app/tests/api/routes/test_users.py @@ -33,29 +33,6 @@ def test_get_users_normal_user_me( assert current_user["email"] == settings.EMAIL_TEST_USER -def test_create_user_new_email( - client: TestClient, superuser_token_headers: dict[str, str], db: Session -) -> None: - with ( - patch("app.utils.send_email", return_value=None), - patch("app.core.config.settings.SMTP_HOST", "smtp.example.com"), - patch("app.core.config.settings.SMTP_USER", "admin@example.com"), - ): - username = random_email() - password = random_lower_string() - data = {"email": username, "password": password} - r = client.post( - f"{settings.API_V1_STR}/users/", - headers=superuser_token_headers, - json=data, - ) - assert 200 <= r.status_code < 300 - created_user = r.json() - user = crud.get_user_by_email(session=db, email=username) - assert user - assert user.email == created_user["email"] - - def test_get_existing_user( client: TestClient, superuser_token_headers: dict[str, str], db: Session ) -> None: