mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
Merge 9e79fac12379a77c504302987aa5abba7e8d4f52 into dbd26ba2e71d0a5b79dba873a2beeff59f1cd8dd
This commit is contained in:
commit
c17796ba91
@ -94,6 +94,12 @@ const UserEdit = (props) => {
|
||||
notify('resources.user.notifications.updated', 'info', {
|
||||
smart_count: 1,
|
||||
})
|
||||
// Keep the locally stored identity name in sync when users edit their
|
||||
// own profile, so the app bar menu (and the ExtAuth logout/login reload,
|
||||
// which reads localStorage.name via getIdentity) reflect the new name.
|
||||
if (isMyself) {
|
||||
localStorage.setItem('name', values.name)
|
||||
}
|
||||
permissions === 'admin' ? redirect('/user') : refresh()
|
||||
} catch (error) {
|
||||
if (error?.body?.errors) {
|
||||
@ -102,7 +108,7 @@ const UserEdit = (props) => {
|
||||
notify('ra.page.error', 'warning')
|
||||
}
|
||||
},
|
||||
[mutate, notify, permissions, redirect, refresh],
|
||||
[isMyself, mutate, notify, permissions, redirect, refresh],
|
||||
)
|
||||
|
||||
// Custom validation function
|
||||
|
||||
@ -147,6 +147,7 @@ describe('<UserEdit />', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
hooks.save = null
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
it('notifies success and redirects when the update succeeds', async () => {
|
||||
@ -197,5 +198,26 @@ describe('<UserEdit />', () => {
|
||||
expect(hooks.notify).toHaveBeenCalledWith('ra.page.error', 'warning')
|
||||
expect(hooks.redirect).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('syncs the stored identity name when editing your own profile', async () => {
|
||||
localStorage.setItem('userId', 'user1')
|
||||
hooks.mutate.mockResolvedValue({ data: defaultUser })
|
||||
render(<UserEdit id="user1" permissions="user" />)
|
||||
|
||||
await hooks.save({ id: 'user1', name: 'Renamed' })
|
||||
|
||||
expect(localStorage.getItem('name')).toBe('Renamed')
|
||||
})
|
||||
|
||||
it('does not touch the stored identity name when editing another user', async () => {
|
||||
localStorage.setItem('userId', 'admin1')
|
||||
localStorage.setItem('name', 'Admin User')
|
||||
hooks.mutate.mockResolvedValue({ data: defaultUser })
|
||||
render(<UserEdit id="user1" permissions="admin" />)
|
||||
|
||||
await hooks.save({ id: 'user1', name: 'Renamed' })
|
||||
|
||||
expect(localStorage.getItem('name')).toBe('Admin User')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user