Skip to content

Commit

Permalink
Tweaks for send_email (#1786)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Oct 18, 2024
1 parent aa16958 commit e33b888
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pay-api/src/pay_api/models/eft_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def find_refunds(cls, statuses: List[str], short_name_id: int = None):
"""Return all refunds by status."""
query = cls.query
if statuses:
query = cls.query.filter(EFTRefund.status.in_(statuses))
query = query.filter(EFTRefund.status.in_(statuses))
if short_name_id:
query = cls.query.filter(EFTRefund.short_name_id == short_name_id)
query = query.filter(EFTRefund.short_name_id == short_name_id)
return query.all()
7 changes: 4 additions & 3 deletions pay-api/src/pay_api/services/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""This manages all of the authorization service."""
import base64
from typing import List

from flask import abort, current_app, g

Expand Down Expand Up @@ -148,13 +149,13 @@ def get_account_admin_users(auth_account_id, **kwargs):
).json()


def get_emails_with_keycloak_role(role: str) -> str:
def get_emails_with_keycloak_role(role: str) -> List[str]:
"""Retrieve emails with the specified keycloak role."""
users = get_users_with_keycloak_role(role)
# Purpose of this is so our TEST users don't get hammered with emails, also our tester can easily switch this on.
if flags.is_on("override-eft-refund-emails", default=False):
return flags.value("override-eft-refund-emails")
return ",".join([user["email"] for user in users])
return flags.value("override-eft-refund-emails").split(",")
return [user["email"] for user in users]


def get_users_with_keycloak_role(role: str) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/services/eft_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def update_shortname_refund(refund_id: int, data: EFTShortNameRefundPatchRequest
staff_body = content.render_body()
expense_authority_recipients = get_emails_with_keycloak_role(Role.EFT_REFUND_APPROVER.value)
send_email(expense_authority_recipients, subject, staff_body)
client_recipients = refund.refund_email
client_recipients = [refund.refund_email]
client_body = content.render_body(is_for_client=True)
send_email(client_recipients, subject, client_body)
case _:
Expand Down
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/services/email_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pay_api.utils.serializable import Serializable


def send_email(recipients: list, subject: str, body: str):
def send_email(recipients: list[str], subject: str, body: str):
"""Send the email notification."""
# Note if we send HTML in the body, we aren't sending through GCNotify, ideally we'd like to send through GCNotify.
token = get_service_account_token()
Expand Down

0 comments on commit e33b888

Please sign in to comment.