diff --git a/app/integrations/server/lib/triggerHandler.js b/app/integrations/server/lib/triggerHandler.js index a565fa0b4d945..8ba50fca9bd4a 100644 --- a/app/integrations/server/lib/triggerHandler.js +++ b/app/integrations/server/lib/triggerHandler.js @@ -841,91 +841,91 @@ export class RocketChatIntegrationHandler { this.updateHistory({ historyId, step: 'after-process-false-result', finished: true }); return; } + } - // if the result contained nothing or wasn't a successful statusCode - if (!content || !this.successResults.includes(res.status)) { - if (content) { - outgoingLogger.error({ - msg: `Error for the Integration "${trigger.name}" to ${url}`, - result: content, - }); + // if the result contained nothing or wasn't a successful statusCode + if (!content || !this.successResults.includes(res.status)) { + if (content) { + outgoingLogger.error({ + msg: `Error for the Integration "${trigger.name}" to ${url}`, + result: content, + }); - if (res.status === 410) { - this.updateHistory({ historyId, step: 'after-process-http-status-410', error: true }); - outgoingLogger.error(`Disabling the Integration "${trigger.name}" because the status code was 401 (Gone).`); - await Integrations.updateOne({ _id: trigger._id }, { $set: { enabled: false } }); - return; - } + if (res.status === 410) { + this.updateHistory({ historyId, step: 'after-process-http-status-410', error: true }); + outgoingLogger.error(`Disabling the Integration "${trigger.name}" because the status code was 401 (Gone).`); + await Integrations.updateOne({ _id: trigger._id }, { $set: { enabled: false } }); + return; + } - if (res.status === 500) { - this.updateHistory({ historyId, step: 'after-process-http-status-500', error: true }); - outgoingLogger.error({ - msg: `Error "500" for the Integration "${trigger.name}" to ${url}.`, - content, - }); - return; - } + if (res.status === 500) { + this.updateHistory({ historyId, step: 'after-process-http-status-500', error: true }); + outgoingLogger.error({ + msg: `Error "500" for the Integration "${trigger.name}" to ${url}.`, + content, + }); + return; } + } - if (trigger.retryFailedCalls) { - if (tries < trigger.retryCount && trigger.retryDelay) { - this.updateHistory({ historyId, error: true, step: `going-to-retry-${tries + 1}` }); - - let waitTime; - - switch (trigger.retryDelay) { - case 'powers-of-ten': - // Try again in 0.1s, 1s, 10s, 1m40s, 16m40s, 2h46m40s, 27h46m40s, etc - waitTime = Math.pow(10, tries + 2); - break; - case 'powers-of-two': - // 2 seconds, 4 seconds, 8 seconds - waitTime = Math.pow(2, tries + 1) * 1000; - break; - case 'increments-of-two': - // 2 second, 4 seconds, 6 seconds, etc - waitTime = (tries + 1) * 2 * 1000; - break; - default: - const er = new Error("The integration's retryDelay setting is invalid."); - this.updateHistory({ - historyId, - step: 'failed-and-retry-delay-is-invalid', - error: true, - errorStack: er.stack, - }); - return; - } - - outgoingLogger.info(`Trying the Integration ${trigger.name} to ${url} again in ${waitTime} milliseconds.`); - Meteor.setTimeout(() => { - this.executeTriggerUrl(url, trigger, { event, message, room, owner, user }, historyId, tries + 1); - }, waitTime); - } else { - this.updateHistory({ historyId, step: 'too-many-retries', error: true }); + if (trigger.retryFailedCalls) { + if (tries < trigger.retryCount && trigger.retryDelay) { + this.updateHistory({ historyId, error: true, step: `going-to-retry-${tries + 1}` }); + + let waitTime; + + switch (trigger.retryDelay) { + case 'powers-of-ten': + // Try again in 0.1s, 1s, 10s, 1m40s, 16m40s, 2h46m40s, 27h46m40s, etc + waitTime = Math.pow(10, tries + 2); + break; + case 'powers-of-two': + // 2 seconds, 4 seconds, 8 seconds + waitTime = Math.pow(2, tries + 1) * 1000; + break; + case 'increments-of-two': + // 2 second, 4 seconds, 6 seconds, etc + waitTime = (tries + 1) * 2 * 1000; + break; + default: + const er = new Error("The integration's retryDelay setting is invalid."); + this.updateHistory({ + historyId, + step: 'failed-and-retry-delay-is-invalid', + error: true, + errorStack: er.stack, + }); + return; } + + outgoingLogger.info(`Trying the Integration ${trigger.name} to ${url} again in ${waitTime} milliseconds.`); + Meteor.setTimeout(() => { + this.executeTriggerUrl(url, trigger, { event, message, room, owner, user }, historyId, tries + 1); + }, waitTime); } else { - this.updateHistory({ - historyId, - step: 'failed-and-not-configured-to-retry', - error: true, - }); + this.updateHistory({ historyId, step: 'too-many-retries', error: true }); } - - return; + } else { + this.updateHistory({ + historyId, + step: 'failed-and-not-configured-to-retry', + error: true, + }); } - // process outgoing webhook response as a new message - if (content && this.successResults.includes(res.status)) { - if (data?.text || data?.attachments) { - const resultMsg = this.sendMessage({ trigger, room, message: data, data }); - this.updateHistory({ - historyId, - step: 'url-response-sent-message', - resultMessage: resultMsg, - finished: true, - }); - } + return; + } + + // process outgoing webhook response as a new message + if (content && this.successResults.includes(res.status)) { + if (data?.text || data?.attachments) { + const resultMsg = this.sendMessage({ trigger, room, message: data, data }); + this.updateHistory({ + historyId, + step: 'url-response-sent-message', + resultMessage: resultMsg, + finished: true, + }); } } }) diff --git a/app/lib/server/methods/addOAuthService.js b/app/lib/server/methods/addOAuthService.ts similarity index 90% rename from app/lib/server/methods/addOAuthService.js rename to app/lib/server/methods/addOAuthService.ts index 36a4ba555ec26..57ce8265fc3a2 100644 --- a/app/lib/server/methods/addOAuthService.js +++ b/app/lib/server/methods/addOAuthService.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; +import { hasPermission } from '../../../authorization/server'; import { addOAuthService } from '../functions/addOAuthService'; Meteor.methods({ diff --git a/app/lib/server/methods/addUserToRoom.js b/app/lib/server/methods/addUserToRoom.ts similarity index 100% rename from app/lib/server/methods/addUserToRoom.js rename to app/lib/server/methods/addUserToRoom.ts diff --git a/app/lib/server/methods/archiveRoom.js b/app/lib/server/methods/archiveRoom.ts similarity index 89% rename from app/lib/server/methods/archiveRoom.js rename to app/lib/server/methods/archiveRoom.ts index 4f101615b8416..7f55af28122b5 100644 --- a/app/lib/server/methods/archiveRoom.js +++ b/app/lib/server/methods/archiveRoom.ts @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { Rooms } from '../../../models'; -import { hasPermission } from '../../../authorization'; +import { Rooms } from '../../../models/server'; +import { hasPermission } from '../../../authorization/server'; import { archiveRoom } from '../functions'; import { roomTypes, RoomMemberActions } from '../../../utils/server'; diff --git a/app/lib/server/methods/blockUser.js b/app/lib/server/methods/blockUser.ts similarity index 91% rename from app/lib/server/methods/blockUser.js rename to app/lib/server/methods/blockUser.ts index f9e4bb4c54d22..7ca223e4ad00b 100644 --- a/app/lib/server/methods/blockUser.js +++ b/app/lib/server/methods/blockUser.ts @@ -1,9 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { Subscriptions } from '../../../models'; import { roomTypes, RoomMemberActions } from '../../../utils/server'; -import { Rooms } from '../../../models/server'; +import { Rooms, Subscriptions } from '../../../models/server'; Meteor.methods({ blockUser({ rid, blocked }) { diff --git a/app/lib/server/methods/checkRegistrationSecretURL.js b/app/lib/server/methods/checkRegistrationSecretURL.ts similarity index 81% rename from app/lib/server/methods/checkRegistrationSecretURL.js rename to app/lib/server/methods/checkRegistrationSecretURL.ts index ab411be95d1a5..11a1d4ea42007 100644 --- a/app/lib/server/methods/checkRegistrationSecretURL.js +++ b/app/lib/server/methods/checkRegistrationSecretURL.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; Meteor.methods({ checkRegistrationSecretURL(hash) { diff --git a/app/lib/server/methods/checkUsernameAvailability.js b/app/lib/server/methods/checkUsernameAvailability.ts similarity index 80% rename from app/lib/server/methods/checkUsernameAvailability.js rename to app/lib/server/methods/checkUsernameAvailability.ts index 7bf9b7f9acdbd..2a9f34780f2a1 100644 --- a/app/lib/server/methods/checkUsernameAvailability.js +++ b/app/lib/server/methods/checkUsernameAvailability.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; import { checkUsernameAvailability } from '../functions'; import { RateLimiter } from '../lib'; @@ -15,11 +15,11 @@ Meteor.methods({ const user = Meteor.user(); - if (user.username && !settings.get('Accounts_AllowUsernameChange')) { + if (user?.username && !settings.get('Accounts_AllowUsernameChange')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setUsername' }); } - if (user.username === username) { + if (user?.username === username) { return true; } return checkUsernameAvailability(username); diff --git a/app/lib/server/methods/createChannel.js b/app/lib/server/methods/createChannel.ts similarity index 79% rename from app/lib/server/methods/createChannel.js rename to app/lib/server/methods/createChannel.ts index 0201e985e74f7..364d31200d21c 100644 --- a/app/lib/server/methods/createChannel.js +++ b/app/lib/server/methods/createChannel.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; +import { hasPermission } from '../../../authorization/server'; import { createRoom } from '../functions'; Meteor.methods({ @@ -16,7 +16,7 @@ Meteor.methods({ if (!hasPermission(Meteor.userId(), 'create-c')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'createChannel' }); } - return createRoom('c', name, Meteor.user() && Meteor.user().username, members, readOnly, { + return createRoom('c', name, Meteor.user() && Meteor.user()?.username, members, readOnly, { customFields, ...extraData, }); diff --git a/app/lib/server/methods/createToken.js b/app/lib/server/methods/createToken.ts similarity index 78% rename from app/lib/server/methods/createToken.js rename to app/lib/server/methods/createToken.ts index 47713c0fc44ee..d05df8d95562f 100644 --- a/app/lib/server/methods/createToken.js +++ b/app/lib/server/methods/createToken.ts @@ -1,12 +1,12 @@ import { Meteor } from 'meteor/meteor'; import { Accounts } from 'meteor/accounts-base'; -import { hasPermission } from '../../../authorization'; +import { hasPermission } from '../../../authorization/server'; Meteor.methods({ createToken(userId) { if ( - !['yes', 'true'].includes(process.env.CREATE_TOKENS_FOR_USERS) || + !['yes', 'true'].includes(String(process.env.CREATE_TOKENS_FOR_USERS)) || (Meteor.userId() !== userId && !hasPermission(Meteor.userId(), 'user-generate-access-token')) ) { throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'createToken' }); diff --git a/app/lib/server/methods/deleteMessage.js b/app/lib/server/methods/deleteMessage.ts similarity index 83% rename from app/lib/server/methods/deleteMessage.js rename to app/lib/server/methods/deleteMessage.ts index 47d54f4e940e3..d8c1b97034dbc 100644 --- a/app/lib/server/methods/deleteMessage.js +++ b/app/lib/server/methods/deleteMessage.ts @@ -2,8 +2,9 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; import { canDeleteMessage } from '../../../authorization/server/functions/canDeleteMessage'; -import { Messages } from '../../../models'; +import { Messages } from '../../../models/server'; import { deleteMessage } from '../functions'; +import { IUser } from '../../../../definition/IUser'; Meteor.methods({ async deleteMessage(message) { @@ -38,6 +39,6 @@ Meteor.methods({ }); } - return deleteMessage(originalMessage, Meteor.user()); + return deleteMessage(originalMessage, Meteor.user() as IUser); }, }); diff --git a/app/lib/server/methods/deleteUserOwnAccount.js b/app/lib/server/methods/deleteUserOwnAccount.ts similarity index 93% rename from app/lib/server/methods/deleteUserOwnAccount.js rename to app/lib/server/methods/deleteUserOwnAccount.ts index f6dda0888febd..2ce0a3df79fa3 100644 --- a/app/lib/server/methods/deleteUserOwnAccount.js +++ b/app/lib/server/methods/deleteUserOwnAccount.ts @@ -4,8 +4,8 @@ import { Accounts } from 'meteor/accounts-base'; import { SHA256 } from 'meteor/sha'; import s from 'underscore.string'; -import { settings } from '../../../settings'; -import { Users } from '../../../models'; +import { settings } from '../../../settings/server'; +import { Users } from '../../../models/server'; import { deleteUser } from '../functions'; Meteor.methods({ diff --git a/app/lib/server/methods/executeSlashCommandPreview.js b/app/lib/server/methods/executeSlashCommandPreview.ts similarity index 94% rename from app/lib/server/methods/executeSlashCommandPreview.js rename to app/lib/server/methods/executeSlashCommandPreview.ts index 52f2c18527a5c..8df013402607a 100644 --- a/app/lib/server/methods/executeSlashCommandPreview.js +++ b/app/lib/server/methods/executeSlashCommandPreview.ts @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { slashCommands } from '../../../utils'; +import { slashCommands } from '../../../utils/server'; Meteor.methods({ executeSlashCommandPreview(command, preview) { diff --git a/app/lib/server/methods/getChannelHistory.js b/app/lib/server/methods/getChannelHistory.ts similarity index 96% rename from app/lib/server/methods/getChannelHistory.js rename to app/lib/server/methods/getChannelHistory.ts index d39499a845245..939889eff2fea 100644 --- a/app/lib/server/methods/getChannelHistory.js +++ b/app/lib/server/methods/getChannelHistory.ts @@ -16,7 +16,7 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getChannelHistory' }); } - const fromUserId = Meteor.userId(); + const fromUserId = Meteor.userId() || undefined; const room = Rooms.findOneById(rid); if (!room) { return false; @@ -47,7 +47,7 @@ Meteor.methods({ const hiddenMessageTypes = getHiddenSystemMessages(room); - const options = { + const options: Record = { sort: { ts: -1, }, diff --git a/app/lib/server/methods/getMessages.js b/app/lib/server/methods/getMessages.ts similarity index 62% rename from app/lib/server/methods/getMessages.js rename to app/lib/server/methods/getMessages.ts index f8ccbbbb6f740..57b5d50483fb6 100644 --- a/app/lib/server/methods/getMessages.js +++ b/app/lib/server/methods/getMessages.ts @@ -3,16 +3,23 @@ import { check } from 'meteor/check'; import { canAccessRoom } from '../../../authorization/server'; import { Messages } from '../../../models/server'; +import { IMessage } from '../../../../definition/IMessage'; Meteor.methods({ getMessages(messages) { check(messages, [String]); + const uid = Meteor.userId(); - const msgs = Messages.findVisibleByIds(messages).fetch(); + if (!uid) { + throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getMessages' }); + } + + const msgs = Messages.findVisibleByIds(messages).fetch() as IMessage[]; - const user = { _id: Meteor.userId() }; + const user = { _id: uid }; const rids = [...new Set(msgs.map((m) => m.rid))]; + if (!rids.every((_id) => canAccessRoom({ _id }, user))) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' }); } diff --git a/app/lib/server/methods/getRoomJoinCode.js b/app/lib/server/methods/getRoomJoinCode.ts similarity index 77% rename from app/lib/server/methods/getRoomJoinCode.js rename to app/lib/server/methods/getRoomJoinCode.ts index da58b6b86e834..0776787a0a285 100644 --- a/app/lib/server/methods/getRoomJoinCode.js +++ b/app/lib/server/methods/getRoomJoinCode.ts @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; -import { Rooms } from '../../../models'; +import { hasPermission } from '../../../authorization/server'; +import { Rooms } from '../../../models/server'; Meteor.methods({ getRoomJoinCode(rid) { @@ -18,6 +18,6 @@ Meteor.methods({ const [room] = Rooms.findById(rid).fetch(); - return room && room.joinCode; + return room?.joinCode; }, }); diff --git a/app/lib/server/methods/getRoomRoles.js b/app/lib/server/methods/getRoomRoles.ts similarity index 89% rename from app/lib/server/methods/getRoomRoles.js rename to app/lib/server/methods/getRoomRoles.ts index 33b6ef34edad3..5b20c92849236 100644 --- a/app/lib/server/methods/getRoomRoles.js +++ b/app/lib/server/methods/getRoomRoles.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; import { getRoomRoles } from '../lib/getRoomRoles'; Meteor.methods({ diff --git a/app/lib/server/methods/getSingleMessage.js b/app/lib/server/methods/getSingleMessage.ts similarity index 70% rename from app/lib/server/methods/getSingleMessage.js rename to app/lib/server/methods/getSingleMessage.ts index 604ac2f1b4f70..ff5457a06657a 100644 --- a/app/lib/server/methods/getSingleMessage.js +++ b/app/lib/server/methods/getSingleMessage.ts @@ -8,13 +8,19 @@ Meteor.methods({ getSingleMessage(msgId) { check(msgId, String); + const uid = Meteor.userId(); + + if (!uid) { + throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getSingleMessage' }); + } + const msg = Messages.findOneById(msgId); if (!msg || !msg.rid) { return undefined; } - if (!canAccessRoom({ _id: msg.rid }, { _id: Meteor.userId() })) { + if (!canAccessRoom({ _id: msg.rid }, { _id: uid })) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' }); } diff --git a/app/lib/server/methods/getSlashCommandPreviews.js b/app/lib/server/methods/getSlashCommandPreviews.ts similarity index 93% rename from app/lib/server/methods/getSlashCommandPreviews.js rename to app/lib/server/methods/getSlashCommandPreviews.ts index a643593217354..2d8b7ce179b5f 100644 --- a/app/lib/server/methods/getSlashCommandPreviews.js +++ b/app/lib/server/methods/getSlashCommandPreviews.ts @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { slashCommands } from '../../../utils'; +import { slashCommands } from '../../../utils/server'; Meteor.methods({ getSlashCommandPreviews(command) { diff --git a/app/lib/server/methods/joinDefaultChannels.js b/app/lib/server/methods/joinDefaultChannels.ts similarity index 100% rename from app/lib/server/methods/joinDefaultChannels.js rename to app/lib/server/methods/joinDefaultChannels.ts diff --git a/app/lib/server/methods/joinRoom.js b/app/lib/server/methods/joinRoom.ts similarity index 89% rename from app/lib/server/methods/joinRoom.js rename to app/lib/server/methods/joinRoom.ts index 9460f68cf6729..c4de0456dd393 100644 --- a/app/lib/server/methods/joinRoom.js +++ b/app/lib/server/methods/joinRoom.ts @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { hasPermission, canAccessRoom } from '../../../authorization'; -import { Rooms } from '../../../models'; +import { hasPermission, canAccessRoom } from '../../../authorization/server'; +import { Rooms } from '../../../models/server'; import { Tokenpass, updateUserTokenpassBalances } from '../../../tokenpass/server'; import { addUserToRoom } from '../functions'; import { roomTypes, RoomMemberActions } from '../../../utils/server'; @@ -11,7 +11,9 @@ Meteor.methods({ joinRoom(rid, code) { check(rid, String); - if (!Meteor.userId()) { + const user = Meteor.user(); + + if (!user) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'joinRoom' }); } @@ -26,7 +28,7 @@ Meteor.methods({ } // TODO we should have a 'beforeJoinRoom' call back so external services can do their own validations - const user = Meteor.user(); + if (room.tokenpass && user && user.services && user.services.tokenpass) { const balances = updateUserTokenpassBalances(user); @@ -34,10 +36,10 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Token required', { method: 'joinRoom' }); } } else { - if (!canAccessRoom(room, Meteor.user())) { + if (!canAccessRoom(room, user)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'joinRoom' }); } - if (room.joinCodeRequired === true && code !== room.joinCode && !hasPermission(Meteor.userId(), 'join-without-join-code')) { + if (room.joinCodeRequired === true && code !== room.joinCode && !hasPermission(user._id, 'join-without-join-code')) { throw new Meteor.Error('error-code-invalid', 'Invalid Room Password', { method: 'joinRoom', }); diff --git a/app/lib/server/methods/restartServer.js b/app/lib/server/methods/restartServer.ts similarity index 73% rename from app/lib/server/methods/restartServer.js rename to app/lib/server/methods/restartServer.ts index d694b833f746f..c530ee1b7afa2 100644 --- a/app/lib/server/methods/restartServer.js +++ b/app/lib/server/methods/restartServer.ts @@ -1,14 +1,17 @@ import { Meteor } from 'meteor/meteor'; -import { hasRole } from '../../../authorization'; +import { hasRole } from '../../../authorization/server'; Meteor.methods({ + // eslint-disable-next-line @typescript-eslint/camelcase restart_server() { - if (!Meteor.userId()) { + const uid = Meteor.userId(); + + if (!uid) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'restart_server' }); } - if (hasRole(Meteor.userId(), 'admin') !== true) { + if (hasRole(uid, 'admin') !== true) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'restart_server' }); } diff --git a/app/lib/server/methods/setAdminStatus.js b/app/lib/server/methods/setAdminStatus.ts similarity index 76% rename from app/lib/server/methods/setAdminStatus.js rename to app/lib/server/methods/setAdminStatus.ts index 9ea6d5259d315..2f416fe8e6d77 100644 --- a/app/lib/server/methods/setAdminStatus.js +++ b/app/lib/server/methods/setAdminStatus.ts @@ -1,26 +1,28 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; +import { hasPermission } from '../../../authorization/server'; Meteor.methods({ setAdminStatus(userId, admin) { check(userId, String); check(admin, Match.Optional(Boolean)); - if (!Meteor.userId()) { + const uid = Meteor.userId(); + + if (!uid) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setAdminStatus' }); } - if (hasPermission(Meteor.userId(), 'assign-admin-role') !== true) { + if (hasPermission(uid, 'assign-admin-role') !== true) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setAdminStatus' }); } const user = Meteor.users.findOne({ _id: userId }, { fields: { username: 1 } }); if (admin) { - return Meteor.call('authorization:addUserToRole', 'admin', user.username); + return Meteor.call('authorization:addUserToRole', 'admin', user?.username); } - return Meteor.call('authorization:removeUserFromRole', 'admin', user.username); + return Meteor.call('authorization:removeUserFromRole', 'admin', user?.username); }, }); diff --git a/app/lib/server/methods/setEmail.js b/app/lib/server/methods/setEmail.ts similarity index 92% rename from app/lib/server/methods/setEmail.js rename to app/lib/server/methods/setEmail.ts index 027e6418145c1..682f936defc7f 100644 --- a/app/lib/server/methods/setEmail.js +++ b/app/lib/server/methods/setEmail.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; import { setEmail } from '../functions'; import { RateLimiter } from '../lib'; @@ -9,12 +9,12 @@ Meteor.methods({ setEmail(email) { check(email, String); - if (!Meteor.userId()) { + const user = Meteor.user(); + + if (!user) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setEmail' }); } - const user = Meteor.user(); - if (!settings.get('Accounts_AllowEmailChange')) { throw new Meteor.Error('error-action-not-allowed', 'Changing email is not allowed', { method: 'setEmail', diff --git a/app/lib/server/methods/setRealName.js b/app/lib/server/methods/setRealName.ts similarity index 93% rename from app/lib/server/methods/setRealName.js rename to app/lib/server/methods/setRealName.ts index 5f8301667a344..0ebc9ebb76bf8 100644 --- a/app/lib/server/methods/setRealName.js +++ b/app/lib/server/methods/setRealName.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; import { setRealName } from '../functions'; import { RateLimiter } from '../lib'; diff --git a/app/lib/server/methods/setUsername.js b/app/lib/server/methods/setUsername.ts similarity index 92% rename from app/lib/server/methods/setUsername.js rename to app/lib/server/methods/setUsername.ts index 91e1d60d6d86c..83ffee0bf2f96 100644 --- a/app/lib/server/methods/setUsername.js +++ b/app/lib/server/methods/setUsername.ts @@ -2,8 +2,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import _ from 'underscore'; -import { settings } from '../../../settings'; -import { Users } from '../../../models'; +import { settings } from '../../../settings/server'; +import { Users } from '../../../models/server'; import { callbacks } from '../../../../lib/callbacks'; import { checkUsernameAvailability } from '../functions'; import { RateLimiter } from '../lib'; @@ -14,12 +14,12 @@ Meteor.methods({ const { joinDefaultChannelsSilenced } = param; check(username, String); - if (!Meteor.userId()) { + const user = Meteor.user(); + + if (!user) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setUsername' }); } - const user = Meteor.user(); - if (user.username && !settings.get('Accounts_AllowUsernameChange')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setUsername' }); } @@ -49,7 +49,7 @@ Meteor.methods({ }); } - if (!saveUserIdentity({ _id: user._id, username })) { + if (!saveUserIdentity({ _id: user?._id, username })) { throw new Meteor.Error('error-could-not-change-username', 'Could not change username', { method: 'setUsername', }); diff --git a/app/lib/server/methods/unarchiveRoom.js b/app/lib/server/methods/unarchiveRoom.ts similarity index 85% rename from app/lib/server/methods/unarchiveRoom.js rename to app/lib/server/methods/unarchiveRoom.ts index e584ce1044d3c..f0313b7a24cc5 100644 --- a/app/lib/server/methods/unarchiveRoom.js +++ b/app/lib/server/methods/unarchiveRoom.ts @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; -import { Rooms } from '../../../models'; +import { hasPermission } from '../../../authorization/server'; +import { Rooms } from '../../../models/server'; import { unarchiveRoom } from '../functions'; Meteor.methods({ diff --git a/app/lib/server/methods/unblockUser.js b/app/lib/server/methods/unblockUser.ts similarity index 92% rename from app/lib/server/methods/unblockUser.js rename to app/lib/server/methods/unblockUser.ts index 3b3522feebd89..4a4650e6fd40c 100644 --- a/app/lib/server/methods/unblockUser.js +++ b/app/lib/server/methods/unblockUser.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { Subscriptions } from '../../../models'; +import { Subscriptions } from '../../../models/server'; Meteor.methods({ unblockUser({ rid, blocked }) { diff --git a/app/ui-login/client/login/form.html b/app/ui-login/client/login/form.html index ef639ddc1719f..4c4a253104d93 100644 --- a/app/ui-login/client/login/form.html +++ b/app/ui-login/client/login/form.html @@ -126,7 +126,7 @@

{{{_ "Registration_Succeeded"}}}

{{/if}} {{#if registrationAllowed}} - + {{else}} {{#if linkReplacementText}}