diff --git a/app/javascript/dashboard/api/auth.js b/app/javascript/dashboard/api/auth.js index 75e7e2953..a1b15ee79 100644 --- a/app/javascript/dashboard/api/auth.js +++ b/app/javascript/dashboard/api/auth.js @@ -38,13 +38,7 @@ export default { } return false; }, - profileUpdate({ - password, - password_confirmation, - displayName, - avatar, - ...profileAttributes - }) { + profileUpdate({ displayName, avatar, ...profileAttributes }) { const formData = new FormData(); Object.keys(profileAttributes).forEach(key => { const hasValue = profileAttributes[key] === undefined; @@ -53,16 +47,22 @@ export default { } }); formData.append('profile[display_name]', displayName || ''); - if (password && password_confirmation) { - formData.append('profile[password]', password); - formData.append('profile[password_confirmation]', password_confirmation); - } if (avatar) { formData.append('profile[avatar]', avatar); } return axios.put(endPoints('profileUpdate').url, formData); }, + profilePasswordUpdate({ currentPassword, password, passwordConfirmation }) { + return axios.put(endPoints('profileUpdate').url, { + profile: { + current_password: currentPassword, + password, + password_confirmation: passwordConfirmation, + }, + }); + }, + updateUISettings({ uiSettings }) { return axios.put(endPoints('profileUpdate').url, { profile: { ui_settings: uiSettings }, diff --git a/app/javascript/dashboard/api/endPoints.js b/app/javascript/dashboard/api/endPoints.js index 5409aac60..ecd3f0170 100644 --- a/app/javascript/dashboard/api/endPoints.js +++ b/app/javascript/dashboard/api/endPoints.js @@ -51,6 +51,7 @@ const endPoints = { resendConfirmation: { url: '/api/v1/profile/resend_confirmation', }, + resetAccessToken: { url: '/api/v1/profile/reset_access_token', }, diff --git a/app/javascript/dashboard/routes/dashboard/settings/profile/ChangePassword.vue b/app/javascript/dashboard/routes/dashboard/settings/profile/ChangePassword.vue index e224ee5c5..6ee5108ac 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/profile/ChangePassword.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/profile/ChangePassword.vue @@ -62,10 +62,10 @@ export default { } let alertMessage = this.$t('PROFILE_SETTINGS.PASSWORD_UPDATE_SUCCESS'); try { - await this.$store.dispatch('updateProfile', { + await this.$store.dispatch('updatePassword', { password: this.password, - password_confirmation: this.passwordConfirmation, - current_password: this.currentPassword, + passwordConfirmation: this.passwordConfirmation, + currentPassword: this.currentPassword, }); } catch (error) { alertMessage = diff --git a/app/javascript/dashboard/store/modules/auth.js b/app/javascript/dashboard/store/modules/auth.js index f329fb009..91338d938 100644 --- a/app/javascript/dashboard/store/modules/auth.js +++ b/app/javascript/dashboard/store/modules/auth.js @@ -135,6 +135,16 @@ export const actions = { } }, + updatePassword: async ({ commit }, params) => { + // eslint-disable-next-line no-useless-catch + try { + const response = await authAPI.profilePasswordUpdate(params); + commit(types.SET_CURRENT_USER, response.data); + } catch (error) { + throw error; + } + }, + deleteAvatar: async ({ commit }) => { try { const response = await authAPI.deleteAvatar(); diff --git a/spec/controllers/api/v1/profiles_controller_spec.rb b/spec/controllers/api/v1/profiles_controller_spec.rb index 8af9e30c0..30c5b69f4 100644 --- a/spec/controllers/api/v1/profiles_controller_spec.rb +++ b/spec/controllers/api/v1/profiles_controller_spec.rb @@ -94,6 +94,18 @@ RSpec.describe 'Profile API', type: :request do expect(agent.reload.valid_password?('Test1234!')).to be true end + it 'does not reset the display name if updates the password' do + display_name = agent.display_name + + put '/api/v1/profile', + params: { profile: { current_password: 'Test123!', password: 'Test1234!', password_confirmation: 'Test1234!' } }, + headers: agent.create_new_auth_token, + as: :json + + expect(response).to have_http_status(:success) + expect(agent.reload.display_name).to eq(display_name) + end + it 'throws error when current password provided is invalid' do put '/api/v1/profile', params: { profile: { current_password: 'Test', password: 'test123', password_confirmation: 'test123' } },