Skip to content

Commit

Permalink
Tidy auth dependencies a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBacon committed Sep 18, 2024
1 parent c286b0e commit 758d1b1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def get_current_admin_user(
# Create a type alias for brevity when defining an endpoint needing
# authentication.
Auth: TypeAlias = Annotated[User, Depends(get_current_user)]
Admin: TypeAlias = Annotated[User, Depends(get_current_admin_user)]
AdminDependency: TypeAlias = Annotated[User, Depends(get_current_admin_user)]


@router.post(
Expand Down
11 changes: 6 additions & 5 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from fastapi import APIRouter, Depends, Request
from pydantic import BaseModel

import app.auth as auth
from app.auth import AdminDependency, get_current_admin_user
import app.main as app
# from app.county.county_routes import router as county_router
from app.auth import router as auth_router
from app.rule.rule_routes import router as rule_router
from app.settings import SettingsDependency
from app.species.species_routes import router as species_router
Expand Down Expand Up @@ -43,7 +44,7 @@ class SettingResponse(BaseModel):

# Instantiate a router.
router = APIRouter()
router.include_router(auth.router)
router.include_router(auth_router)
router.include_router(rule_router)
router.include_router(species_router)
router.include_router(user_router)
Expand Down Expand Up @@ -83,7 +84,7 @@ async def read_service(request: Request, settings: SettingsDependency):
)
async def set_maintenance(
maintenance: Maintenance,
user: auth.Admin,
user: AdminDependency,
settings: SettingsDependency
):
settings.db.maintenance_mode = maintenance.mode
Expand All @@ -100,7 +101,7 @@ async def set_maintenance(
tags=['Service'],
summary="List settings.",
response_model=dict,
dependencies=[Depends(auth.get_current_admin_user)]
dependencies=[Depends(get_current_admin_user)]
)
async def read_settings(settings: SettingsDependency):
return settings.db.list()
Expand All @@ -111,7 +112,7 @@ async def read_settings(settings: SettingsDependency):
summary="Alter settings.",
tags=['Service'],
response_model=dict,
dependencies=[Depends(auth.get_current_admin_user)]
dependencies=[Depends(get_current_admin_user)]
)
async def patch_settings(settings: SettingsDependency, new_settings: dict):
for name, value in new_settings.items():
Expand Down
1 change: 0 additions & 1 deletion app/rule/difficulty/difficulty_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
summary="List difficulty codes.",
response_model=list[DifficultyCodeResponse]
)
# async def read_rules(token: auth.Auth):
async def read_codes(db: DbDependency, org_group_id: int):
repo = DifficultyCodeRepo(db)
codes = repo.list(org_group_id)
Expand Down
2 changes: 0 additions & 2 deletions app/rule/period/period_routes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

from fastapi import APIRouter

from app.auth import Auth
from app.database import DbDependency


from .period_models import PeriodRuleResponse, PeriodRuleResponseTvk
from .period_repo import PeriodRuleRepo

Expand Down
3 changes: 1 addition & 2 deletions app/species/cache.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from functools import lru_cache

from fastapi import APIRouter, HTTPException, status
from sqlmodel import SQLModel, Session, func, select, delete
from sqlmodel import Session, func, select, delete

from app.auth import Auth
from app.database import DbDependency
from app.sqlmodels import Taxon
import app.species.indicia as driver
Expand Down

0 comments on commit 758d1b1

Please sign in to comment.