-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: all emails in GEWIS template * chore: reorganize mail messages * wip: add separate class to apply HTML body to GEWIS template * chore: fix mails to adapt to new function specifications * fix: Mailer test cases * chore: remove old signatures * chore: add all mail messages to index
- Loading branch information
Showing
30 changed files
with
799 additions
and
488 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
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 |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
|
||
|
||
export { default } from './mailer'; | ||
export * from './templates'; | ||
export * from './messages'; |
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,47 @@ | ||
/** | ||
* SudoSOS back-end API service. | ||
* Copyright (C) 2024 Study association GEWIS | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import MailMessage, { Language, MailLanguageMap } from '../mail-message'; | ||
import MailContentBuilder from './mail-content-builder'; | ||
|
||
interface ChangedPinOptions {} | ||
|
||
const changedPinDutch = new MailContentBuilder<ChangedPinOptions>({ | ||
getHTML: '<p>De pincode van je account in SudoSOS is zojuist veranderd.</p>', | ||
getSubject: 'Je pincode is veranderd', | ||
getText: 'De pincode van je account in SudoSOS is zojuist veranderd.', | ||
getTitle: 'PIN gewijzigd', | ||
}); | ||
|
||
const changedPinEnglish = new MailContentBuilder<ChangedPinOptions>({ | ||
getSubject: 'Your PIN has changed', | ||
getText: 'The PIN number of your account in SudoSOS has just been changed.', | ||
getHTML: '<p>The PIN number of your account in SudoSOS has just been changed.</p>', | ||
getTitle: 'PIN changed', | ||
}); | ||
|
||
const mailContents: MailLanguageMap<ChangedPinOptions> = { | ||
[Language.DUTCH]: changedPinDutch, | ||
[Language.ENGLISH]: changedPinEnglish, | ||
}; | ||
|
||
export default class ChangedPin extends MailMessage<ChangedPinOptions> { | ||
public constructor(options: ChangedPinOptions) { | ||
super(options, mailContents); | ||
} | ||
} |
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,75 @@ | ||
/** | ||
* SudoSOS back-end API service. | ||
* Copyright (C) 2024 Study association GEWIS | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
type MailContentFunction<T> = string | ((context: T) => string); | ||
|
||
export interface MailContentFunctions<T> { | ||
getHTML: MailContentFunction<T>; | ||
getText: MailContentFunction<T>; | ||
getSubject: MailContentFunction<T>; | ||
|
||
/** | ||
* Short title used as the header in a templated email | ||
*/ | ||
getTitle: MailContentFunction<T>; | ||
|
||
/** | ||
* Short, bottom text explaining in the templated email why | ||
* the received got this email. | ||
*/ | ||
getReasonForEmail?: MailContentFunction<T>; | ||
} | ||
|
||
export interface MailContent { | ||
text: string; | ||
html: string; | ||
subject: string; | ||
/** | ||
* Short title used as the header in a templated email | ||
*/ | ||
title: string; | ||
/** | ||
* Short, bottom text explaining in the templated email why | ||
* the received got this email. | ||
*/ | ||
reason?: string; | ||
} | ||
|
||
export default class MailContentBuilder<T> { | ||
constructor(mail: MailContentFunctions<T>) { | ||
this.mail = mail; | ||
} | ||
|
||
protected mail: MailContentFunctions<T>; | ||
|
||
public getContent(context: T): MailContent { | ||
const text = typeof this.mail.getText === 'string' ? this.mail.getText : this.mail.getText(context); | ||
const html = typeof this.mail.getHTML === 'string' ? this.mail.getHTML : this.mail.getHTML(context); | ||
const subject = typeof this.mail.getSubject === 'string' ? this.mail.getSubject : this.mail.getSubject(context); | ||
const title = typeof this.mail.getTitle === 'string' ? this.mail.getTitle : this.mail.getTitle(context); | ||
|
||
let reason: string | undefined; | ||
if (this.mail.getReasonForEmail !== undefined && typeof this.mail.getReasonForEmail === 'string') { | ||
reason = this.mail.getReasonForEmail; | ||
} else if (this.mail.getReasonForEmail !== undefined && typeof this.mail.getReasonForEmail !== 'string') { | ||
reason = this.mail.getReasonForEmail(context); | ||
} | ||
|
||
return { text, html, subject, title, reason }; | ||
} | ||
} |
Oops, something went wrong.