Commit graph

4,396 commits

Author SHA1 Message Date
Deluan
d344eba896 refactor: rename search_test.go to searching_test.go for consistency
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:58:46 -04:00
Deluan
72006fab4c refactor: remove unused library access functions and related tests
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:49:25 -04:00
Deluan
b9386ab41a fix: resolve LibrarySelectionField validation error for non-admin users
Fixed validation error 'At least one library must be selected for non-admin users' that appeared even when libraries were selected. The issue was caused by a data format mismatch between backend and frontend.

The backend sends user data with libraries as an array of objects, but the LibrarySelectionField component expects libraryIds as an array of IDs. Added data transformation in the data provider's getOne method to automatically convert libraries array to libraryIds format when fetching user records.

Also extracted validation logic into a separate userValidation module for better code organization and added comprehensive test coverage to prevent similar issues.
2025-07-16 18:10:15 -04:00
Deluan
cab5da7846 refactor: simplify artist repository library filtering
Removed conditional admin logic from applyLibraryFilterToArtistQuery method
and unified the library filtering approach to match the tag repository pattern.
The method now always uses the same SQL join structure regardless of user role,
with admin access handled automatically through user_library associations.

Added artistLibraryIdFilter function to properly qualify library_id column
references and prevent SQL ambiguity errors when multiple tables contain
library_id columns. This ensures the filter targets library_artist.library_id
specifically rather than causing ambiguous column name conflicts.
2025-07-16 18:10:15 -04:00
Deluan
295900e6f7 feat: add multi-library support to tag repository system
Implemented comprehensive library filtering for tag repositories to support the multi-library feature. This change ensures that users only see tags from libraries they have access to, while admin users can see all tags.

Key changes:
- Enhanced TagRepository.Add() method to accept libraryID parameter for proper library association
- Updated baseTagRepository to implement library-aware queries with proper joins
- Added library_tag table integration for per-library tag statistics
- Implemented user permission-based filtering through user_library associations
- Added comprehensive test coverage for library filtering scenarios
- Updated UI data provider to include tag filtering by selected libraries
- Modified scanner to pass library ID when adding tags during folder processing

The implementation maintains backward compatibility while providing proper isolation between libraries for tag-based operations like genres and other metadata tags.
2025-07-16 18:10:15 -04:00
Deluan
dd7ae6ce2b refactor: genre and tag repositories. add comprehensive tests
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
817a2c41dc feat: add multi-library support with per-library tag statistics - WIP
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
6316c3d137 feat: implement per-library artist statistics with automatic aggregation
Implemented comprehensive multi-library support for artist statistics that
automatically aggregates stats from user-accessible libraries. This fundamental
change moves artist statistics from global scope to per-library granularity
while maintaining backward compatibility and transparent operation.

Key changes include:
- Migrated artist statistics from global artist.stats to per-library library_artist.stats
- Added automatic library filtering and aggregation in existing Get/GetAll methods
- Updated role-based filtering to work with per-library statistics storage
- Enhanced statistics calculation to process and store stats per library
- Implemented user permission-aware aggregation that respects library access control
- Added comprehensive test coverage for library filtering and restricted user access
- Created helper functions to ensure proper library associations in tests

