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

Draft: Email notifications #31

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

GreatDanton
Copy link
Collaborator

Work in progress

Copy link
Contributor

@tangkong tangkong left a comment

Choose a reason for hiding this comment

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

I do more python so I'm more helpful in this review 😆

I know this is a draft but I just wanted to drop a few thoughts in. I think the basic structure of this makes sense 👍

context.py Show resolved Hide resolved
notifications/email_sender.py Show resolved Hide resolved
notifications/email_sender.py Outdated Show resolved Hide resolved
if False and status: # NOTE: this endpoint works, but we don't have approver's emails
project_name = prj["name"]
project_id = prj["_id"]
# @TODO: we need a way to access approver users email
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the user names that we pass through to the flaskauthnz authorization are also the email addresses @slac.stanford.edu I'll go back and verify this

start.py Outdated
app.config["NOTIFICATIONS"] = {"service_url": "http://localhost:3000"}

# read credentials file for notifications module
credentials_file = "./credentials.ini"
Copy link
Contributor

Choose a reason for hiding this comment

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

Note for our future selves, we probably want a place (optional argument or otherwise) to specify where this credentials file is

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we should look towards moving environment variables into a config file (which currently does not exist), as otherwise you lose track of what is even possible to configure and you have to dig into the source code.

start.py Show resolved Hide resolved
self.email_sender = EmailSender(email_config)
self.service_url = service_url

def notify_project_approver(self, approver_emails: [], project_name: str, project_id: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

Mutable default arguments here as well.

Is the intention to make a new method for each notification type we're sending? It might be worth just having a single send_notification method that we provide a type to, then gather all the notification templates in a dictionary elsewhere.

We could make the notification types an Enum, to keep the options limited

Copy link
Collaborator Author

@GreatDanton GreatDanton Nov 5, 2024

Choose a reason for hiding this comment

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

Yes the initial idea was that each type of notification would have its own method, but that's up for a discussion.

Having a single method handling all integration points could be a bit problematic. The problem is that different notifications will need a different message format:

  • email clients expect html formatting (and sometimes even plain text) as well as an email subject and the sender's username (e.g., Slac NoReply) that will be shown in an email client

  • services like Slack expect a message in markdown, the name of the chat room and probably no subject. If notifying specific people is expected, then we need to somehow associate users with their Slack username (if they even have an account).

  • Jira and friends probably expect something completely different (e.g., an issue id number).

Therefore, if we ever expect to extend the notifier, I guess we should have one method handling each of the integration points (due to their specific differences):

notifier.send_emails(from, users, approve_user_subject, approve_user_email_msg.format(var1, var))
notifier.send_slack_msg(users, approve_user_slack_msg.format(var1, var2))

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm on board with the one-method-per-destination. Since the only thing that changes within one destination is the message contents, it didn't really make sense to duplicate the methods to me. This seems like a good amount of de-duplication for now. (maybe there could be more, but that can be a later optimization)

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.

2 participants