Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue-10372 The value of the display_name field reset #10374

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Alex808r
Copy link

Pull Request Template

Description

When changing the password through the user profile menu, the display_name field is not reset.

Fixes # 10372

@pranavrajs
Copy link
Member

@Alex808r Thanks for the PR. This seems like a hacky fix. The best solution would be to move change_password to a different endpoint so that it only does password change and doesn't update the user data. Let me know if you would be able to make the change.

@Alex808r
Copy link
Author

Alex808r commented Oct 31, 2024

@pranavrajs

it would be interesting for me to deal with this problem. Could you describe in more detail exactly what it should look like.
Now, when changing the password, an empty value display_name => "" is added to params in this method
string: formData.append('profile[display_name]', displayName || '');

app/javascript/dashboard/api/auth.js

profileUpdate({
    password,
    password_confirmation,
    displayName,
    avatar,
    ...profileAttributes
  }) {
    const formData = new FormData();
    Object.keys(profileAttributes).forEach(key => {
      const hasValue = profileAttributes[key] === undefined;
      if (!hasValue) {
        formData.append(`profile[${key}]`, profileAttributes[key]);
      }
    });
    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);
  },

I have another quick solution in app/controllers/api/v1/profiles_controller.rb , we can use return when updating the password

in this case, you will not need a new endpoint and will not have to create a new method updatePassword next to profileUpdate in app/javascript/dashboard/api/auth.js

 def update
    if password_params[:password].present?
      render_could_not_create_error('Invalid current password') and return unless @user.valid_password?(password_params[:current_password])

      return @user.update!(password_params.except(:current_password))
    end

    @user.assign_attributes(profile_params)
    @user.custom_attributes.merge!(custom_attributes_params)
    @user.save!
  end

But if you think the right solution is a new endpoint, I can do it.

@Alex808r Alex808r changed the title fix/issue-10372-profile-display-name fix: issue-10372-profile-display-name Oct 31, 2024
@Alex808r Alex808r force-pushed the fix/issue-10372-profile-display-name branch 6 times, most recently from 0d5a2cd to 044a494 Compare October 31, 2024 15:02
@Alex808r Alex808r changed the title fix: issue-10372-profile-display-name fix: issue-10372 The value of the display_name field reset Oct 31, 2024
@Alex808r Alex808r force-pushed the fix/issue-10372-profile-display-name branch from 044a494 to a8f6f89 Compare October 31, 2024 18:41
@pranavrajs
Copy link
Member

@Alex808r Thanks for the input. Removing the line formData.append('profile[display_name]', displayName || ''); for password updates could work as a solution, but it doesn’t address the root problem. If someone still sends this parameter to the API, the issue would re-appear.

Returning after the password update, as you suggested, is an option, but it could lead to more confusion. We’d then have to explain why profile updates didn’t apply due to the presence of a password parameter.

To keep things straightforward, a separate endpoint for password updates would be more readable and manageable.

I will review and test the PR. Thanks for the changes.

@pranavrajs pranavrajs self-requested a review October 31, 2024 22:07
@pranavrajs pranavrajs self-assigned this Oct 31, 2024
Copy link

github-actions bot commented Dec 1, 2024

🐢 Turtley slow progress alert! This pull request has been idle for over 30 days. Can we please speed things up and either merge it or release it back into the wild?

@github-actions github-actions bot added the stale label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants