Skip to content

Commit 3836d6a

Browse files
fix: executeSaveUserProfile does not trigger username stream (#36385)
Co-authored-by: Pierre Lehnen <55164754+pierre-lehnen-rc@users.noreply.github.com>
1 parent 19c4f60 commit 3836d6a

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

.changeset/angry-years-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
fixes: v1/updateOwnBasicInfo does not trigger user stream

apps/meteor/app/lib/server/functions/setUsername.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import { Meteor } from 'meteor/meteor';
77
import type { ClientSession } from 'mongodb';
88
import _ from 'underscore';
99

10-
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
11-
import { settings } from '../../../settings/server';
12-
import { RateLimiter } from '../lib';
1310
import { addUserToRoom } from './addUserToRoom';
1411
import { checkUsernameAvailability } from './checkUsernameAvailability';
1512
import { getAvatarSuggestionForUser } from './getAvatarSuggestionForUser';
@@ -20,6 +17,7 @@ import { validateUsername } from './validateUsername';
2017
import { callbacks } from '../../../../lib/callbacks';
2118
import { onceTransactionCommitedSuccessfully } from '../../../../server/database/utils';
2219
import { SystemLogger } from '../../../../server/lib/logger/system';
20+
import { settings } from '../../../settings/server';
2321
import { notifyOnUserChange } from '../lib/notifyListener';
2422

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

152150
return user;
153151
};
154-
155-
export const setUsername = RateLimiter.limitFunction(_setUsername, 1, 60000, {
156-
async 0() {
157-
const userId = Meteor.userId();
158-
return !userId || !(await hasPermissionAsync(userId, 'edit-other-user-info'));
159-
},
160-
});

apps/meteor/server/methods/saveUserProfile.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import { Match, check } from 'meteor/check';
77
import { Meteor } from 'meteor/meteor';
88

99
import { twoFactorRequired } from '../../app/2fa/server/twoFactorRequired';
10+
import { getUserInfo } from '../../app/api/server/helpers/getUserInfo';
1011
import { saveCustomFields } from '../../app/lib/server/functions/saveCustomFields';
1112
import { validateUserEditing } from '../../app/lib/server/functions/saveUser';
1213
import { saveUserIdentity } from '../../app/lib/server/functions/saveUserIdentity';
14+
import { notifyOnUserChange } from '../../app/lib/server/lib/notifyListener';
1315
import { passwordPolicy } from '../../app/lib/server/lib/passwordPolicy';
1416
import { setEmailFunction } from '../../app/lib/server/methods/setEmail';
1517
import { settings as rcSettings } from '../../app/settings/server';
@@ -158,6 +160,14 @@ async function saveUserProfile(
158160

159161
// App IPostUserUpdated event hook
160162
const updatedUser = await Users.findOneById(this.userId);
163+
164+
// This should never happen, but since `Users.findOneById` might return null, we'll handle it just in case
165+
if (!updatedUser) {
166+
throw new Error('Unexpected error after saving user profile: user not found');
167+
}
168+
169+
void notifyOnUserChange({ clientAction: 'updated', id: updatedUser._id, diff: getUserInfo(updatedUser) });
170+
161171
await Apps.self?.triggerEvent(AppEvents.IPostUserUpdated, { user: updatedUser, previousUser: user });
162172

163173
return true;

0 commit comments

Comments
 (0)