Commit Graph

92 Commits

Author SHA1 Message Date
Matthieu B
4e6728c95f fix: prevent CASCADE data loss in LDAP migration and repair invitation_user
The LDAP migration (20251226) ran batch_alter_table on the invitation and
user tables with PRAGMA foreign_keys=ON. In SQLite, DROP TABLE with FKs
enabled triggers an implicit DELETE FROM that fires ON DELETE CASCADE,
silently wiping every row in invitation_user. This caused the "Latest
Accepted Invites" card to show blank after updating to v2026.3.0.

- Extend PRAGMA foreign_keys=OFF to cover all batch_alter_table operations
  in both upgrade() and downgrade()
- Add repair migration that repopulates invitation_user from
  invitation.used_by_id and user.code matching (same logic as the
  original 20250814 migration)

Closes #1207
2026-04-01 22:42:45 +02:00
Matthieu B
c57d29035e fix: clean up _alembic_tmp_ debris from prior failed migration runs
Previous failed batch_alter_table attempts leave behind
_alembic_tmp_admin_account in SQLite (no transactional DDL).
Subsequent retries fail trying to CREATE the same temp table.

Now drops any _alembic_tmp_* tables before batch operations, and
splits the admin_account alter into two paths depending on whether
prior columns already exist.
2026-03-29 17:48:46 +02:00
Matthieu B
7b316a4674 fix: make LDAP migration idempotent for crash recovery
The previous fix addressed the root cause (FK enforcement blocking
batch_alter_table), but users who already hit the bug have databases
with orphaned LDAP tables from the failed partial run. Since SQLite
has no transactional DDL, those tables persist despite the rollback.

Now the migration checks for existing tables/columns before creating
them, so it recovers cleanly regardless of database state.
2026-03-29 17:43:59 +02:00
Matthieu B
48848657db fix: disable FK enforcement during LDAP migration batch_alter_table
SQLite batch_alter_table recreates tables via DROP + CREATE. With
PRAGMA foreign_keys=ON (set by our connection handler), the DROP TABLE
admin_account fails because webauthn_credential and api_key reference
it. This caused a crash loop: tables created before the crash persisted
(no transactional DDL in SQLite), then re-running created duplicates.
2026-03-29 17:39:14 +02:00
Matthieu B
8817e0a3de fix: use batch_alter_table for SQLite-compatible column addition
SQLite rejects ALTER TABLE ADD COLUMN with non-constant defaults like
datetime('now'). Wrap in batch_alter_table which recreates the table.
2026-03-29 16:42:24 +02:00
Matthieu B
59e2cb8199 chore: merge main into ldap branch, resolve conflicts 2026-03-29 16:28:20 +02:00
Matthieu B
b642d9100b Merge pull request #1200 from wizarrrr/fix/1182-user-created-at
fix: add missing created_at column to User model
2026-03-29 16:25:40 +02:00
Matthieu B
73c29458fe fix: resolve all test failures, linting errors, and type errors
- Fix 55 test failures caused by missing request contexts and incorrect
  session_transaction() usage across 8 test files
- Fix ruff import sorting errors and unused imports
- Fix 122 type errors: rename method override parameters to match base
  classes, add None guards for fetchone()/datetime, widen dict type
  annotations, add type: ignore for SQLAlchemy stub limitations
