Skip to content

Commit

Permalink
chore: add the channel as an identifier for the email bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustrb committed Aug 5, 2024
1 parent 76b7677 commit 96c29d0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/definition/accessors/IEmailCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface IEmailCreator {
* Sends an OTP through the configured SMTP server within Rocket.Chat
*
* @param email the email that will recieve the TOTP
* @param channel from which type of channel is the visitor verifying
*/
sendOTPThroughSMTP(email: string): Promise<any>;
sendOTPThroughSMTP(email: string, channel: string): Promise<any>;
}
3 changes: 2 additions & 1 deletion src/definition/accessors/IEmailReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface IEmailReader {
*
* @param code the code that is going to be verified
* @param email the email the code was sent
* @param channel from which channel is the visitor verifying
*/
verifyOTPCode(code: string, email: string): Promise<any>;
verifyOTPCode(code: string, email: string, channel: string): Promise<any>;
}
4 changes: 2 additions & 2 deletions src/server/accessors/EmailCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { IEmailCreator } from '../../definition/accessors/IEmailCreator';
export class EmailCreator implements IEmailCreator {
constructor(private readonly bridges: AppBridges, private readonly appId: string) {}

public async sendOTPThroughSMTP(email: string): Promise<any> {
return this.bridges.getEmailBridge().doSendOtpCodeThroughSMTP(email, this.appId);
public async sendOTPThroughSMTP(email: string, channel: string): Promise<any> {
return this.bridges.getEmailBridge().doSendOtpCodeThroughSMTP(email, channel, this.appId);
}
}
4 changes: 2 additions & 2 deletions src/server/accessors/EmailReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { AppBridges } from '../bridges';
export class EmailReader implements IEmailReader {
constructor(private readonly bridges: AppBridges, private readonly appId: string) {}

public async verifyOTPCode(code: string, email: string): Promise<any> {
return this.bridges.getEmailBridge().doVerifyOTPCode(code, email, this.appId);
public async verifyOTPCode(code: string, channel: string, email: string): Promise<any> {
return this.bridges.getEmailBridge().doVerifyOTPCode(code, email, channel, this.appId);
}
}
12 changes: 6 additions & 6 deletions src/server/bridges/EmailBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { AppPermissions } from '../permissions/AppPermissions';
import { BaseBridge } from './BaseBridge';

export abstract class EmailBridge extends BaseBridge {
public async doSendOtpCodeThroughSMTP(email: string, appId: string): Promise<any> {
public async doSendOtpCodeThroughSMTP(email: string, channel: string, appId: string): Promise<any> {
if (this.hasWritePermission(appId)) {
return this.sendOtpCodeThroughSMTP(email, appId);
return this.sendOtpCodeThroughSMTP(email, channel, appId);
}
}

public async doVerifyOTPCode(code: string, email: string, appId: string): Promise<any> {
public async doVerifyOTPCode(code: string, email: string, channel: string, appId: string): Promise<any> {
if (this.hasReadPermission(appId)) {
return this.verifyOTPCode(code, email, appId);
return this.verifyOTPCode(code, email, channel, appId);
}
}

protected abstract sendOtpCodeThroughSMTP(email: string, appId: string): Promise<any>;
protected abstract sendOtpCodeThroughSMTP(email: string, channel: string, appId: string): Promise<any>;

protected abstract verifyOTPCode(code: string, email: string, appId: string): Promise<any>;
protected abstract verifyOTPCode(code: string, email: string, channel: string, appId: string): Promise<any>;

private hasWritePermission(appId: string): boolean {
if (AppPermissionManager.hasPermission(appId, AppPermissions.email.sendOTP)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/test-data/bridges/emailBridge.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EmailBridge } from '../../../src/server/bridges/EmailBridge';

export class TestsEmailBridge extends EmailBridge {
protected verifyOTPCode(code: string, email: string, appId: string): Promise<any> {
protected verifyOTPCode(code: string, channel: string, email: string, appId: string): Promise<any> {
throw new Error('Method not implemented.');
}

protected sendOtpCodeThroughSMTP(email: string, appId: string): Promise<any> {
protected sendOtpCodeThroughSMTP(email: string, channel: string, appId: string): Promise<any> {
throw new Error('Method not implemented.');
}
}

0 comments on commit 96c29d0

Please sign in to comment.