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(user-profile): enable saving empty bio to clear user profile field #33927

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-lamps-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Enables saving of an empty bio field in user profiles by adjusting validation logic, allowing users to clear their bio information if desired.
2 changes: 1 addition & 1 deletion apps/meteor/server/methods/saveUserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async function saveUserProfile(
await setUserStatusMethod(this.userId, settings.statusType as UserStatus, undefined);
}

if (user && settings.bio) {
if (user && settings.bio !== undefined) {
Gustrb marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that if you change this to != it will work. let javascript coerce null to undefined
(empty string does not coerce to undefined)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will apply these changes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please re run the workflows so that we can see the tests are still failing or not ??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please give the approval to run the workflows ??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run the tests once again to see whether the tests are failing of not

if (typeof settings.bio !== 'string') {
throw new Meteor.Error('error-invalid-field', 'bio', {
method: 'saveUserProfile',
Expand Down
11 changes: 11 additions & 0 deletions apps/meteor/tests/unit/server/users/saveUserIdentity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,15 @@ describe('Users - saveUserIdentity', () => {
expect(stubs.updateUserReferences.called).to.be.true;
expect(result).to.be.true;
});

it('should update bio to an empty string', async () => {
Gustrb marked this conversation as resolved.
Show resolved Hide resolved
stubs.findOneUserById.returns({ bio: 'Some bio text', username: 'oldUsername' });
stubs.setRealName.returns(true);
stubs.setUsername.returns(true);
const result = await saveUserIdentity({ _id: 'valid_id', bio: '' });
expect(stubs.setRealName.called).to.be.false;
expect(stubs.setUsername.called).to.be.false;
expect(stubs.updateUsernameOfEditByUserId.called).to.be.false;
expect(result).to.be.true;
});
});
Loading