diff --git a/web/client/reducers/__tests__/security-test.js b/web/client/reducers/__tests__/security-test.js index 926b256640..9c673cf950 100644 --- a/web/client/reducers/__tests__/security-test.js +++ b/web/client/reducers/__tests__/security-test.js @@ -8,6 +8,7 @@ var expect = require('expect'); var security = require('../security'); var {LOGIN_SUCCESS, LOGIN_FAIL, RESET_ERROR, LOGOUT} = require('../../actions/security'); +var {USERMANAGER_UPDATE_USER} = require('../../actions/users'); describe('Test the security reducer', () => { let testToken = "260a670e-4dc0-4719-8bc9-85555d7dcbe1"; @@ -69,4 +70,21 @@ describe('Test the security reducer', () => { expect(state).toExist(); expect(!state.user).toBe(true); }); + it('update user', () => { + let state = security({user: testUser.User}, {type: USERMANAGER_UPDATE_USER, user: { + id: 6, + name: "changed" + }}); + expect(state).toExist(); + expect(state.user.name).toBe("changed"); + }); + + it('do not update user', () => { + let state = security({user: testUser.User}, {type: USERMANAGER_UPDATE_USER, user: { + id: 7, + name: "changed" + }}); + expect(state).toExist(); + expect(state.user.name).toBe("user"); + }); }); diff --git a/web/client/reducers/security.js b/web/client/reducers/security.js index d6ed17e904..901756deb3 100644 --- a/web/client/reducers/security.js +++ b/web/client/reducers/security.js @@ -7,13 +7,22 @@ */ const { LOGIN_SUCCESS, LOGIN_FAIL, LOGOUT, CHANGE_PASSWORD_SUCCESS, RESET_ERROR } = require('../actions/security'); +const { USERMANAGER_UPDATE_USER } = require('../actions/users'); + const SecurityUtils = require('../utils/SecurityUtils'); const assign = require('object-assign'); +const {cloneDeep} = require('lodash'); function security(state = {user: null, errorCause: null}, action) { switch (action.type) { - + case USERMANAGER_UPDATE_USER: + if (state.user && action.user && state.user.id === action.user.id) { + return assign({}, state, { + user: cloneDeep(action.user) + }); + } + return state; case LOGIN_SUCCESS: const userAttributes = SecurityUtils.getUserAttributes(action.userDetails.User); const userUuid = userAttributes.find(attribute => attribute.name.toLowerCase() === 'uuid');