-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'alpha' into sync/1.46.0-alpha
- Loading branch information
Showing
13 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { IEmail } from '../email'; | ||
|
||
export interface IEmailCreator { | ||
/** | ||
* Sends an email through Rocket.Chat | ||
* | ||
* @param email the email data | ||
*/ | ||
send(email: IEmail): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface IEmail { | ||
to: string | string[]; | ||
from: string; | ||
replyTo?: string; | ||
subject: string; | ||
html?: string; | ||
text?: string; | ||
headers?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './IEmailDescriptor'; | ||
export * from './IPreEmailSent'; | ||
export * from './IPreEmailSentContext'; | ||
export * from './IEmail'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { AppBridges } from '../bridges'; | ||
import type { IEmailCreator } from '../../definition/accessors/IEmailCreator'; | ||
import type { IEmail } from '../../definition/email'; | ||
|
||
export class EmailCreator implements IEmailCreator { | ||
constructor(private readonly bridges: AppBridges, private readonly appId: string) {} | ||
|
||
public async send(email: IEmail): Promise<void> { | ||
return this.bridges.getEmailBridge().doSendEmail(email, this.appId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { IEmail } 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 doSendEmail(email: IEmail, appId: string): Promise<void> { | ||
if (this.hasWritePermission(appId)) { | ||
return this.sendEmail(email, appId); | ||
} | ||
} | ||
|
||
protected abstract sendEmail(email: IEmail, appId: string): Promise<void>; | ||
|
||
private hasWritePermission(appId: string): boolean { | ||
if (AppPermissionManager.hasPermission(appId, AppPermissions.email.send)) { | ||
return true; | ||
} | ||
|
||
AppPermissionManager.notifyAboutError( | ||
new PermissionDeniedError({ | ||
appId, | ||
missingPermissions: [AppPermissions.email.send], | ||
}), | ||
); | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { IEmail } from '../../../src/definition/email'; | ||
import { EmailBridge } from '../../../src/server/bridges/EmailBridge'; | ||
|
||
export class TestsEmailBridge extends EmailBridge { | ||
protected sendEmail(email: IEmail, appId: string): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |