Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send email when new passlist entry is added #2087

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

rfontanarosa
Copy link
Collaborator

@rfontanarosa rfontanarosa commented Nov 12, 2024

closes #2077

Screenshot 2024-12-11 alle 15 58 55

@rfontanarosa rfontanarosa changed the title Rfontanarosa/2077/feature user access granted notification Email notification when new passlist entry is added Nov 12, 2024
@gino-m gino-m changed the title Email notification when new passlist entry is added Send email when new passlist entry is added Nov 17, 2024
@rfontanarosa rfontanarosa self-assigned this Nov 29, 2024
@gino-m
Copy link
Collaborator

gino-m commented Dec 10, 2024

@rfontanarosa Any updates on this PR?

@rfontanarosa rfontanarosa requested a review from gino-m December 11, 2024 15:02
@rfontanarosa rfontanarosa marked this pull request as ready for review December 11, 2024 15:02
Copy link
Collaborator

@gino-m gino-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions

functions/src/common/context.ts Outdated Show resolved Hide resolved
functions/src/common/context.ts Outdated Show resolved Hide resolved
functions/src/common/context.ts Outdated Show resolved Hide resolved
functions/src/common/datastore.ts Outdated Show resolved Hide resolved
functions/src/common/mail-service.ts Show resolved Hide resolved
functions/src/common/mail-service.ts Outdated Show resolved Hide resolved
functions/src/common/mail-service.ts Outdated Show resolved Hide resolved
functions/src/common/mail-service.ts Show resolved Hide resolved
functions/src/common/utils.ts Show resolved Hide resolved
functions/src/on-create-passlist-entry.ts Outdated Show resolved Hide resolved
@rfontanarosa rfontanarosa requested a review from gino-m December 13, 2024 15:07
host: string;
port: number;
username: string;
password: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we be storing the password in plain-text? This sounds like a big risk. Does the mail server offer some sort of auth token or other mechanism for authenticating?

export interface MailServiceEmail {
to: string;
subject: string;
html: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/html/template/? That way we can also introduce Markdown in the future without breaking the name, and it will also make it clear there can be placeholders?


await new Promise<void>((resolve, reject) => {
this.transporter_.sendMail(
{from: this.sender_, ...email, html: safeHtnl},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: safeHtnl

if (error) {
// 501 and 550 are errors from the mail server: email address not found
if (error.responseCode === 501 || error.responseCode === 550) {
reject(new Error(error.response));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just reject(error) in both cases?

db: Datastore
): Promise<MailServerConfig | undefined> {
const mailConfig = (await db.fetchMailConfig()) as MailConfig;
if (!mailConfig) console.error('Unable to find mail configuration');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really an error if an instance of Ground doesn't have a mail serve? Assuming it's optional, perhaps this should be a debug log message instead.

if (!mailConfig) console.error('Unable to find mail configuration');
const {server: mailServerConfig} = mailConfig;
if (!mailServerConfig)
console.error('Mail server config not found in /config/mail/server');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the if branch doesn't return this code will log an error twice. Let's instead use !mailConfig?.mailServerConfig to check and log once?

import {MailServiceEmail} from './common/mail-service';
import {stringFormat} from './common/utils';

export async function onCreatePasslistEntryHandler(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add TSDoc at least to all public methods and classes.

const template = await db.fetchMailTemplate('passlisted');

if (!template) {
console.error('Template not found in /config/mail/templates/passlisted');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Template/Passlist notification email template/

Also, if this is an optional feature, reduce the to console.debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Auth] Send an email to user when added to passlist
2 participants