Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/angry-years-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fixes: v1/updateOwnBasicInfo does not trigger user stream
11 changes: 1 addition & 10 deletions apps/meteor/app/lib/server/functions/setUsername.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import { Meteor } from 'meteor/meteor';
import type { ClientSession } from 'mongodb';
import _ from 'underscore';

import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { settings } from '../../../settings/server';
import { RateLimiter } from '../lib';
import { addUserToRoom } from './addUserToRoom';
import { checkUsernameAvailability } from './checkUsernameAvailability';
import { getAvatarSuggestionForUser } from './getAvatarSuggestionForUser';
Expand All @@ -20,6 +17,7 @@ import { validateUsername } from './validateUsername';
import { callbacks } from '../../../../lib/callbacks';
import { onceTransactionCommitedSuccessfully } from '../../../../server/database/utils';
import { SystemLogger } from '../../../../server/lib/logger/system';
import { settings } from '../../../settings/server';
import { notifyOnUserChange } from '../lib/notifyListener';

export const setUsernameWithValidation = async (userId: string, username: string, joinDefaultChannelsSilenced?: boolean): Promise<void> => {
Expand Down Expand Up @@ -151,10 +149,3 @@ export const _setUsername = async function (

return user;
};

export const setUsername = RateLimiter.limitFunction(_setUsername, 1, 60000, {
async 0() {
const userId = Meteor.userId();
return !userId || !(await hasPermissionAsync(userId, 'edit-other-user-info'));
},
});
10 changes: 10 additions & 0 deletions apps/meteor/server/methods/saveUserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { Match, check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import { twoFactorRequired } from '../../app/2fa/server/twoFactorRequired';
import { getUserInfo } from '../../app/api/server/helpers/getUserInfo';
import { saveCustomFields } from '../../app/lib/server/functions/saveCustomFields';
import { validateUserEditing } from '../../app/lib/server/functions/saveUser';
import { saveUserIdentity } from '../../app/lib/server/functions/saveUserIdentity';
import { notifyOnUserChange } from '../../app/lib/server/lib/notifyListener';
import { passwordPolicy } from '../../app/lib/server/lib/passwordPolicy';
import { setEmailFunction } from '../../app/lib/server/methods/setEmail';
import { settings as rcSettings } from '../../app/settings/server';
Expand Down Expand Up @@ -158,6 +160,14 @@ async function saveUserProfile(

// App IPostUserUpdated event hook
const updatedUser = await Users.findOneById(this.userId);

// This should never happen, but since `Users.findOneById` might return null, we'll handle it just in case
if (!updatedUser) {
throw new Error('Unexpected error after saving user profile: user not found');
}

void notifyOnUserChange({ clientAction: 'updated', id: updatedUser._id, diff: getUserInfo(updatedUser) });

await Apps.self?.triggerEvent(AppEvents.IPostUserUpdated, { user: updatedUser, previousUser: user });

return true;
Expand Down
Loading