mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-16 07:28:34 +03:00
pushing bulk of changes
This commit is contained in:
@@ -6,8 +6,9 @@ from sqlalchemy.orm import Session
|
||||
from core.config import VERSION, BREAKING_CHANGES
|
||||
from core.logging import log_error
|
||||
from db import crud, schemas
|
||||
from db.database import get_db_dependency, get_db
|
||||
from web.security import get_user_auth, bearer_security
|
||||
from db.database import get_db_dependency
|
||||
from db.user_state import UserState
|
||||
from web.security import get_user_auth, bearer_security, get_active_user_state
|
||||
|
||||
default_router = APIRouter()
|
||||
|
||||
@@ -18,8 +19,7 @@ async def home(request: Request):
|
||||
status = {"version": VERSION, "breakingChanges": BREAKING_CHANGES}
|
||||
try:
|
||||
email = await get_user_auth(await bearer_security(request))
|
||||
with get_db() as db:
|
||||
status["groups"] = crud.get_user_groups(db, email)
|
||||
status["groups"] = crud.get_user_groups(email)
|
||||
except HTTPException: pass # not authenticated is fine
|
||||
except Exception as e: log_error(e)
|
||||
return JSONResponse(status)
|
||||
@@ -31,13 +31,28 @@ async def health():
|
||||
|
||||
|
||||
@default_router.get("/user/active", summary="Check if the user is active and can use the tool.")
|
||||
# TODO: reorder db dependencies to after auth
|
||||
async def active(db: Session = Depends(get_db_dependency), email=Depends(get_user_auth)) -> schemas.ActiveUser:
|
||||
return {"active": crud.is_active_user(db, email)}
|
||||
|
||||
|
||||
@default_router.get("/groups")
|
||||
def get_user_groups(db: Session = Depends(get_db_dependency), email=Depends(get_user_auth)) -> list[str]:
|
||||
return crud.get_user_groups(db, email)
|
||||
def get_user_groups(email=Depends(get_user_auth)) -> list[str]:
|
||||
return crud.get_user_groups(email)
|
||||
|
||||
|
||||
@default_router.get("/permissions")
|
||||
def get_user_groups(
|
||||
user: UserState = Depends(get_active_user_state),
|
||||
) -> list[str]:
|
||||
return JSONResponse({
|
||||
"groups": user.user_groups_names,
|
||||
"allowedFrequencies": list(user.allowed_frequencies),
|
||||
"sheet_quota": user.sheet_quota,
|
||||
"monthly_urls": user.monthly_urls,
|
||||
"monthly_mbs": user.monthly_mbs,
|
||||
#TODO: should this return
|
||||
})
|
||||
|
||||
|
||||
@default_router.get('/favicon.ico', include_in_schema=False)
|
||||
|
||||
Reference in New Issue
Block a user