Commit Graph

273 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] 862ba99802 fix(settings): rollback restores old_value instead of new_value and supports deletion fallback
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 12:15:44 +00:00
copilot-swe-agent[bot] 96fd0b8dd5 feat(settings): patch API in-memory settings on save and add Back to ENV button
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 11:42:37 +00:00
copilot-swe-agent[bot] ec7a35e747 fix(settings): fix route ordering and settings page display of DB values
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 11:39:13 +00:00
copilot-swe-agent[bot] 0188575c27 fix: isolate token_hex mock to wizard module and fix mypy annotation
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 10:01:07 +00:00
github-actions[bot] 540541eec6 style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-23 09:33:48 +00:00
copilot-swe-agent[bot] ecc8100e24 feat(settings): persist storage provider settings to DB, add export endpoint, enrich setup wizard
- dropbox/google_drive/onedrive save-settings: switch to DB as primary,
  .env write as best-effort (no longer fails when .env is absent)
- onedrive/google_drive update-settings: persist changes to DB alongside
  in-memory update; call notify_settings_updated()
- onedrive test_onedrive_token: persist rotated refresh token to DB
- settings_service: add get_settings_for_export() (db / effective modes)
- settings API: add GET /api/settings/export-env (admin-only, downloads .env)
- wizard: enrich settings with current values (DB > ENV > default) and
  value_source badges; pass setup_skipped to template; call
  notify_settings_updated() on save; add /setup/undo-skip route
- setup_wizard.html: pre-populate inputs with current_value; show
  DB/ENV/DEFAULT source badges; skip/undo-skip messaging
- settings.html: replace single Audit Log button with Setup Wizard link,
  Export .env dropdown, and Audit Log button group

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-23 02:41:04 +00:00
copilot-swe-agent[bot] 0d5c20f685 chore: outline plan for wizard DB persistence, worker sync, and ENV exporter
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 02:30:56 +00:00
copilot-swe-agent[bot] 90e5e0037c feat(settings): per-option save, live worker sync, audit log, and rollback
A) Per-option Save Button
- Add per-setting Save button in settings.html (visible only when value changed)
- Button calls POST /api/settings/{key} directly; existing bulk Save retained
- Add Audit Log link in settings page header

B) Immediate Worker Sync
- New app/utils/settings_sync.py with notify_settings_updated() (Redis version key)
  and register_settings_reload_signal() (Celery task_prerun handler)
- Register signal in celery_worker.py at startup
- All API write paths call notify_settings_updated() after successful saves

C) Audit Log
- Add SettingsAuditLog model (key, old_value, new_value, changed_by, changed_at, action)
- save_setting_to_db / delete_setting_from_db accept changed_by and write audit entries
- New get_audit_log() service function (masks sensitive values)
- New GET /api/settings/audit-log endpoint (admin-only)
- New GET /admin/settings/audit-log view + audit_log.html template
- Visible to all admins (per clarified requirement)

D) Config Rollback / History
- New get_setting_history() and rollback_setting() service functions
- New GET /api/settings/{key}/history endpoint
- New POST /api/settings/{key}/rollback/{history_id} endpoint
- Rollback buttons in audit_log.html with confirmation dialog
- Tests: 25 new tests covering audit log, rollback, worker sync helpers, and API endpoints

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-23 02:28:08 +00:00
copilot-swe-agent[bot] e632e0333f fix(api): return 200 with value=None for unknown setting keys in GET endpoint
`GET /api/settings/{key}` was calling `validate_setting_key()` which raises
HTTP 404 for keys not in SETTING_METADATA. The test expects 200 with value=None
for unknown keys.

