Merge 9e79fac12379a77c504302987aa5abba7e8d4f52 into dbd26ba2e71d0a5b79dba873a2beeff59f1cd8dd

This commit is contained in:
Junker der Provinz 2026-08-31 07:19:18 +02:00 committed by GitHub
commit c17796ba91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -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

View File

@ -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')
})
})
})