style: fix all flake8 linter errors across app/ directory

- Run Black formatter and isort on all app/ files
- Remove unused imports (F401) across multiple files
- Add # noqa: F401 for intentional re-exports in celery_worker.py,
  tasks/__init__.py, utils.py, frontend.py, views/base.py
- Fix f-strings without placeholders (F541) in azure.py, notification.py,
  check_credentials.py, upload_to_onedrive.py, settings.py
- Fix bare except (E722) in upload_to_sftp.py
- Fix block comment format (E265) in models.py
- Move imports to top of file to fix E402 in celery_app.py, celery_worker.py
- Fix line-too-long (E501) by wrapping strings in multiple files
- Remove unused variable (F841) in upload_to_nextcloud.py

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-08 17:42:33 +00:00
parent 7827b97e06
commit d08040ac4a
73 changed files with 2200 additions and 2185 deletions
+33 -35
View File
@@ -2,17 +2,18 @@
Settings management views for the application.
"""
import os
import logging
import inspect
import logging
import os
from functools import wraps
from fastapi import Request, Depends, HTTPException, status
from fastapi import Depends, HTTPException, Request, status
from fastapi.responses import RedirectResponse
from sqlalchemy.orm import Session
from app.views.base import APIRouter, templates, require_login, settings, get_db
from app.utils.settings_service import get_settings_by_category, get_setting_metadata, SETTING_METADATA
from app.utils.config_validator.masking import mask_sensitive_value
from app.utils.settings_service import get_setting_metadata, get_settings_by_category
from app.views.base import APIRouter, get_db, require_login, settings, templates
logger = logging.getLogger(__name__)
router = APIRouter()
@@ -21,23 +22,25 @@ router = APIRouter()
def require_admin_access(func):
"""
Decorator to require admin access for a route.
This decorator checks if the user in the session has admin privileges.
If not, redirects to the home page. Works with both sync and async functions,
though FastAPI route handlers should always be async.
"""
@wraps(func)
async def wrapper(request: Request, *args, **kwargs):
user = request.session.get("user")
if not user or not user.get("is_admin"):
logger.warning(f"Non-admin user attempted to access admin-only route")
logger.warning("Non-admin user attempted to access admin-only route")
return RedirectResponse(url="/", status_code=status.HTTP_302_FOUND)
# FastAPI route handlers are async, but we support sync for flexibility
if inspect.iscoroutinefunction(func):
return await func(request, *args, **kwargs)
else:
return func(request, *args, **kwargs)
return wrapper
@@ -47,19 +50,20 @@ def require_admin_access(func):
async def settings_page(request: Request, db: Session = Depends(get_db)):
"""
Settings management page - admin only.
This page is a convenience feature to view and edit settings.
Values are displayed in precedence order: Database > Environment > Defaults
"""
try:
# Get settings from database
from app.utils.settings_service import get_all_settings_from_db
db_settings = get_all_settings_from_db(db)
# Get settings organized by category
categories = get_settings_by_category()
# Build settings data for display
settings_data = {}
for category, keys in categories.items():
@@ -67,7 +71,7 @@ async def settings_page(request: Request, db: Session = Depends(get_db)):
for key in keys:
# Get current value from settings (already has precedence applied)
value = getattr(settings, key, None)
# Determine the source of this setting
# Check if it's in the database
if key in db_settings:
@@ -84,35 +88,29 @@ async def settings_page(request: Request, db: Session = Depends(get_db)):
source = "default"
source_label = "DEFAULT"
source_color = "gray"
# Get metadata
metadata = get_setting_metadata(key)
# Mask sensitive values
display_value = value
if metadata.get("sensitive") and value:
display_value = mask_sensitive_value(value)
settings_data[category].append({
"key": key,
"display_value": display_value if display_value is not None else "",
"metadata": metadata,
"source": source,
"source_label": source_label,
"source_color": source_color
})
settings_data[category].append(
{
"key": key,
"display_value": display_value if display_value is not None else "",
"metadata": metadata,
"source": source,
"source_label": source_label,
"source_color": source_color,
}
)
return templates.TemplateResponse(
"settings.html",
{
"request": request,
"settings_data": settings_data,
"app_version": settings.version
}
"settings.html", {"request": request, "settings_data": settings_data, "app_version": settings.version}
)
except Exception as e:
logger.error(f"Error loading settings page: {e}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Failed to load settings page"
)
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to load settings page")