Skip to content

Commit

Permalink
Merge branch 'develop' into toolTipOption
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-malviya15 authored Feb 7, 2022
2 parents 470b175 + e990444 commit ba7a7b9
Show file tree
Hide file tree
Showing 57 changed files with 336 additions and 257 deletions.
150 changes: 75 additions & 75 deletions app/integrations/server/lib/triggerHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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 }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -38,6 +39,6 @@ Meteor.methods({
});
}

return deleteMessage(originalMessage, Meteor.user());
return deleteMessage(originalMessage, Meteor.user() as IUser);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';

import { slashCommands } from '../../../utils';
import { slashCommands } from '../../../utils/server';

Meteor.methods({
executeSlashCommandPreview(command, preview) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,7 +47,7 @@ Meteor.methods({

const hiddenMessageTypes = getHiddenSystemMessages(room);

const options = {
const options: Record<string, unknown> = {
sort: {
ts: -1,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -18,6 +18,6 @@ Meteor.methods({

const [room] = Rooms.findById(rid).fetch();

return room && room.joinCode;
return room?.joinCode;
},
});
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}

Expand Down
Loading

0 comments on commit ba7a7b9

Please sign in to comment.