fix: resolve failing tests in main
- fix(api/dropbox): _require_admin bypasses auth when AUTH_ENABLED=False, fixing all 5 TestSaveDropboxSettings failures - fix(api/onedrive): same AUTH_ENABLED bypass in _require_admin; fix one-arg update_env_file call using env_utils version for token rotation - fix(auth): update login TemplateResponse to Starlette 1.0+ API (request as first arg instead of in context dict) - fix(api/local_auth): update all TemplateResponse calls to Starlette 1.0+ API - fix(views/share): update TemplateResponse call to Starlette 1.0+ API - fix(api/billing): update TemplateResponse call to Starlette 1.0+ API - fix(tests/test_imap_tasks): mock is_private_ip for tests using imap.example.com (unresolvable in sandboxed/CI environments) - fix(tests): update TemplateResponse call_args assertions to new API (call_args.kwargs['context'] instead of call_args[0][1]) - fix(tests): update fake_original signatures in dark_mode tests Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> Agent-Logs-Url: https://github.com/christianlouis/DocuElevate/sessions/52d7b7b7-3a71-4a96-b2b1-b675b8a6d3b4
This commit is contained in:
+10
-3
@@ -11,9 +11,10 @@ import httpx
|
||||
from fastapi import APIRouter, Depends, Form, HTTPException, Request, status
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.auth import require_login
|
||||
from app.auth import AUTH_ENABLED, require_login
|
||||
from app.config import settings
|
||||
from app.database import get_db
|
||||
from app.utils.env_utils import update_env_file as _update_env_file_auto
|
||||
from app.utils.oauth_helper import exchange_oauth_token
|
||||
from app.utils.settings_service import save_setting_to_db, update_env_file
|
||||
from app.utils.settings_sync import notify_settings_updated
|
||||
@@ -25,7 +26,13 @@ router = APIRouter()
|
||||
|
||||
|
||||
def _require_admin(request: Request) -> dict:
|
||||
"""Dependency to ensure the current user is an admin."""
|
||||
"""Dependency to ensure the current user is an admin.
|
||||
|
||||
When AUTH_ENABLED=False (single-user/development mode), admin checks are
|
||||
skipped because there is no authentication at all.
|
||||
"""
|
||||
if not AUTH_ENABLED:
|
||||
return {}
|
||||
user = request.session.get("user")
|
||||
if not user or not user.get("is_admin"):
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Admin access required")
|
||||
@@ -127,7 +134,7 @@ async def test_onedrive_token(request: Request):
|
||||
settings.onedrive_refresh_token = new_refresh_token
|
||||
|
||||
# Also try to update .env file if it exists
|
||||
update_env_file({"ONEDRIVE_REFRESH_TOKEN": new_refresh_token})
|
||||
_update_env_file_auto({"ONEDRIVE_REFRESH_TOKEN": new_refresh_token})
|
||||
|
||||
# Persist the rotated refresh token to the database
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user