From 74faa4c2ceca3a46297e11e47b06427eb64cab74 Mon Sep 17 00:00:00 2001 From: Timothee Legros <62490329+timolegros@users.noreply.github.com> Date: Wed, 26 Jun 2024 18:10:24 +0200 Subject: [PATCH] Reduce Rollbar Usage (#8249) * resolve sequelize syntax errors * remove email notifications * cleaner solution * lint --- .../server/routes/getNewProfile.ts | 7 +++++ .../server/routes/viewComments.ts | 6 ++++ .../server/util/emitNotifications.ts | 31 ------------------- 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/packages/commonwealth/server/routes/getNewProfile.ts b/packages/commonwealth/server/routes/getNewProfile.ts index 4675df05db7..42c2cf1884e 100644 --- a/packages/commonwealth/server/routes/getNewProfile.ts +++ b/packages/commonwealth/server/routes/getNewProfile.ts @@ -1,3 +1,4 @@ +import { AppError } from '@hicommonwealth/core'; import type { AddressAttributes, CommentAttributes, @@ -42,9 +43,15 @@ const getNewProfile = async ( next: NextFunction, ) => { const { profileId } = req.query; + let profile: ProfileInstance; if (profileId) { + const parsedInt = parseInt(profileId); + if (isNaN(parsedInt) || parsedInt !== parseFloat(profileId)) { + throw new AppError('Invalid profile id'); + } + // @ts-expect-error StrictNullChecks profile = await models.Profile.findOne({ where: { diff --git a/packages/commonwealth/server/routes/viewComments.ts b/packages/commonwealth/server/routes/viewComments.ts index 214b1799574..64008bc61a9 100644 --- a/packages/commonwealth/server/routes/viewComments.ts +++ b/packages/commonwealth/server/routes/viewComments.ts @@ -6,6 +6,7 @@ import { sanitizeDeletedComment } from 'server/util/sanitizeDeletedComment'; export const Errors = { NoRootId: 'Must provide thread_id', + InvalidId: 'Invalid thread_id', }; const viewComments = async ( @@ -21,6 +22,11 @@ const viewComments = async ( return next(new AppError(Errors.NoRootId)); } + const parsedInt = parseInt(threadId, 10); + if (isNaN(parsedInt) || parsedInt !== parseFloat(threadId)) { + return next(new AppError(Errors.InvalidId)); + } + const comments = await models.Comment.findAll({ // @ts-expect-error StrictNullChecks where: { community_id: community.id, thread_id: threadId }, diff --git a/packages/commonwealth/server/util/emitNotifications.ts b/packages/commonwealth/server/util/emitNotifications.ts index aa53013e8f4..131c159b5f0 100644 --- a/packages/commonwealth/server/util/emitNotifications.ts +++ b/packages/commonwealth/server/util/emitNotifications.ts @@ -10,10 +10,6 @@ import { import Sequelize, { QueryTypes } from 'sequelize'; import { fileURLToPath } from 'url'; import { config } from '../config'; -import { - createImmediateNotificationEmailObject, - sendImmediateNotificationEmail, -} from '../scripts/emails'; import { mapNotificationsDataToSubscriptions } from './subscriptionMapping'; import { dispatchWebhooks } from './webhooks/dispatchWebhook'; @@ -143,20 +139,6 @@ export default async function emitNotifications( } } - let msg; - try { - if (category_id !== 'snapshot-proposal') { - msg = await createImmediateNotificationEmailObject( - notification_data, - category_id, - models, - ); - } - } catch (e) { - console.log('Error generating immediate notification email!'); - console.trace(e); - } - let query = `INSERT INTO "NotificationsRead" (notification_id, subscription_id, is_read, user_id) VALUES `; const replacements = []; for (const subscription of subscriptions) { @@ -194,19 +176,6 @@ export default async function emitNotifications( } if (config.SEND_WEBHOOKS_EMAILS) { - // emails - for (const subscription of subscriptions) { - // @ts-expect-error StrictNullChecks - if (msg && isChainEventData && chainEvent.community_id) { - // @ts-expect-error StrictNullChecks - msg.dynamic_template_data.notification.path = `${config.SERVER_URL}/${chainEvent.community_id}/notifications?id=${notification.id}`; - } - if (msg && subscription?.immediate_email && subscription?.User) { - // kick off async call and immediately return - sendImmediateNotificationEmail(subscription.User, msg); - } - } - // webhooks try { await dispatchWebhooks(notification_data_and_category);