- Add [tool.ty.rules] config to suppress unsupported-base warnings
- Fix _ variable shadowing gettext in wizard routes
- Add noqa: ARG002 for unused method arguments required by base class
2026-03-29 16:20:23 +02:00
Matthieu B
41ca8856f0 fix: add missing created_at column to User model (#1182)
Add created_at column to the User model, an Alembic migration to
backfill existing rows via server_default, and update the API
serialization and OpenAPI spec from the stale `created` field to
`created_at` so the joined/created date is no longer returned as null.
2026-03-29 16:11:05 +02:00
Matthieu B
498886c06a fix(ldap): address security, correctness, and code quality issues
Security:
- Fix XSS in HTMX responses by replacing f-string HTML with Jinja partials
- Fix TLS verify_cert not being applied (add Tls config to ldap3 Server)
- Fix password_hash NOT NULL conflict for LDAP-only admin accounts
- Fix should_create_ldap_user defaulting to True for existing invitations

Correctness:
- Fix DN reconstruction fragility using escape_rdn for special characters
- Fix connection leaks with try/finally in all LDAPClient methods
- Fix sync interval logic (check FLASK_ENV not WIZARR_ENABLE_SCHEDULER)
- Only register LDAP sync job when LDAP is actually configured
- Make find_user_dn and service_connection public API methods

Cleanup:
- Squash 5 incremental LDAP migrations into single 20251226_add_ldap_support
- Remove duplicate imports/queries in auth routes
- Replace f-string logging with %s formatting
- Extract inline HTML to Jinja template partials
2026-03-29 15:58:09 +02:00
Matthieu B
e992873e4d Merge origin/main into ldap branch
Resolve conflicts in auth/routes.py (incorporate media_server_url),
login.html (combine admin page text + LDAP error guard), and uv.lock.
2026-03-29 15:49:50 +02:00
Jacob Swanson
7f64f558dc Add Telegram notification support
Introduces Telegram as a notification agent, including backend logic, form fields, and database columns for bot token and chat ID. Updates creation and editing flows, notification service, and UI to support Telegram integration. Includes a migration to add the new fields to the Notification model.
2026-01-23 22:03:05 -06:00
Erwan Leboucher
5bb51e0cf1 feat(ldap): add LDAP authentication and invitation integration 2025-12-27 17:14:17 +01:00
Matthieu B
ac36e793e1 refactor: improve code formatting and readability across multiple files 2025-12-09 14:12:17 +01:00
Matthieu B
6758372bb3 fix: merge migrations 2025-12-09 14:08:42 +01:00
Matthieu B
0b2c90fee2 Merge pull request #1020 from 6im0n/feature/reset-password
Feat/Adds password reset functionality for Jellyfin user
2025-12-04 12:02:08 +00:00
Simon
b2cb69a8d5 feat: Add max_active_sessions column to Invitation model 2025-11-21 23:49:34 +01:00
Simon
42d286eee6 Fix: password reset token cascade delete 2025-11-21 01:38:43 +01:00
Simon
00f3ef95c3 feat: Implement link password reset functionality 2025-11-21 00:16:24 +01:00
Matthieu B
0b04a5f520 feat: improve user deletion process and fix foreign key constraints 2025-11-03 14:48:50 +01:00
Matthieu B
eca653b10b fix: kavita api errors closes #952 2025-10-27 15:04:24 +01:00
Matthieu B
6a3632ec66 refactor: update type hints for better clarity and consistency across multiple files 2025-10-23 19:49:58 +02:00
Matthieu B
42d4b56df1 Merge branch 'main' into plus 2025-10-18 16:07:43 +02:00
Matthieu B
8682d14e6b fix: Update migration revision ID and down_revision for activity audit features 2025-10-18 16:03:49 +02:00
Matthieu B
e2b54efe7b refactor: Remove obsolete migration files for activity identity links and historical import jobs 2025-10-18 16:02:02 +02:00
Matthieu B
92aad82fe1 Update migrations/versions/20251013_add_activity_identity_links.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-18 12:58:51 +02:00
Matthieu B
77a1112d62 feat: Add historical import job functionality
- Introduced the HistoricalImportJob model to track historical data import jobs.
- Implemented asynchronous job processing for importing historical activity data from media servers.
- Enhanced the activity settings page to allow users to specify the number of days back for historical imports.
- Added a new route to display recent historical import jobs.
- Updated the import_historical_activity function to create and manage import jobs.
- Improved UI components for displaying success and error messages related to historical imports.
- Added migration script to create the historical_import_job table in the database.
2025-10-17 13:14:37 +02:00
Matthieu B
8361144972 feat(activity): Enhance activity monitoring with historical data import and management features 2025-10-17 11:00:33 +02:00
engels74
0fb4767457 fix(migrations): reorder wizard category migration and apply pre-rebase formatting
Migration Changes:
- Renamed migration file from 20251004 to 20251005
- Updated down_revision from fd5a34530162 to 08a6c8fb44db
- Ensures migration runs after upstream notification events migration
- Fixes migration chain branching issue
- Removed incorrect merge migration (1e83c67d9785)

Migration chain is now:
fd5a34530162 (disabled attribute) → 08a6c8fb44db (notification events)
→ 20251005_add_category_to_wizard_step (wizard category)

Wizard Refactoring:
- Enhanced uniqueness constraint for WizardStep from (server_type, position)
  to (server_type, category, position)
- Ensures steps in different categories (pre_invite vs post_invite) can have
  the same position indexing without conflict
- Updated wizard state management documentation to explicitly list and
  describe data-* attributes used in steps.html template

Code Quality:
- Applied djlint formatting to 8 template files to minimize rebase conflicts
- Applied ruff format and ruff check --fix (no changes needed)
- Removed redundant requirement comments from spec-driven development
- Fixed case sensitivity in test assertion (POST vs post)
- Updated test references from 20251004 to 20251005 to match corrected
  migration revision ID
2025-10-16 16:57:14 +02:00
engels74
d0df4c6d5d feat: wizard step refactor into pre/post wizard steps
Changes:
  - Pre/post invitation wizard phases
  - Phase-aware routing (/pre-wizard/*, /post-wizard/*)
  - Phase indicator badges (visual categorization)
  - Dynamic completion button behavior
  - Two-column admin layout with category drag-and-drop
  - Invite code management service
  - Enhanced wizard export/import
  - Comprehensive test coverage (17 new test files)
2025-10-16 15:28:48 +02:00
Matthieu B
17e5b26703 Add identity links to activity sessions and drop ended_at column
- Added columns `wizarr_user_id` and `wizarr_identity_id` to the `activity_session` table.
- Created foreign key constraints for the new columns linking to `user` and `identity` tables.
- Created indexes for the new columns to improve query performance.
- Dropped the `ended_at` column from the `activity_session` table.
- Added a new `active` column to the `activity_session` table with a default value of true.
- Created an index for the `active` column to enhance query efficiency.
2025-10-15 12:52:06 +02:00
Matthieu B
7eae142e69 update migration 2025-10-13 14:26:25 +02:00
Matthieu B
a072bdf097 feat: add main side plus features 2025-10-09 12:12:02 +02:00
Matthieu B
b682967ed2 feat: add notification events handling and UI updates for user notifications 2025-10-04 14:46:01 +02:00
Matthieu B
f295a345a1 feat: add user disable functionality and update user management settings
- Introduced `is_disabled` attribute to the User model.
- Added `expiry_action` selection in the GeneralSettingsForm for user management.
- Implemented `disable_user` methods for various media clients (Audiobookshelf, Jellyfin, Kavita, etc.) to handle user disabling.
- Updated `check_expiring` task to process expired users based on the new settings.
- Enhanced user interface to reflect disabled status in user cards.
- Added migration for the new `is_disabled` column in the user table.
2025-09-27 12:19:48 +02:00
Matthieu B
2f1ee4ef70 fix: added missing admin column closes #842 2025-09-13 13:43:39 +02:00
Matthieu B
3310c2133c feat: revamp user policy handling 2025-09-12 14:11:51 +02:00
Matthieu B
95b72160da fix: remove conflicting allow_downloads and allow_live_tv columns from User model 2025-09-10 15:09:05 +02:00
Matthieu B
6f28f7dbb0 feat: UI speedup 2025-09-09 22:12:17 +02:00
Matthieu B
22d7e5dcc5 fix: resolve test failures and lint issues
- Fix test database isolation by cleaning WizardStep data before tests run
- Remove unused imports and fix import ordering
- Replace setattr with direct attribute assignment
- Use contextlib.suppress for cleaner exception handling
- Fix nested if statement in wizard_export_import.py

Fixes the failing CI checks for PR #817.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-07 15:58:42 +02:00
engels74
0f0dedde0a feat: implement wizard step interaction requirement system
Add comprehensive "require interaction" functionality for wizard steps that prevents users from proceeding until they engage with step content.

## Key Features:
- **Database Integration**: New `require_interaction` boolean field in WizardStep model with migration
- **Frontend Gating**: Robust JavaScript system that disables "Next" button until user clicks links/buttons in step content
- **UI Enhancement**: Improved checkbox forms with clear descriptions and visual indicators
- **Event Handling**: Advanced interaction detection with proper HTMX disabling and event capture
- **Admin Interface**: Full integration with wizard configuration forms (main and simple)
- **Export/Import**: Support for require_interaction field in wizard step data operations

## Technical Implementation:
- Disabled button state management with pointer-events and tabindex control
- HTMX attribute manipulation to prevent premature navigation
- Event listener capture phase handling for reliable interaction blocking
- Comprehensive test coverage for interaction scenarios
- Form validation and user experience improvements

## Files Modified:
- Backend: models, routes, forms, services, migration
- Frontend: JavaScript interaction logic, templates, UI components
- Testing: Complete test suite for interaction requirements

This feature ensures users engage with critical wizard content before proceeding, improving onboarding experience and preventing accidental step skipping.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-07 14:46:50 +02:00
Matthieu B
22d307d901 cleanup: remove unnecessary migration scripts and complexity
- Remove all migration helper scripts (over-engineering)
- Revert Docker entrypoint changes (not needed)
- Clean up CLAUDE.md migration strategy section
- Keep only the essential: beautifully renamed migration files

The simple solution won: just rename the files, Alembic doesn't care about filenames!

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-06 19:06:39 +02:00
Matthieu B
0cc94971b6 feat: complete migration chaos solution with full renaming
BREAKING CHANGE: Migration files renamed to clean YYYYMMDD format

- Renamed 17 migrations from chaotic hash-based to clean date-based names
- Maintained all revision IDs and dependency chains
- Updated Docker entrypoint to check/log migration mappings
- All tests pass, migration chain validated and healthy
- 28/30 migrations now follow YYYYMMDD_description.py format
- Added comprehensive migration management tooling

Changes:
- migrations/versions/*: 17 files renamed to YYYYMMDD format using real creation dates
- docker-entrypoint.sh: Added migration name checker before DB migrations
- Complete 4-phase renaming strategy implemented and executed

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-06 18:55:59 +02:00
Matthieu B
0757ca8fe0 fix: resolve remaining linting issues in migration scripts
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-06 18:54:05 +02:00
Matthieu B
8875cfb066 fix: fix allow download / live tv icons 2025-09-05 12:53:48 +02:00
Matthieu B
2dee2aa7af feat: add notes to users 2025-09-05 11:52:32 +02:00
Matthieu B
c11e5d5326 Enhance user display logic in invite and user modals to show usernames for multiple users and improve server type tagging in user cards 2025-08-14 15:53:25 +02:00
Matthieu B
2422cb1702 Add many-to-many relationship between invitations and users with tracking for invitation usage 2025-08-14 15:38:31 +02:00
Matthieu B
5f95b788b5 Add external integration fields to GeneralSettingsForm and update settings template 2025-08-13 21:33:39 +02:00
Matthieu B
1723e876b6 Refactor API models and invitation flow; add comprehensive tests
- Updated `InvitationCreateRequest` model to change `server_ids` from required to optional with improved description.
- Enhanced `library_model` to include `external_id`, `server_name`, and `enabled` fields.
- Modified `InvitationFlowManager` to prioritize new many-to-many relationship checks for invitations.
- Created a new migration file to merge branches related to API key and foreign key improvements.
- Added comprehensive tests for API endpoints, including status, users, invitations, libraries, servers, and API key management.
- Implemented error handling tests for malformed JSON and inactive API keys.
2025-08-13 20:58:11 +02:00