Skip to content

Commit

Permalink
Use get_user_db dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Sep 20, 2021
1 parent dd1a176 commit ed6cb26
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions plugins/auth/fps_auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def current_user(optional: bool = False):
async def _(
auth_config=Depends(get_auth_config),
user: User = Depends(users.current_user(optional=True)),
user_db=Depends(get_user_db),
):
if auth_config.mode == "noauth":
return await user_db.get_by_email(noauth_email)
Expand Down
5 changes: 4 additions & 1 deletion plugins/jupyterlab/fps_jupyterlab/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from starlette.requests import Request # type: ignore
from fps.hooks import register_router # type: ignore

from fps_auth.db import get_user_db # type: ignore
from fps_auth.routes import ( # type: ignore
current_user,
user_db,
cookie_authentication,
LoginCookieAuthentication,
)
Expand Down Expand Up @@ -74,6 +74,7 @@ async def get_root(
token: Optional[UUID4] = None,
auth_config=Depends(get_auth_config),
jlab_config=Depends(get_jlab_config),
user_db=Depends(get_user_db),
):
if token and auth_config.mode == "token":
user = await user_db.get(token)
Expand Down Expand Up @@ -138,6 +139,7 @@ async def get_workspace_data(user: User = Depends(current_user(optional=True))):
async def set_workspace(
request: Request,
user: User = Depends(current_user()),
user_db=Depends(get_user_db),
):
user.workspace = await request.body()
await user_db.update(user)
Expand Down Expand Up @@ -245,6 +247,7 @@ async def change_setting(
name0,
name1,
user: User = Depends(current_user()),
user_db=Depends(get_user_db),
):
settings = json.loads(user.settings)
settings[f"{name0}:{name1}"] = await request.json()
Expand Down
8 changes: 6 additions & 2 deletions plugins/kernels/fps_kernels/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from fps_auth.routes import cookie_authentication, current_user # type: ignore
from fps_auth.models import User # type: ignore
from fps_auth.db import user_db # type: ignore
from fps_auth.db import get_user_db # type: ignore
from fps_auth.config import get_auth_config # type: ignore

from .kernel_server.server import KernelServer # type: ignore
Expand Down Expand Up @@ -167,7 +167,11 @@ async def restart_kernel(

@router.websocket("/api/kernels/{kernel_id}/channels")
async def kernel_channels(
websocket: WebSocket, kernel_id, session_id, auth_config=Depends(get_auth_config)
websocket: WebSocket,
kernel_id,
session_id,
auth_config=Depends(get_auth_config),
user_db=Depends(get_user_db),
):
accept_websocket = False
if auth_config.mode == "noauth":
Expand Down
7 changes: 5 additions & 2 deletions plugins/terminals/fps_terminals/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from fps_auth.routes import cookie_authentication, current_user # type: ignore
from fps_auth.models import User # type: ignore
from fps_auth.db import user_db # type: ignore
from fps_auth.db import get_user_db # type: ignore
from fps_auth.config import get_auth_config # type: ignore

from .models import Terminal
Expand Down Expand Up @@ -51,7 +51,10 @@ async def delete_terminal(

@router.websocket("/terminals/websocket/{name}")
async def terminal_websocket(
websocket: WebSocket, name, auth_config=Depends(get_auth_config)
websocket: WebSocket,
name,
auth_config=Depends(get_auth_config),
user_db=Depends(get_user_db),
):
accept_websocket = False
if auth_config.mode == "noauth":
Expand Down
8 changes: 6 additions & 2 deletions plugins/yjs/fps_yjs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import fastapi

from fps_auth.routes import cookie_authentication # type: ignore
from fps_auth.db import user_db # type: ignore
from fps_auth.db import get_user_db # type: ignore
from fps_auth.config import get_auth_config # type: ignore

router = APIRouter()
Expand All @@ -25,7 +25,11 @@ def get_path_param_names(path: str) -> Set[str]:

@router.websocket("/api/yjs/{type}:{path:path}")
async def websocket_endpoint(
websocket: WebSocket, type, path, auth_config=Depends(get_auth_config)
websocket: WebSocket,
type,
path,
auth_config=Depends(get_auth_config),
user_db=Depends(get_user_db),
):
accept_websocket = False
if auth_config.mode == "noauth":
Expand Down

0 comments on commit ed6cb26

Please sign in to comment.