Compare commits

...

7 Commits

Author SHA1 Message Date
dependabot[bot]
813b359575
Merge 08a5d6447745284b4abe1a76f3ac223047190779 into 32e1313fc6ddf7100af094d14df13d47735a44bf 2025-11-17 09:33:24 -08:00
Kendall Garner
32e1313fc6
ci: bump plugin compilation timeout for regressions (#4690) 2025-11-16 13:46:32 -05:00
Deluan
489d5c7760 test: update make test-race target to use PKG variable for improved flexibility
Signed-off-by: Deluan <deluan@navidrome.org>
2025-11-16 13:41:22 -05:00
Kendall Garner
0f1ede2581
fix(scanner): specify exact table to use for missing mediafile filter (#4689)
In `getAffectedAlbumIDs`, when one or more IDs is added, it adds a filter `"id": ids`.
This filter is ambiguous though, because the `getAll` query joins with library table, which _also_ has an `id` field.
Clarify this by adding the table name to the filter.

Note that this was not caught in testing, as it only uses mock db.
2025-11-16 12:54:28 -05:00
Deluan Quintão
395a36e10f
fix(ui): fix library selection state for single-library users (#4686)
* fix: validate library selection state for single-library users

Fixes issues where users with a single library see no content when
selectedLibraries in localStorage contains library IDs they no longer
have access to (e.g., after removing libraries or switching accounts).

Changes:
- libraryReducer: Validate selectedLibraries when SET_USER_LIBRARIES
  is dispatched, filtering out invalid IDs and resetting to empty for
  single-library users (empty means 'all accessible libraries')
- wrapperDataProvider: Add defensive validation in getSelectedLibraries
  to check against current user libraries before applying filters
- Add comprehensive test coverage for reducer validation logic

Fixes #4553, #4508, #4569

* style: format code with prettier
2025-11-15 17:42:28 -05:00
Deluan
0161a0958c fix(ui): add CreateButton back to LibraryListActions
Signed-off-by: Deluan <deluan@navidrome.org>
2025-11-15 17:31:37 -05:00
dependabot[bot]
08a5d64477
chore(deps-dev): bump typescript from 5.8.3 to 5.9.3 in /ui
Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.8.3 to 5.9.3.
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release-publish.yml)
- [Commits](https://github.com/microsoft/TypeScript/compare/v5.8.3...v5.9.3)

---
updated-dependencies:
- dependency-name: typescript
  dependency-version: 5.9.3
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-03 17:42:57 +00:00
9 changed files with 244 additions and 17 deletions

View File

@ -54,7 +54,7 @@ testall: test-race test-i18n test-js ##@Development Run Go and JS tests
.PHONY: testall
test-race: ##@Development Run Go tests with race detector
go test -tags netgo -race -shuffle=on ./...
go test -tags netgo -race -shuffle=on $(PKG)
.PHONY: test-race
test-js: ##@Development Run JS tests

View File

@ -166,7 +166,7 @@ func (s *maintenanceService) getAffectedAlbumIDs(ctx context.Context, ids []stri
if len(ids) > 0 {
filters = squirrel.And{
squirrel.Eq{"missing": true},
squirrel.Eq{"id": ids},
squirrel.Eq{"media_file.id": ids},
}
}

View File

@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"time"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/core/agents"
@ -22,8 +23,11 @@ var _ = Describe("Plugin Manager", func() {
// but, as this is an integration test, we can't use configtest.SetupConfig() as it causes
// data races.
originalPluginsFolder := conf.Server.Plugins.Folder
originalTimeout := conf.Server.DevPluginCompilationTimeout
conf.Server.DevPluginCompilationTimeout = 2 * time.Minute
DeferCleanup(func() {
conf.Server.Plugins.Folder = originalPluginsFolder
conf.Server.DevPluginCompilationTimeout = originalTimeout
})
conf.Server.Plugins.Enabled = true
conf.Server.Plugins.Folder = testDataDir

9
ui/package-lock.json generated
View File

@ -63,7 +63,7 @@
"jsdom": "^26.1.0",
"prettier": "^3.6.2",
"ra-test": "^3.19.12",
"typescript": "^5.8.3",
"typescript": "^5.9.3",
"vite": "^7.1.12",
"vite-plugin-pwa": "^1.1.0",
"vitest": "^4.0.3"
@ -10610,10 +10610,11 @@
}
},
"node_modules/typescript": {
"version": "5.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
"version": "5.9.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"

View File

@ -72,7 +72,7 @@
"jsdom": "^26.1.0",
"prettier": "^3.6.2",
"ra-test": "^3.19.12",
"typescript": "^5.8.3",
"typescript": "^5.9.3",
"vite": "^7.1.12",
"vite-plugin-pwa": "^1.1.0",
"vitest": "^4.0.3"

View File

@ -12,7 +12,21 @@ const isAdmin = () => {
const getSelectedLibraries = () => {
try {
const state = JSON.parse(localStorage.getItem('state'))
return state?.library?.selectedLibraries || []
const selectedLibraries = state?.library?.selectedLibraries || []
const userLibraries = state?.library?.userLibraries || []
// Validate selected libraries against current user libraries
const userLibraryIds = userLibraries.map((lib) => lib.id)
const validatedSelection = selectedLibraries.filter((id) =>
userLibraryIds.includes(id),
)
// If user has only one library, return empty array (no filter needed)
if (userLibraryIds.length === 1) {
return []
}
return validatedSelection
} catch (err) {
return []
}

View File

@ -1,5 +1,5 @@
import React, { cloneElement } from 'react'
import { sanitizeListRestProps, TopToolbar } from 'react-admin'
import { sanitizeListRestProps, TopToolbar, CreateButton } from 'react-admin'
import LibraryScanButton from './LibraryScanButton'
const LibraryListActions = ({
@ -23,6 +23,7 @@ const LibraryListActions = ({
})}
<LibraryScanButton fullScan={false} />
<LibraryScanButton fullScan={true} />
<CreateButton />
</TopToolbar>
)
}

View File

@ -8,18 +8,39 @@ const initialState = {
export const libraryReducer = (previousState = initialState, payload) => {
const { type, data } = payload
switch (type) {
case SET_USER_LIBRARIES:
case SET_USER_LIBRARIES: {
const newUserLibraryIds = data.map((lib) => lib.id)
// Validate and filter selected libraries to only include IDs that exist in new user libraries
const validatedSelection = previousState.selectedLibraries.filter((id) =>
newUserLibraryIds.includes(id),
)
// Determine the final selection:
// 1. If first time setting libraries (no previous user libraries), select all
// 2. If user now has only one library, reset to empty (no filter needed)
// 3. Otherwise, use validated selection (may be empty if all previous selections were invalid)
let finalSelection
if (
previousState.selectedLibraries.length === 0 &&
previousState.userLibraries.length === 0
) {
// First time: select all libraries
finalSelection = newUserLibraryIds
} else if (newUserLibraryIds.length === 1) {
// Single library: reset selection (empty means "all accessible")
finalSelection = []
} else {
// Multiple libraries: use validated selection
finalSelection = validatedSelection
}
return {
...previousState,
userLibraries: data,
// If this is the first time setting user libraries and no selection exists,
// default to all libraries
selectedLibraries:
previousState.selectedLibraries.length === 0 &&
previousState.userLibraries.length === 0
? data.map((lib) => lib.id)
: previousState.selectedLibraries,
selectedLibraries: finalSelection,
}
}
case SET_SELECTED_LIBRARIES:
return {
...previousState,

View File

@ -0,0 +1,186 @@
import { describe, it, expect } from 'vitest'
import { libraryReducer } from './libraryReducer'
import { SET_SELECTED_LIBRARIES, SET_USER_LIBRARIES } from '../actions'
describe('libraryReducer', () => {
const mockLibraries = [
{ id: '1', name: 'Music Library' },
{ id: '2', name: 'Podcasts' },
{ id: '3', name: 'Audiobooks' },
]
const initialState = {
userLibraries: [],
selectedLibraries: [],
}
describe('SET_USER_LIBRARIES', () => {
it('should set user libraries and select all on first load', () => {
const action = {
type: SET_USER_LIBRARIES,
data: mockLibraries,
}
const result = libraryReducer(initialState, action)
expect(result.userLibraries).toEqual(mockLibraries)
expect(result.selectedLibraries).toEqual(['1', '2', '3'])
})
it('should reset selection to empty when user has only one library', () => {
const previousState = {
userLibraries: mockLibraries,
selectedLibraries: ['1', '2'],
}
const action = {
type: SET_USER_LIBRARIES,
data: [mockLibraries[0]], // Only one library now
}
const result = libraryReducer(previousState, action)
expect(result.userLibraries).toEqual([mockLibraries[0]])
expect(result.selectedLibraries).toEqual([]) // Reset for single library
})
it('should filter out invalid library IDs from selection', () => {
const previousState = {
userLibraries: mockLibraries,
selectedLibraries: ['1', '2', '3'],
}
const action = {
type: SET_USER_LIBRARIES,
data: [mockLibraries[0], mockLibraries[1]], // Only libraries 1 and 2 remain
}
const result = libraryReducer(previousState, action)
expect(result.userLibraries).toEqual([mockLibraries[0], mockLibraries[1]])
expect(result.selectedLibraries).toEqual(['1', '2']) // Library 3 removed
})
it('should keep valid selection when libraries change', () => {
const previousState = {
userLibraries: mockLibraries,
selectedLibraries: ['1'],
}
const action = {
type: SET_USER_LIBRARIES,
data: mockLibraries, // Same libraries
}
const result = libraryReducer(previousState, action)
expect(result.userLibraries).toEqual(mockLibraries)
expect(result.selectedLibraries).toEqual(['1']) // Selection preserved
})
it('should handle selection becoming empty after filtering invalid IDs', () => {
const previousState = {
userLibraries: mockLibraries,
selectedLibraries: ['1', '2'],
}
const newLibraries = [{ id: '4', name: 'New Library' }]
const action = {
type: SET_USER_LIBRARIES,
data: newLibraries,
}
const result = libraryReducer(previousState, action)
expect(result.userLibraries).toEqual(newLibraries)
expect(result.selectedLibraries).toEqual([]) // All selected IDs were invalid
})
it('should handle transition from multiple to single library with invalid selection', () => {
const previousState = {
userLibraries: mockLibraries,
selectedLibraries: ['2', '3'], // User had libraries 2 and 3 selected
}
const action = {
type: SET_USER_LIBRARIES,
data: [mockLibraries[0]], // Now only has access to library 1
}
const result = libraryReducer(previousState, action)
expect(result.userLibraries).toEqual([mockLibraries[0]])
expect(result.selectedLibraries).toEqual([]) // Reset for single library
})
it('should handle empty library list', () => {
const previousState = {
userLibraries: mockLibraries,
selectedLibraries: ['1', '2'],
}
const action = {
type: SET_USER_LIBRARIES,
data: [],
}
const result = libraryReducer(previousState, action)
expect(result.userLibraries).toEqual([])
expect(result.selectedLibraries).toEqual([]) // All selections filtered out
})
})
describe('SET_SELECTED_LIBRARIES', () => {
it('should update selected libraries', () => {
const previousState = {
userLibraries: mockLibraries,
selectedLibraries: ['1'],
}
const action = {
type: SET_SELECTED_LIBRARIES,
data: ['2', '3'],
}
const result = libraryReducer(previousState, action)
expect(result.selectedLibraries).toEqual(['2', '3'])
expect(result.userLibraries).toEqual(mockLibraries) // Unchanged
})
it('should allow setting empty selection', () => {
const previousState = {
userLibraries: mockLibraries,
selectedLibraries: ['1', '2'],
}
const action = {
type: SET_SELECTED_LIBRARIES,
data: [],
}
const result = libraryReducer(previousState, action)
expect(result.selectedLibraries).toEqual([])
})
})
describe('unknown action', () => {
it('should return previous state for unknown action', () => {
const previousState = {
userLibraries: mockLibraries,
selectedLibraries: ['1'],
}
const action = {
type: 'UNKNOWN_ACTION',
data: null,
}
const result = libraryReducer(previousState, action)
expect(result).toBe(previousState) // Same reference
})
})
})