Skip to content

Commit

Permalink
Support User: Fetch user settings and user info when switching
Browse files Browse the repository at this point in the history
This change reloads the user settings when activating and
deactivating support user mode. This should prevent some
issues with sticky data on the user profile page.
  • Loading branch information
jordwest committed Jan 11, 2016
1 parent efbcdf8 commit c6178f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
2 changes: 2 additions & 0 deletions client/lib/user/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ User.prototype.changeUser = function( username, password, callback, fnTokenError
User.prototype.restoreUser = function() {
if ( config.isEnabled( 'support-user' ) ) {
wpcom.restoreUser();

this.fetch();
}
}

Expand Down
59 changes: 32 additions & 27 deletions client/state/support/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {

import User from 'lib/user';

import userSettings from 'lib/user-settings';

/**
* Toggles the visibility of the support user dialog
* @return {object} The action object
Expand All @@ -27,36 +29,35 @@ export function toggleSupportUserDialog() {
* @param {string} supportPassword Support password
* @return {thunk} The action thunk
*/
export function fetchSupportUserToken( supportUser, supportPassword ) {
return ( dispatch ) => {
dispatch( {
type: FETCH_SUPPORT_USER_TOKEN,
supportUser
} );
export function fetchSupportUserToken( supportUser, supportPassword ) {
return ( dispatch ) => {
dispatch( {
type: FETCH_SUPPORT_USER_TOKEN,
supportUser
} );

if ( supportUser && supportPassword ) {
if ( supportUser && supportPassword ) {
let user = new User();

user.clear();
user.changeUser(
supportUser,
supportPassword,
( error ) => {
if ( error ) {
dispatch( deactivateSupportUser( error.message ) );
} else {
let userData = Object.assign( {}, user.data );
dispatch( activateSupportUser( userData ) );
}
},
( tokenError ) => {
dispatch( deactivateSupportUser( tokenError.message ) );
}
);
}
}
}

user.clear();
user.changeUser(
supportUser,
supportPassword,
( error ) => {
if ( error ) {
dispatch( deactivateSupportUser( error.message ) );
} else {
let userData = Object.assign( {}, user.data );
dispatch( activateSupportUser( userData ) );
}
},
( tokenError ) => {
dispatch( deactivateSupportUser( tokenError.message ) );
}
);
}
}
}
/**
* Logs out of support user, restoring the original user
* @return {object} The action object
Expand All @@ -74,6 +75,8 @@ export function restoreSupportUser() {
* @return {Object} Action object
*/
export function activateSupportUser( userData ) {
userSettings.fetchSettings();

return {
type: ACTIVATE_SUPPORT_USER,
userData
Expand All @@ -86,6 +89,8 @@ export function activateSupportUser( userData ) {
* @return {Object} Action object
*/
export function deactivateSupportUser( error ) {
userSettings.fetchSettings();

return {
type: DEACTIVATE_SUPPORT_USER,
error
Expand Down

0 comments on commit c6178f3

Please sign in to comment.