Skip to content

Commit

Permalink
feat: removed the verify feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustrb committed Aug 5, 2024
1 parent 397ef79 commit acd4da6
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 58 deletions.
6 changes: 3 additions & 3 deletions src/definition/accessors/IEmailCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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
* @param visitorId the id from the visitor
* @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
*/
sendOTPThroughSMTP(email: string, channel: string, visitorId: string): Promise<any>;
sendOTPThroughSMTP(email: string, code: string, language: string): Promise<any>;
}
11 changes: 0 additions & 11 deletions src/definition/accessors/IEmailReader.ts

This file was deleted.

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, channel: string, visitorId: string): Promise<any> {
return this.bridges.getEmailBridge().doSendOtpCodeThroughSMTP(email, channel, visitorId, this.appId);
public async sendOTPThroughSMTP(email: string, code: string, language: string): Promise<void> {
return this.bridges.getEmailBridge().doSendOtpCodeThroughSMTP(email, code, language, this.appId);
}
}
10 changes: 0 additions & 10 deletions src/server/accessors/EmailReader.ts

This file was deleted.

29 changes: 3 additions & 26 deletions src/server/bridges/EmailBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@ import { AppPermissions } from '../permissions/AppPermissions';
import { BaseBridge } from './BaseBridge';

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

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

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

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

private hasWritePermission(appId: string): boolean {
if (AppPermissionManager.hasPermission(appId, AppPermissions.email.sendOTP)) {
Expand All @@ -34,19 +26,4 @@ export abstract class EmailBridge extends BaseBridge {

return false;
}

private hasReadPermission(appId: string): boolean {
if (AppPermissionManager.hasPermission(appId, AppPermissions.email.verifyOTP)) {
return true;
}

AppPermissionManager.notifyAboutError(
new PermissionDeniedError({
appId,
missingPermissions: [AppPermissions.email.verifyOTP],
}),
);

return false;
}
}
1 change: 0 additions & 1 deletion src/server/permissions/AppPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const AppPermissions = {
},
email: {
sendOTP: { name: 'email.sendOTP' },
verifyOTP: { name: 'email.verifyOTP' },
},
ui: {
interaction: { name: 'ui.interact' },
Expand Down
6 changes: 1 addition & 5 deletions tests/test-data/bridges/emailBridge.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { EmailBridge } from '../../../src/server/bridges/EmailBridge';

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

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

0 comments on commit acd4da6

Please sign in to comment.