fix: Prevent display_name reset when updating password (#10374)

Fixes #10372

---------
Co-authored-by: Pranav <pranavrajs@gmail.com>
This commit is contained in:
Alex808r
2025-06-12 02:05:30 +03:00
committed by GitHub
parent c8f5633d9d
commit 0d05a07aa7
5 changed files with 37 additions and 14 deletions

View File

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

View File

@@ -51,6 +51,7 @@ const endPoints = {
resendConfirmation: {
url: '/api/v1/profile/resend_confirmation',
},
resetAccessToken: {
url: '/api/v1/profile/reset_access_token',
},

View File

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

View File

@@ -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();

View File

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