Add support e-mail to settings (#1960)
Adds support email to /api/settings Also adds a response model for this endpoint and consolidates api tests Addresses request in #1912
This commit is contained in:
parent
8c4e481bd3
commit
a8c5f07b7c
@ -13,6 +13,7 @@ from fastapi.routing import APIRouter
|
|||||||
|
|
||||||
from fastapi.openapi.utils import get_openapi
|
from fastapi.openapi.utils import get_openapi
|
||||||
from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html
|
from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from .db import init_db, await_db_and_migrations, update_and_prepare_db
|
from .db import init_db, await_db_and_migrations, update_and_prepare_db
|
||||||
|
|
||||||
@ -98,9 +99,29 @@ See [https://docs.browsertrix.com/](https://docs.browsertrix.com/) for more info
|
|||||||
return schema
|
return schema
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
class SettingsResponse(BaseModel):
|
||||||
|
"""/api/settings response model"""
|
||||||
|
|
||||||
|
registrationEnabled: bool
|
||||||
|
|
||||||
|
jwtTokenLifetime: int
|
||||||
|
|
||||||
|
defaultBehaviorTimeSeconds: int
|
||||||
|
defaultPageLoadTimeSeconds: int
|
||||||
|
|
||||||
|
maxPagesPerCrawl: int
|
||||||
|
maxScale: int
|
||||||
|
|
||||||
|
billingEnabled: bool
|
||||||
|
|
||||||
|
salesEmail: str = ""
|
||||||
|
supportEmail: str = ""
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# pylint: disable=too-many-locals, duplicate-code
|
# pylint: disable=too-many-locals, duplicate-code
|
||||||
def main():
|
def main() -> None:
|
||||||
"""init browsertrix api"""
|
"""init browsertrix api"""
|
||||||
|
|
||||||
app = APIRouter()
|
app = APIRouter()
|
||||||
@ -110,20 +131,21 @@ def main():
|
|||||||
|
|
||||||
dbclient, mdb = init_db()
|
dbclient, mdb = init_db()
|
||||||
|
|
||||||
settings = {
|
settings = SettingsResponse(
|
||||||
"registrationEnabled": is_bool(os.environ.get("REGISTRATION_ENABLED")),
|
registrationEnabled=is_bool(os.environ.get("REGISTRATION_ENABLED")),
|
||||||
"jwtTokenLifetime": JWT_TOKEN_LIFETIME,
|
jwtTokenLifetime=JWT_TOKEN_LIFETIME,
|
||||||
"defaultBehaviorTimeSeconds": int(
|
defaultBehaviorTimeSeconds=int(
|
||||||
os.environ.get("DEFAULT_BEHAVIOR_TIME_SECONDS", 300)
|
os.environ.get("DEFAULT_BEHAVIOR_TIME_SECONDS", 300)
|
||||||
),
|
),
|
||||||
"defaultPageLoadTimeSeconds": int(
|
defaultPageLoadTimeSeconds=int(
|
||||||
os.environ.get("DEFAULT_PAGE_LOAD_TIME_SECONDS", 120)
|
os.environ.get("DEFAULT_PAGE_LOAD_TIME_SECONDS", 120)
|
||||||
),
|
),
|
||||||
"maxPagesPerCrawl": int(os.environ.get("MAX_PAGES_PER_CRAWL", 0)),
|
maxPagesPerCrawl=int(os.environ.get("MAX_PAGES_PER_CRAWL", 0)),
|
||||||
"maxScale": int(os.environ.get("MAX_CRAWL_SCALE", 3)),
|
maxScale=int(os.environ.get("MAX_CRAWL_SCALE", 3)),
|
||||||
"billingEnabled": is_bool(os.environ.get("BILLING_ENABLED")),
|
billingEnabled=is_bool(os.environ.get("BILLING_ENABLED")),
|
||||||
"salesEmail": os.environ.get("SALES_EMAIL"),
|
salesEmail=os.environ.get("SALES_EMAIL", ""),
|
||||||
}
|
supportEmail=os.environ.get("EMAIL_SUPPORT", ""),
|
||||||
|
)
|
||||||
|
|
||||||
invites = init_invites(mdb, email)
|
invites = init_invites(mdb, email)
|
||||||
|
|
||||||
@ -245,8 +267,8 @@ def main():
|
|||||||
|
|
||||||
app.include_router(org_ops.router)
|
app.include_router(org_ops.router)
|
||||||
|
|
||||||
@app.get("/settings", tags=["settings"])
|
@app.get("/settings", tags=["settings"], response_model=SettingsResponse)
|
||||||
async def get_settings():
|
async def get_settings() -> SettingsResponse:
|
||||||
if not db_inited.get("inited"):
|
if not db_inited.get("inited"):
|
||||||
raise HTTPException(status_code=503, detail="not_ready_yet")
|
raise HTTPException(status_code=503, detail="not_ready_yet")
|
||||||
return settings
|
return settings
|
||||||
|
@ -30,3 +30,22 @@ def test_api_openapi():
|
|||||||
json = r.json()
|
json = r.json()
|
||||||
assert json["info"]["title"] == "Browsertrix"
|
assert json["info"]["title"] == "Browsertrix"
|
||||||
assert json["info"]["x-logo"]["url"] == "/docs-logo.svg"
|
assert json["info"]["x-logo"]["url"] == "/docs-logo.svg"
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_settings():
|
||||||
|
r = requests.get(f"{API_PREFIX}/settings")
|
||||||
|
assert r.status_code == 200
|
||||||
|
|
||||||
|
data = r.json()
|
||||||
|
|
||||||
|
assert data == {
|
||||||
|
"registrationEnabled": False,
|
||||||
|
"jwtTokenLifetime": 86400,
|
||||||
|
"defaultBehaviorTimeSeconds": 300,
|
||||||
|
"maxPagesPerCrawl": 4,
|
||||||
|
"maxScale": 3,
|
||||||
|
"defaultPageLoadTimeSeconds": 120,
|
||||||
|
"billingEnabled": True,
|
||||||
|
"salesEmail": "",
|
||||||
|
"supportEmail": "",
|
||||||
|
}
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
import requests
|
|
||||||
|
|
||||||
from .conftest import API_PREFIX
|
|
||||||
|
|
||||||
|
|
||||||
def test_settings():
|
|
||||||
r = requests.get(f"{API_PREFIX}/settings")
|
|
||||||
assert r.status_code == 200
|
|
||||||
|
|
||||||
data = r.json()
|
|
||||||
|
|
||||||
assert data == {
|
|
||||||
"registrationEnabled": False,
|
|
||||||
"jwtTokenLifetime": 86400,
|
|
||||||
"defaultBehaviorTimeSeconds": 300,
|
|
||||||
"maxPagesPerCrawl": 4,
|
|
||||||
"maxScale": 3,
|
|
||||||
"defaultPageLoadTimeSeconds": 120,
|
|
||||||
"billingEnabled": True,
|
|
||||||
"salesEmail": "",
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user