Skip to content

Commit

Permalink
Fixes #1074: update current user info (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto committed Oct 5, 2016
1 parent 9b46195 commit d535cf9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
18 changes: 18 additions & 0 deletions web/client/reducers/__tests__/security-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
});
});
11 changes: 10 additions & 1 deletion web/client/reducers/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit d535cf9

Please sign in to comment.