Added `validate_setting_key_format()` to `input_validation.py` that validates
only the key format without the SETTING_METADATA existence check. Updated
`get_setting` to use the format-only validator; POST/DELETE endpoints continue
using the full `validate_setting_key()` for write-side security.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 20:04:57 +00:00
Christian Krakau-Louis d870dd9fa7 Merge pull request #350 from christianlouis/copilot/implement-api-key-rotation
feat: API key rotation mechanisms — audit endpoint, rotation guide, and admin UI
2026-02-22 20:44:01 +01:00
github-actions[bot] 6cea3a370c style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 19:43:15 +00:00
copilot-swe-agent[bot] 3fa24c0686 feat(ui): add Credential Audit page under Admin menu
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 19:39:01 +00:00
copilot-swe-agent[bot] 1648d8c745 feat(api): configure CORS middleware for API endpoints
- Add CORSMiddleware (disabled by default, enabled via CORS_ENABLED=true)
- Add cors_enabled, cors_allowed_origins, cors_allow_credentials,
  cors_allowed_methods, cors_allowed_headers settings to config.py
- Add parse_comma_separated_list validator for CORS list env vars
- Insert CORS middleware between SessionMiddleware and ProxyHeaders
  so preflight runs before CSRF/auth but after proxy-header processing
- Document CORS env vars in .env.demo with rationale for proxy-first approach
- Mark CORS TODO as completed in SECURITY_AUDIT.md
- Add tests/test_cors.py with 12 unit and integration tests

