Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,18 @@ 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

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

Expand All @@ -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

Expand Down
39 changes: 3 additions & 36 deletions backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from typing import Annotated, Any, Literal

from pydantic import (
AnyUrl,
BeforeValidator,
EmailStr,
HttpUrl,
PostgresDsn,
Expand Down Expand Up @@ -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
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is also to check if we are using these variables and if not then remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is being used in test cases for user and login routes


@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")

Expand Down
11 changes: 0 additions & 11 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
16 changes: 0 additions & 16 deletions backend/app/tests/api/routes/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 0 additions & 23 deletions backend/app/tests/api/routes/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down