refactor: Ditch `Meteor.user` in favor of `Meteor.userAsync` - 1x (#28601)

Co-authored-by: Rodrigo Nascimento <234261+rodrigok@users.noreply.github.com>
pull/28598/head^2
Kevin Aleman 3 years ago committed by GitHub
parent 3dee3d9c7e
commit f6b679217f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/meteor/app/2fa/server/methods/checkCodesRemaining.ts
  2. 4
      apps/meteor/app/2fa/server/methods/disable.ts
  3. 4
      apps/meteor/app/2fa/server/methods/enable.ts
  4. 4
      apps/meteor/app/2fa/server/methods/regenerateCodes.ts
  5. 4
      apps/meteor/app/2fa/server/methods/validateTempToken.ts
  6. 2
      apps/meteor/app/channel-settings/server/methods/saveRoomSettings.ts
  7. 4
      apps/meteor/app/crowd/server/methods.ts
  8. 2
      apps/meteor/app/discussion/server/methods/createDiscussion.ts
  9. 2
      apps/meteor/app/emoji-custom/server/methods/listEmojiCustom.ts
  10. 2
      apps/meteor/app/file-upload/server/methods/sendFileMessage.ts
  11. 6
      apps/meteor/app/lib/server/functions/archiveRoom.ts
  12. 4
      apps/meteor/app/lib/server/functions/unarchiveRoom.ts
  13. 2
      apps/meteor/app/lib/server/methods/addUsersToRoom.ts
  14. 2
      apps/meteor/app/lib/server/methods/archiveRoom.ts
  15. 2
      apps/meteor/app/lib/server/methods/checkUsernameAvailability.ts
  16. 2
      apps/meteor/app/lib/server/methods/createChannel.ts
  17. 2
      apps/meteor/app/lib/server/methods/unarchiveRoom.ts
  18. 4
      apps/meteor/app/slackbridge/server/SlackAdapter.js

@ -9,12 +9,12 @@ declare module '@rocket.chat/ui-contexts' {
}
Meteor.methods<ServerMethods>({
'2fa:checkCodesRemaining'() {
async '2fa:checkCodesRemaining'() {
if (!Meteor.userId()) {
throw new Meteor.Error('not-authorized');
}
const user = Meteor.user();
const user = await Meteor.userAsync();
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {

@ -12,13 +12,13 @@ declare module '@rocket.chat/ui-contexts' {
}
Meteor.methods<ServerMethods>({
'2fa:disable'(code) {
async '2fa:disable'(code) {
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('not-authorized');
}
const user = Meteor.user();
const user = await Meteor.userAsync();
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {

@ -12,13 +12,13 @@ declare module '@rocket.chat/ui-contexts' {
}
Meteor.methods<ServerMethods>({
'2fa:enable'() {
async '2fa:enable'() {
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('not-authorized');
}
const user = Meteor.user();
const user = await Meteor.userAsync();
if (!user?.username) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {

@ -12,13 +12,13 @@ declare module '@rocket.chat/ui-contexts' {
}
Meteor.methods<ServerMethods>({
'2fa:regenerateCodes'(userToken) {
async '2fa:regenerateCodes'(userToken) {
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('not-authorized');
}
const user = Meteor.user();
const user = await Meteor.userAsync();
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: '2fa:regenerateCodes',

@ -12,13 +12,13 @@ declare module '@rocket.chat/ui-contexts' {
}
Meteor.methods<ServerMethods>({
'2fa:validateTempToken'(userToken) {
async '2fa:validateTempToken'(userToken) {
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('not-authorized');
}
const user = Meteor.user();
const user = await Meteor.userAsync();
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: '2fa:validateTempToken',

@ -448,7 +448,7 @@ async function saveRoomSettings(
});
}
const user = Meteor.user() as (IUser & Required<Pick<IUser, 'username' | 'name'>>) | null;
const user = (await Meteor.userAsync()) as (IUser & Required<Pick<IUser, 'username' | 'name'>>) | null;
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'saveRoomSettings',

@ -16,7 +16,7 @@ declare module '@rocket.chat/ui-contexts' {
Meteor.methods<ServerMethods>({
async crowd_test_connection() {
const user = Meteor.user();
const user = await Meteor.userAsync();
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'crowd_test_connection',
@ -50,7 +50,7 @@ Meteor.methods<ServerMethods>({
}
},
async crowd_sync_users() {
const user = Meteor.user();
const user = await Meteor.userAsync();
if (settings.get('CROWD_Enable') !== true) {
throw new Meteor.Error('crowd_disabled');
}

@ -212,6 +212,6 @@ Meteor.methods<ServerMethods>({
throw new Meteor.Error('error-action-not-allowed', 'You are not allowed to create a discussion', { method: 'createDiscussion' });
}
return create({ prid, pmid, t_name: discussionName, reply, users, user: Meteor.user() as IUser, encrypted });
return create({ prid, pmid, t_name: discussionName, reply, users, user: (await Meteor.userAsync()) as IUser, encrypted });
},
});

@ -17,7 +17,7 @@ Meteor.methods<ServerMethods>({
async listEmojiCustom(options = {}) {
methodDeprecationLogger.warn('listEmojiCustom will be removed in future versions of Rocket.Chat');
const user = Meteor.user();
const user = await Meteor.userAsync();
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {

@ -128,7 +128,7 @@ declare module '@rocket.chat/ui-contexts' {
Meteor.methods<ServerMethods>({
async sendFileMessage(roomId, _store, file, msgData = {}) {
const user = Meteor.user() as IUser | undefined;
const user = (await Meteor.userAsync()) as IUser | undefined;
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'sendFileMessage',

@ -3,10 +3,10 @@ import { Meteor } from 'meteor/meteor';
import { Rooms, Messages, Subscriptions } from '../../../models/server';
import { callbacks } from '../../../../lib/callbacks';
export const archiveRoom = function (rid: string): void {
export const archiveRoom = async function (rid: string): Promise<void> {
Rooms.archiveById(rid);
Subscriptions.archiveByRoomId(rid);
Messages.createRoomArchivedByRoomIdAndUser(rid, Meteor.user());
Messages.createRoomArchivedByRoomIdAndUser(rid, await Meteor.userAsync());
callbacks.run('afterRoomArchived', Rooms.findOneById(rid), Meteor.user());
callbacks.run('afterRoomArchived', Rooms.findOneById(rid), await Meteor.userAsync());
};

@ -2,8 +2,8 @@ import { Meteor } from 'meteor/meteor';
import { Rooms, Messages, Subscriptions } from '../../../models/server';
export const unarchiveRoom = function (rid: string): void {
export const unarchiveRoom = async function (rid: string): Promise<void> {
Rooms.unarchiveById(rid);
Subscriptions.unarchiveByRoomId(rid);
Messages.createRoomUnarchivedByRoomIdAndUser(rid, Meteor.user());
Messages.createRoomUnarchivedByRoomIdAndUser(rid, await Meteor.userAsync());
};

@ -75,7 +75,7 @@ Meteor.methods<ServerMethods>({
}
// Validate each user, then add to room
const user = (Meteor.user() as IUser | null) ?? undefined;
const user = ((await Meteor.userAsync()) as IUser | null) ?? undefined;
if (isRoomFederated(room)) {
callbacks.run('federation.onAddUsersToARoom', { invitees: data.users, inviter: user }, room);
return true;

@ -11,7 +11,7 @@ import { RoomMemberActions } from '../../../../definition/IRoomTypeConfig';
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
archiveRoom(rid: string): void;
archiveRoom(rid: string): Promise<void>;
}
}

@ -20,7 +20,7 @@ Meteor.methods<ServerMethods>({
check(username, String);
const user = Meteor.user();
const user = await Meteor.userAsync();
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setUsername' });

@ -26,7 +26,7 @@ Meteor.methods<ServerMethods>({
const uid = Meteor.userId();
const user = Meteor.user();
const user = await Meteor.userAsync();
if (!uid || !user?.username) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'createChannel' });

@ -9,7 +9,7 @@ import { unarchiveRoom } from '../functions';
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
unarchiveRoom(rid: string): void;
unarchiveRoom(rid: string): Promise<void>;
}
}

@ -1099,13 +1099,13 @@ export default class SlackAdapter {
case 'channel_archive':
case 'group_archive':
if (!isImporting) {
archiveRoom(rocketChannel);
await archiveRoom(rocketChannel);
}
return;
case 'channel_unarchive':
case 'group_unarchive':
if (!isImporting) {
unarchiveRoom(rocketChannel);
await unarchiveRoom(rocketChannel);
}
return;
case 'file_share':

Loading…
Cancel
Save