Closes #175

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 19:26:39 +00:00
copilot-swe-agent[bot] a46cd6634b feat(api): implement API key rotation mechanisms (#168)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 19:24:38 +00:00
github-actions[bot] fde4199f5a style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 16:32:30 +00:00
copilot-swe-agent[bot] c54cbcbdd6 feat(auth): implement CSRF token protection for state-changing operations
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 16:27:37 +00:00
copilot-swe-agent[bot] 3035802c16 feat(security): add comprehensive input validation and sanitization (#172)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 16:02:00 +00:00
github-actions[bot] 77e777418c style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 15:25:48 +00:00
copilot-swe-agent[bot] ca27a0b687 feat(security): add request size limits to API endpoints
- Add RequestSizeLimitMiddleware that checks Content-Length header
  before request body is read: non-multipart requests capped at
  MAX_REQUEST_BODY_SIZE (default 1 MB), multipart uploads capped at
  MAX_UPLOAD_SIZE (default 1 GB). Returns HTTP 413 on violation.
- Register middleware in app/main.py
- Add max_request_body_size setting to app/config.py
- Fix ui_upload in files.py to check Content-Length early and read
  in 64 KB chunks (bounded memory usage), removing the post-write
  os.path.getsize check
- Document MAX_REQUEST_BODY_SIZE in .env.demo and ConfigurationGuide.md
- Mark SECURITY_AUDIT.md item #4 as resolved
- Add 9 tests in test_request_size_limit.py
- Update test_upload_file_too_large to use patch.object instead of
  the now-unused os.path.getsize mock

Closes #173

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 14:41:04 +00:00
github-actions[bot] bdf0afd9bf style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 14:24:27 +00:00
copilot-swe-agent[bot] ca6a3beb3f feat(security): add request/audit logging with sensitive data masking (#170)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-21 21:21:29 +00:00
copilot-swe-agent[bot] 895585c1e8 fix(ci): lint errors, remove webhook deploy, add ArgoCD GitOps k8s manifest update
- Fix ruff format: add blank line before nested function in app/views/filemanager.py
- Fix ruff format: use double-quote escaping in tests/test_config.py
- Remove deploy job (Portainer webhook) from ci.yml
- Add update-k8s-manifest job: after main-branch build, updates
  apps/docuelevate/preprod/docuelevate-stack.yaml in christianlouis/k8s-cluster-state
  with the new GHCR image tag (ghcr.io/christianlouis/docuelevate:main-<short-sha>)
  using mikefarah/yq@v4.44.6 and GH_PAT secret for cross-repo write access

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-21 09:40:52 +00:00
copilot-swe-agent[bot] 48443dc30a fix(config): strip outer quotes from env var string values (Kubernetes compatibility)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-21 09:23:39 +00:00
copilot-swe-agent[bot] 54736ea35a feat(admin): enhance file manager with DB reconciliation view (filesystem/database/reconcile tabs)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-21 09:20:59 +00:00
copilot-swe-agent[bot] 16e7b6478e feat(admin): add admin-only file manager, admin menu, de-emphasize status, improve dashboard
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-21 09:15:27 +00:00
copilot-swe-agent[bot] 886bcd3c9b fix: include exc_info in log_task_progress debug message
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-17 11:41:56 +00:00
copilot-swe-agent[bot] 13a3c41482 fix: make log_task_progress resilient to DB errors and fix test assertions
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-17 11:40:34 +00:00
copilot-swe-agent[bot] f2eff3e2fb fix: return boolean values from _should_upload functions and fix test expectations
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-16 16:59:17 +00:00
copilot-swe-agent[bot] d3b3575f8a style: fix import ordering in database.py
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-14 00:32:02 +00:00
copilot-swe-agent[bot] 53a9efa56d feat: add strict mypy type-checking for app/utils/ module
- Add [[tool.mypy.overrides]] section for app/utils/** with disallow_untyped_defs=true
- Add type annotations to all functions in app/utils/ (12 files)
- Fix type annotations in app/config.py and app/database.py (imported by utils)
- All 85 source files now pass mypy type checking

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-14 00:27:52 +00:00
copilot-swe-agent[bot] fc4f5631ee test: increase coverage for imap_tasks.py and fix config_validator.py
- Add comprehensive tests for imap_tasks.py covering:
  - Lock acquire/release mechanisms
  - pull_all_inboxes task with various scenarios
  - pull_inbox for Gmail and non-Gmail with edge cases
  - find_all_mail_xlist functionality
  - Extended fetch_attachments tests for all MIME types
  - Edge cases: invalid JSON, missing Message-ID, already processed, etc.
- Achieve 98.26% coverage for imap_tasks.py (up from 48.78%)

- Fix config_validator.py to include validate_auth_config export
- Update tests to verify all exports including validate_auth_config
- Note: config_validator.py file is shadowed by config_validator/ directory
  in Python's module resolution, so it cannot be directly imported or tested.
  The package's __init__.py (which has 100% coverage) is what's actually used.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 23:42:49 +00:00
copilot-swe-agent[bot] e6a4995a5c style: run ruff format on 6 files to fix formatting issues
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 22:39:34 +00:00
copilot-swe-agent[bot] c129badc14 feat(api): add enhanced logging and original_file_path fallback to retry-subtask endpoint
- Add comprehensive logging to all pipeline retry branches (process_document, process_with_azure_document_intelligence, extract_metadata_with_gpt, embed_metadata_into_pdf)
- Add original_file_path as 3rd fallback for embed_metadata_into_pdf (checks: local_filename, processed_file_path, original_file_path, workdir/tmp fallback)
- Include all checked paths with existence status in 400 error responses for easier debugging
- Add enhanced logging to upload task retry path showing which processed file paths were checked
- Log successful file path when found
- Add comprehensive test suite covering new logging and fallback behavior

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 22:15:18 +00:00
copilot-swe-agent[bot] bcf5f652fc style: fix linting issues in retry and metadata extraction code
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 21:07:23 +00:00
copilot-swe-agent[bot] 42d35c7c6f fix: handle file in processed directory when retrying embed_metadata_into_pdf
- Update _retry_pipeline_step to check for file in tmp, processed, and fallback locations
- Pass full path to extract_metadata_with_gpt instead of just basename
- Update extract_metadata_with_gpt to handle both basename and full path parameters
- Add test case for retrying when file is in processed directory

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 21:06:20 +00:00
copilot-swe-agent[bot] defcf746ea fix: serialize dict to JSON in rotate_pdf_pages log_task_progress calls
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 20:54:34 +00:00
copilot-swe-agent[bot] 0edc51d17f fix: expose helper functions at module level for test patching
- Move get_all_settings_from_db import to module level in app/views/settings.py
- Move get_provider_status and get_settings_for_display imports to module level in app/views/status.py
- Fix CI workflow: replace deprecated 'file' parameter with 'files' in codecov-action
- Fix CI workflow: update test results upload to use codecov-action@v5 with report_type instead of deprecated test-results-action@v1

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 17:24:22 +00:00
copilot-swe-agent[bot] aa077f2b6c fix: track TLS usage with variable instead of isinstance check
Replace isinstance(ftp, ftplib.FTP_TLS) with a boolean flag to avoid issues when FTP_TLS is mocked in tests. Also fix Google Drive test parameter passing.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 16:20:32 +00:00
copilot-swe-agent[bot] b42c6f5f64 fix: resolve all Ruff linting errors
- Fix PLW2901: Use different variable name for stripped lines in loop
- Fix E721: Use 'is' instead of '==' for type comparisons
- Add noqa comments for intentional security warnings (S321, S507, S110, S603)

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 16:12:39 +00:00
copilot-swe-agent[bot] 4897cb6655 fix: apply Phase 1-2 correctness and constant extraction from PR #273
- Replace datetime.utcnow() with datetime.now(timezone.utc) in 4 files
- Extract duplicate literals to constants in 5 files
  - models.py: "files.id" → _FILES_ID_FK
  - upload_to_email.py: "logo.png" → _LOGO_FILENAME
  - general.py: "%B %d, %Y" → _DATE_DISPLAY_FORMAT
  - files.py: "File not found" → _FILE_NOT_FOUND
  - upload_to_google_drive.py: Google token URL → _GOOGLE_TOKEN_URL

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 11:25:30 +00:00
copilot-swe-agent[bot] b03ebab747 chore: apply ruff formatting and fix whitespace issues
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 09:12:11 +00:00
copilot-swe-agent[bot] 43bc58770d refactor: consolidate linting tools into Ruff
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 09:10:52 +00:00
copilot-swe-agent[bot] dff32e08e1 test: add comprehensive tests for critical untested files and fix deprecated warnings
- Add tests for migrate_logs_to_steps.py, upload_to_paperless.py, dropbox API,
  upload_to_dropbox.py, upload_to_nextcloud.py, upload_to_onedrive.py,
  upload_with_rclone.py, and config_validator.py
- Fix PydanticDeprecatedSince20: @validator → @field_validator in config.py, url_upload.py
- Fix PydanticDeprecatedSince20: class Config → model_config = SettingsConfigDict
- Fix PydanticDeprecatedSince211: filter Pydantic internals in settings_display.py
- Fix MovedIn20Warning: use sqlalchemy.orm.declarative_base instead of ext.declarative

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-12 17:32:17 +00:00
copilot-swe-agent[bot] c67974d350 fix: apply Black formatting to app/auth.py
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-12 14:22:25 +00:00
copilot-swe-agent[bot] 459e9fafc7 fix(test): fix OAuth integration tests and auth redirect status code
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-12 13:17:26 +00:00
copilot-swe-agent[bot] 604facf36f fix(test): fix task __wrapped__ calls, auth imports, mock chains, async markers, and rate limit mock
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-12 13:03:26 +00:00
copilot-swe-agent[bot] ff9a3ff49f style: fix code formatting with black, isort, and flake8
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-12 03:21:41 +00:00
copilot-swe-agent[bot] cc98039246 fix(deps): upgrade PyPDF2 to pypdf >= 3.9.0 to fix CVE-2023-36464
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-12 02:52:17 +00:00
Christian Krakau-Louis 9a2c2d20b1 feat(duplication): implement duplicate file handling and detection across processing steps 2026-02-12 02:38:00 +01:00
Christian Krakau-Louis 70757e5644 feat(step-timeout): add automatic recovery for stalled processing steps
- Implement step timeout detection to prevent files from getting stuck in 'pending' state
- Add monitor_stalled_steps periodic task running every minute (Celery Beat)
- Automatically mark in-progress steps as failed if they exceed timeout (default: 10 minutes)
- Add step_timeout configuration setting (default: 600 seconds)
- Recover stalled steps with error message indicating when timeout was triggered
- Fix duplicate check to exclude self-comparison (file not duplicate of itself)

When processing crashes or hangs:
1. Worker detects stalled steps (in_progress for >10 minutes)
2. Marks them as failed with timeout error message
3. Updates UI to show failure status
4. Allows file to be retried or handled by user

This prevents files from being indefinitely stuck in processing state and provides
visibility into what went wrong.
2026-02-12 02:38:00 +01:00