This enables users to see statistics that accurately reflect only the content
from libraries they have access to, providing proper multi-tenant behavior
while maintaining the existing API surface and UI functionality.

Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
f9afd889ea fix formating
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
775f5fa89c fix: improve cache buffering logic
Refactored the cache buffering logic to ensure thread safety when checking
the buffer length

Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
8a0017a186 fix: correct updated_at assignment in library repository
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
7fbf6c6382 feat: add default library assignment for new users
Introduced a new column `default_new_users` in the library table to
facilitate automatic assignment of default libraries to new regular users.
When a new user is created, they will now be assigned to libraries marked
as default, enhancing user experience by ensuring they have immediate access
to essential resources. Additionally, updated the user repository logic
to handle this new functionality and modified the user creation validation
to reflect that library selection is optional for non-admin users.

Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
0b2d728b21 feat: enhance library selection with master checkbox functionality
Added a master checkbox to the SelectLibraryInput component, allowing users to select or deselect all libraries at once. This improves user experience by simplifying the selection process when multiple libraries are available. Additionally, updated translations in the en.json file to include a new message for selecting all libraries, ensuring consistency in user interface messaging.

Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
cf676f2a08 chore: remove commented-out genre repository code from persistence tests 2025-07-16 18:10:15 -04:00
Deluan
fbde103499 feat: replace AddUserLibrary and RemoveUserLibrary with SetUserLibraries for better library management
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
dc264a64db feat: enhance library management with refresh event broadcasting
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
340192693e feat: add useRefreshOnEvents hook for custom refresh logic on event changes
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
202af6eab4 feat: add event broadcasting for library creation, update, and deletion
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
bcf7f14ed9 refactor: implement SendBroadcastMessage method for event broadcasting
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
d715f161ce fix: allow editing name of main library
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
493e7ff534 feat: refresh LibraryList on scan end
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
1aa48de4eb feat: add musicFolderId parameter support to Search2 and Search3 endpoints
Implemented musicFolderId parameter support for Subsonic API Search2 and Search3 endpoints, completing multi-library functionality across all Subsonic endpoints.

Key changes:
- Added musicFolderId parameter handling to Search2 and Search3 endpoints
- Updated search logic to filter results by specified library or all accessible libraries when parameter not provided
- Added proper error handling for invalid/inaccessible musicFolderId values
- Refactored SearchableRepository interface to support library filtering with variadic QueryOptions
- Updated repository implementations (Album, Artist, MediaFile) to handle library filtering in search operations
- Added comprehensive test coverage with robust assertions verifying library filtering works correctly
- Enhanced mock repositories to capture QueryOptions for test validation

Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
19e1830e9d fix: return error when any musicFolderId is invalid or inaccessible
Changed behavior from silently filtering invalid library IDs to returning
ErrorDataNotFound (code 70) when any provided musicFolderId parameter
is invalid or the user doesn't have access to it.

The error message includes the specific library number for better debugging.
This affects album/song list endpoints (getAlbumList, getRandomSongs,
getSongsByGenre, getStarred) to provide consistent error handling
across all Subsonic API endpoints.

Updated corresponding tests to expect errors instead of silent filtering.
2025-07-16 18:10:15 -04:00
Deluan
739856cda4 feat: enhance artist library filtering based on user permissions and optimize library ID retrieval
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
9eb89a9650 feat: implement library access filtering for artist queries based on user permissions
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
915f09a75c feat: add library access methods to User model
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
3f44e86299 fix: add ApplyArtistLibraryFilter to filter artists by associated music folders
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
b2fec7277b refactor: optimize starred items queries with parallel execution and fix test isolation
Refactored starred items functionality by extracting common logic into getStarredItems()
method that executes artist, album, and media file queries in parallel for better performance.
This eliminates code duplication between GetStarred and GetStarred2 methods while improving
response times through concurrent database queries using run.Parallel().

Also fixed test isolation issues by adding missing auth.Init(ds) call in album lists test setup.
This resolves nil pointer dereference errors in GetStarred and GetStarred2 tests when run independently.
2025-07-16 18:10:15 -04:00
Deluan
a93fa53ae7 feat: implement multi-library support for GetRandomSongs, GetSongsByGenre, GetStarred, and GetStarred2
- Added multi-library filtering to GetRandomSongs endpoint using musicFolderId parameter
- Added multi-library filtering to GetSongsByGenre endpoint using musicFolderId parameter
- Enhanced GetStarred and GetStarred2 to filter artists, albums, and songs by library
- Added Options field to MockMediaFileRepo and MockArtistRepo for test compatibility
- Added comprehensive Ginkgo/Gomega tests for all new multi-library functionality
- All tests verify proper SQL filter generation and library access validation
- Supports single/multiple musicFolderId values with fallback to all accessible libraries
2025-07-16 18:10:15 -04:00
Deluan
b9e7b7cad7 feat: implement multi-library support for GetAlbumList and GetAlbumList2 endpoints
- Enhanced selectedMusicFolderIds helper to validate and filter library IDs
- Added ApplyLibraryFilter function in filter/filters.go for library filtering
- Updated getAlbumList to support musicFolderId parameter filtering
- Added comprehensive tests for multi-library functionality
- Supports single and multiple musicFolderId values
- Falls back to all accessible libraries when no musicFolderId provided
- Validates library access permissions for user security
2025-07-16 18:10:15 -04:00
Deluan
bbc6d0722c feat: add library access validation to selectedMusicFolderIds
Enhanced the selectedMusicFolderIds function to validate musicFolderId parameters
against the user's accessible libraries. Invalid library IDs (those the user
doesn't have access to) are now silently filtered out, improving security by
preventing users from accessing libraries they don't have permission for.

