mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: disable docs for non-dev envs and introduce internal APIs
This commit is contained in:
parent
7faccfd7e6
commit
5f4ec65e4d
4 changed files with 89 additions and 2 deletions
|
|
@ -25,6 +25,8 @@ learnhouse_config: LearnHouseConfig = get_learnhouse_config()
|
|||
app = FastAPI(
|
||||
title=learnhouse_config.site_name,
|
||||
description=learnhouse_config.site_description,
|
||||
docs_url="/docs" if learnhouse_config.general_config.development_mode else None,
|
||||
redoc_url="/redoc" if learnhouse_config.general_config.development_mode else None,
|
||||
version="0.1.0",
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import os
|
||||
from fastapi import APIRouter, Depends
|
||||
from src.routers import usergroups
|
||||
from src.routers import dev, trail, users, auth, orgs, roles
|
||||
from src.routers.ai import ai
|
||||
from src.routers.courses import chapters, collections, courses, assignments
|
||||
from src.routers.courses.activities import activities, blocks
|
||||
from src.routers.ee import cloud_internal
|
||||
from src.routers.install import install
|
||||
from src.services.dev.dev import isDevModeEnabledOrRaise
|
||||
from src.services.install.install import isInstallModeEnabled
|
||||
|
|
@ -20,13 +22,25 @@ v1_router.include_router(orgs.router, prefix="/orgs", tags=["orgs"])
|
|||
v1_router.include_router(roles.router, prefix="/roles", tags=["roles"])
|
||||
v1_router.include_router(blocks.router, prefix="/blocks", tags=["blocks"])
|
||||
v1_router.include_router(courses.router, prefix="/courses", tags=["courses"])
|
||||
v1_router.include_router(assignments.router, prefix="/assignments", tags=["assignments"])
|
||||
v1_router.include_router(
|
||||
assignments.router, prefix="/assignments", tags=["assignments"]
|
||||
)
|
||||
v1_router.include_router(chapters.router, prefix="/chapters", tags=["chapters"])
|
||||
v1_router.include_router(activities.router, prefix="/activities", tags=["activities"])
|
||||
v1_router.include_router(collections.router, prefix="/collections", tags=["collections"])
|
||||
v1_router.include_router(
|
||||
collections.router, prefix="/collections", tags=["collections"]
|
||||
)
|
||||
v1_router.include_router(trail.router, prefix="/trail", tags=["trail"])
|
||||
v1_router.include_router(ai.router, prefix="/ai", tags=["ai"])
|
||||
|
||||
if os.environ.get("CLOUD_INTERNAL_KEY"):
|
||||
v1_router.include_router(
|
||||
cloud_internal.router,
|
||||
prefix="/cloud_internal",
|
||||
tags=["cloud_internal"],
|
||||
dependencies=[Depends(cloud_internal.check_internal_cloud_key)],
|
||||
)
|
||||
|
||||
# Dev Routes
|
||||
v1_router.include_router(
|
||||
dev.router,
|
||||
|
|
|
|||
29
apps/api/src/routers/ee/cloud_internal.py
Normal file
29
apps/api/src/routers/ee/cloud_internal.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import os
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from sqlmodel import Session
|
||||
from src.core.events.database import get_db_session
|
||||
from src.db.organization_config import OrganizationConfigBase
|
||||
from src.services.orgs.orgs import update_org_with_config_no_auth
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# Utils
|
||||
def check_internal_cloud_key(request: Request):
|
||||
if request.headers.get("CloudInternalKey") != os.environ.get(
|
||||
"CLOUD_INTERNAL_KEY"
|
||||
):
|
||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||
|
||||
|
||||
@router.put("/update_org_config")
|
||||
async def update_org_Config(
|
||||
request: Request,
|
||||
org_id: int,
|
||||
config_object: OrganizationConfigBase,
|
||||
db_session: Session = Depends(get_db_session),
|
||||
):
|
||||
|
||||
res = await update_org_with_config_no_auth(
|
||||
request, config_object, org_id, db_session
|
||||
)
|
||||
return res
|
||||
|
|
@ -338,6 +338,48 @@ async def update_org(
|
|||
|
||||
return org
|
||||
|
||||
async def update_org_with_config_no_auth(
|
||||
request: Request,
|
||||
orgconfig: OrganizationConfigBase,
|
||||
org_id: int,
|
||||
db_session: Session,
|
||||
):
|
||||
statement = select(Organization).where(Organization.id == org_id)
|
||||
result = db_session.exec(statement)
|
||||
|
||||
org = result.first()
|
||||
|
||||
if not org:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Organization slug not found",
|
||||
)
|
||||
|
||||
# Get org config
|
||||
statement = select(OrganizationConfig).where(OrganizationConfig.org_id == org.id)
|
||||
result = db_session.exec(statement)
|
||||
|
||||
org_config = result.first()
|
||||
|
||||
if org_config is None:
|
||||
logging.error(f"Organization {org_id} has no config")
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Organization config not found",
|
||||
)
|
||||
|
||||
updated_config = orgconfig
|
||||
|
||||
# Update the database
|
||||
org_config.config = json.loads(updated_config.json())
|
||||
org_config.update_date = str(datetime.now())
|
||||
|
||||
db_session.add(org_config)
|
||||
db_session.commit()
|
||||
db_session.refresh(org_config)
|
||||
|
||||
return {"detail": "Organization updated"}
|
||||
|
||||
|
||||
async def update_org_logo(
|
||||
request: Request,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue