diff --git a/src/definition/accessors/IEmailCreator.ts b/src/definition/accessors/IEmailCreator.ts index e3eb7a2ce..894f243de 100644 --- a/src/definition/accessors/IEmailCreator.ts +++ b/src/definition/accessors/IEmailCreator.ts @@ -1,10 +1,10 @@ +import type { IEmailDescriptor } from '../email'; + export interface IEmailCreator { /** - * Sends an OTP through the configured SMTP server within Rocket.Chat + * Sends an email through Rocket.Chat * - * @param email the email that will recieve the TOTP - * @param code is the code that is going to be sent via email - * @param language is the language that is going to be used within Rocket.Chat + * @param email the email data */ - sendOTPThroughSMTP(email: string, code: string, language: string): Promise; + send(email: IEmailDescriptor): Promise; } diff --git a/src/server/accessors/EmailCreator.ts b/src/server/accessors/EmailCreator.ts index 747d7c37c..4b3a324d5 100644 --- a/src/server/accessors/EmailCreator.ts +++ b/src/server/accessors/EmailCreator.ts @@ -1,10 +1,11 @@ import type { AppBridges } from '../bridges'; import type { IEmailCreator } from '../../definition/accessors/IEmailCreator'; +import type { IEmailDescriptor } from '../../definition/email'; export class EmailCreator implements IEmailCreator { constructor(private readonly bridges: AppBridges, private readonly appId: string) {} - public async sendOTPThroughSMTP(email: string, code: string, language: string): Promise { - return this.bridges.getEmailBridge().doSendOtpCodeThroughSMTP(email, code, language, this.appId); + public async send(email: IEmailDescriptor): Promise { + return this.bridges.getEmailBridge().doSendEmail(email, this.appId); } } diff --git a/src/server/bridges/EmailBridge.ts b/src/server/bridges/EmailBridge.ts index d36c153e2..6cf98a147 100644 --- a/src/server/bridges/EmailBridge.ts +++ b/src/server/bridges/EmailBridge.ts @@ -1,26 +1,27 @@ +import type { IEmailDescriptor } from '../../definition/email'; import { PermissionDeniedError } from '../errors/PermissionDeniedError'; import { AppPermissionManager } from '../managers/AppPermissionManager'; import { AppPermissions } from '../permissions/AppPermissions'; import { BaseBridge } from './BaseBridge'; export abstract class EmailBridge extends BaseBridge { - public async doSendOtpCodeThroughSMTP(email: string, code: string, language: string, appId: string): Promise { + public async doSendEmail(email: IEmailDescriptor, appId: string): Promise { if (this.hasWritePermission(appId)) { - return this.sendOtpCodeThroughSMTP(email, code, language, appId); + return this.sendEmail(email, appId); } } - protected abstract sendOtpCodeThroughSMTP(email: string, code: string, language: string, appId: string): Promise; + protected abstract sendEmail(email: IEmailDescriptor, appId: string): Promise; private hasWritePermission(appId: string): boolean { - if (AppPermissionManager.hasPermission(appId, AppPermissions.email.sendOTP)) { + if (AppPermissionManager.hasPermission(appId, AppPermissions.email.send)) { return true; } AppPermissionManager.notifyAboutError( new PermissionDeniedError({ appId, - missingPermissions: [AppPermissions.email.sendOTP], + missingPermissions: [AppPermissions.email.send], }), ); diff --git a/src/server/bridges/index.ts b/src/server/bridges/index.ts index 5ecfcd96d..f5550e96f 100644 --- a/src/server/bridges/index.ts +++ b/src/server/bridges/index.ts @@ -4,6 +4,7 @@ import { AppBridges } from './AppBridges'; import { AppDetailChangesBridge } from './AppDetailChangesBridge'; import { CloudWorkspaceBridge } from './CloudWorkspaceBridge'; import { CommandBridge } from './CommandBridge'; +import { EmailBridge } from './EmailBridge'; import { EnvironmentalVariableBridge } from './EnvironmentalVariableBridge'; import { HttpBridge, IHttpBridgeRequestInfo } from './HttpBridge'; import { IInternalBridge } from './IInternalBridge'; @@ -40,6 +41,7 @@ export { ServerSettingBridge, UserBridge, UploadBridge, + EmailBridge, UiInteractionBridge, SchedulerBridge, AppBridges, diff --git a/src/server/permissions/AppPermissions.ts b/src/server/permissions/AppPermissions.ts index c2bc09654..a0cc643c7 100644 --- a/src/server/permissions/AppPermissions.ts +++ b/src/server/permissions/AppPermissions.ts @@ -26,7 +26,7 @@ export const AppPermissions = { write: { name: 'upload.write' }, }, email: { - sendOTP: { name: 'email.sendOTP' }, + send: { name: 'email.send' }, }, ui: { interaction: { name: 'ui.interact' }, diff --git a/tests/test-data/bridges/emailBridge.ts b/tests/test-data/bridges/emailBridge.ts index c75334ac5..563d6983d 100644 --- a/tests/test-data/bridges/emailBridge.ts +++ b/tests/test-data/bridges/emailBridge.ts @@ -1,7 +1,8 @@ +import type { IEmailDescriptor } from '../../../src/definition/email'; import { EmailBridge } from '../../../src/server/bridges/EmailBridge'; export class TestsEmailBridge extends EmailBridge { - protected sendOtpCodeThroughSMTP(email: string, code: string, language: string): Promise { + protected sendEmail(email: IEmailDescriptor, appId: string): Promise { throw new Error('Method not implemented.'); } }