Changes include:
- Added validation logic to check musicFolderId parameters against user's accessible libraries
- Added slices package import for efficient validation
- Enhanced function documentation to clarify validation behavior
- Added comprehensive test cases covering validation scenarios
- Maintains backward compatibility with existing behavior
2025-07-16 18:10:15 -04:00
Deluan
c5b7857fef refactor: change ArtistRepository.GetIndex to accept multiple library IDs
Updated the GetIndex method signature to accept a slice of library IDs instead of a single ID, enabling support for filtering artists across multiple libraries simultaneously.

Changes include:
- Modified ArtistRepository interface in model/artist.go
- Updated implementation in persistence/artist_repository.go with improved library filtering logic
- Refactored Subsonic API browsing.go to use new selectedMusicFolderIds helper
- Added comprehensive test coverage for multiple library scenarios
- Updated mock repository implementation for testing

This change improves flexibility for multi-library operations while maintaining backward compatibility through the selectedMusicFolderIds helper function.
2025-07-16 18:10:15 -04:00
Deluan
64159d715a feat: enhance selectedMusicFolderIds function to handle valid music folder IDs and improve fallback logic
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
ad0c9ae153 refactor: simplify getUserAccessibleLibraries function and update related tests
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
6125a090ef fix: ensure LibrarySelector dropdown refreshes on button close
Added refresh() call when closing the dropdown via button click to maintain
consistency with the ClickAwayListener behavior. This ensures the UI
updates properly regardless of how the dropdown is closed, fixing an
inconsistent refresh behavior between different closing methods.

The fix tracks the previous open state and calls refresh() only when
the dropdown was open and is being closed by the button click.
2025-07-16 18:10:15 -04:00
Deluan
a3281ca027 feat(subsonic): update GetIndexes and GetArtists method to support library ID filtering
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
0b61df1b90 feat(library): enhance LibrarySelectionField to extract library IDs from record
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
c1365cd236 feat(subsonic): implement user-specific library access in GetMusicFolders
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
5d926538d7 Add library_id field support for smart playlists
- Add library_id field to smart playlist criteria system
- Supports Is and IsNot operators for filtering by library ID
- Includes comprehensive test coverage for single values and lists
- Enables creation of library-specific smart playlists
2025-07-16 18:10:15 -04:00
Deluan
4b107b213c feat(artist): add library ID filtering for artists in repository and update resource filtering logic
Signed-off-by: Deluan <deluan@navidrome.org>

# Conflicts:
#	persistence/artist_repository.go
2025-07-16 18:10:15 -04:00
Deluan
5ecad64a3f feat(library): add refresh functionality on LibrarySelector close
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
2f9a9cf4fb fix(repository): add table name handling in filter functions for SQL queries
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
93059204f3 feat(library): streamline library ID filtering in repositories and update resource filtering logic
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
d44292cdc7 feat(library): add library ID filtering for album resources
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
ac31ea640f test: add unit tests for file utility functions
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:15 -04:00
Deluan
17bb39c472 feat(library): add tests for LibrarySelector and library selection hooks
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:14 -04:00
Deluan
1713396da2 feat(library): implement library selection functionality with reducer and UI component
Signed-off-by: Deluan <deluan@navidrome.org>

# Conflicts:
#	.github/copilot-instructions.md

# Conflicts:
#	.gitignore
2025-07-16 18:10:14 -04:00
Deluan
db167f56b9 feat(user): add library selection for user creation and editing
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:14 -04:00
Deluan
e9d6a8eccf feat(repository): apply library filtering in CountAll methods for albums, folders, and media files
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:14 -04:00
Deluan
f9fc3cd1c6 prepend libraryID for track and album PIDs
Signed-off-by: Deluan <deluan@navidrome.org>
2025-07-16 18:10:14 -04:00