From 28860c402ae199880f0efd83a6548d9de6587328 Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Wed, 25 Sep 2024 19:19:31 +0530 Subject: [PATCH 1/2] chore!: removed Mailer.sendMail and Mailer:unsubscribe methods Signed-off-by: Abhinav Kumar --- apps/meteor/app/api/server/v1/mailer.ts | 7 ++-- apps/meteor/app/mail-messages/server/index.ts | 2 -- .../mail-messages/server/methods/sendMail.ts | 36 ------------------- .../server/methods/unsubscribe.ts | 33 ----------------- apps/meteor/server/importPackages.ts | 1 - 5 files changed, 5 insertions(+), 74 deletions(-) delete mode 100644 apps/meteor/app/mail-messages/server/index.ts delete mode 100644 apps/meteor/app/mail-messages/server/methods/sendMail.ts delete mode 100644 apps/meteor/app/mail-messages/server/methods/unsubscribe.ts diff --git a/apps/meteor/app/api/server/v1/mailer.ts b/apps/meteor/app/api/server/v1/mailer.ts index 56229e26dc31..57fa62e85a6c 100644 --- a/apps/meteor/app/api/server/v1/mailer.ts +++ b/apps/meteor/app/api/server/v1/mailer.ts @@ -1,5 +1,7 @@ import { isMailerProps, isMailerUnsubscribeProps } from '@rocket.chat/rest-typings'; +import { sendMail } from '../../../mail-messages/server/functions/sendMail'; +import { Mailer } from '../../../mail-messages/server/lib/Mailer'; import { API } from '../api'; API.v1.addRoute( @@ -13,7 +15,7 @@ API.v1.addRoute( async post() { const { from, subject, body, dryrun, query } = this.bodyParams; - const result = await Meteor.callAsync('Mailer.sendMail', from, subject, body, Boolean(dryrun), query); + const result = await sendMail({ from, subject, body, dryrun: Boolean(dryrun), query }); return API.v1.success(result); }, @@ -25,12 +27,13 @@ API.v1.addRoute( { authRequired: true, validateParams: isMailerUnsubscribeProps, + rateLimiterOptions: { intervalTimeInMS: 60000, numRequestsAllowed: 1 }, }, { async post() { const { _id, createdAt } = this.bodyParams; - await Meteor.callAsync('Mailer:unsubscribe', _id, createdAt); + await Mailer.unsubscribe(_id, createdAt); return API.v1.success(); }, diff --git a/apps/meteor/app/mail-messages/server/index.ts b/apps/meteor/app/mail-messages/server/index.ts deleted file mode 100644 index 255eeddcf63b..000000000000 --- a/apps/meteor/app/mail-messages/server/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -import './methods/sendMail'; -import './methods/unsubscribe'; diff --git a/apps/meteor/app/mail-messages/server/methods/sendMail.ts b/apps/meteor/app/mail-messages/server/methods/sendMail.ts deleted file mode 100644 index cc6469544df8..000000000000 --- a/apps/meteor/app/mail-messages/server/methods/sendMail.ts +++ /dev/null @@ -1,36 +0,0 @@ -import type { ServerMethods } from '@rocket.chat/ddp-client'; -import { Meteor } from 'meteor/meteor'; - -import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; -import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; -import { Mailer } from '../lib/Mailer'; - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - 'Mailer.sendMail'(from: string, subject: string, body: string, dryrun?: boolean, query?: string): any; - } -} - -Meteor.methods({ - async 'Mailer.sendMail'(from, subject, body, dryrun, query) { - methodDeprecationLogger.method('Mailer.sendMail', '7.0.0'); - - const userId = Meteor.userId(); - - if (!userId || !(await hasPermissionAsync(userId, 'send-mail'))) { - throw new Meteor.Error('error-not-allowed', 'Not allowed', { - method: 'Mailer.sendMail', - }); - } - - return Mailer.sendMail({ from, subject, body, dryrun, query }); - }, -}); - -// Limit setting username once per minute -// DDPRateLimiter.addRule -// type: 'method' -// name: 'Mailer.sendMail' -// connectionId: -> return true -// , 1, 60000 diff --git a/apps/meteor/app/mail-messages/server/methods/unsubscribe.ts b/apps/meteor/app/mail-messages/server/methods/unsubscribe.ts deleted file mode 100644 index e52677b5ee1a..000000000000 --- a/apps/meteor/app/mail-messages/server/methods/unsubscribe.ts +++ /dev/null @@ -1,33 +0,0 @@ -import type { ServerMethods } from '@rocket.chat/ddp-client'; -import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; -import { Meteor } from 'meteor/meteor'; - -import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; -import { Mailer } from '../lib/Mailer'; - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - 'Mailer:unsubscribe'(_id: string, createdAt: string): Promise; - } -} - -Meteor.methods({ - async 'Mailer:unsubscribe'(_id, createdAt) { - methodDeprecationLogger.method('Mailer:unsubscribe', '7.0.0'); - - return Mailer.unsubscribe(_id, createdAt); - }, -}); - -DDPRateLimiter.addRule( - { - type: 'method', - name: 'Mailer:unsubscribe', - connectionId() { - return true; - }, - }, - 1, - 60000, -); diff --git a/apps/meteor/server/importPackages.ts b/apps/meteor/server/importPackages.ts index dfda85e52a9e..cab60d63a5c9 100644 --- a/apps/meteor/server/importPackages.ts +++ b/apps/meteor/server/importPackages.ts @@ -75,7 +75,6 @@ import '../app/e2e/server'; import '../app/version-check/server'; import '../app/search/server'; import '../app/discussion/server'; -import '../app/mail-messages/server'; import '../app/user-status/server'; import '../app/metrics/server'; import '../app/notifications/server'; From 1c21662accf9cd713c90f098df7620bb1148a9e3 Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Thu, 26 Sep 2024 14:16:39 +0530 Subject: [PATCH 2/2] added changeset Signed-off-by: Abhinav Kumar --- .changeset/slow-rules-bow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/slow-rules-bow.md diff --git a/.changeset/slow-rules-bow.md b/.changeset/slow-rules-bow.md new file mode 100644 index 000000000000..3f9624f0470b --- /dev/null +++ b/.changeset/slow-rules-bow.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +This adjustment removes the deprecated `Mailer.sendMail` and `Mailer:unsubscribe` methods. Moving forward, use the `mailer` and `mailer.unsubscribe` endpoints.