From 2e27452da32255b1914ba0863fcbda2329038105 Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Fri, 18 Oct 2024 13:54:29 -0700 Subject: [PATCH 1/4] tweaks for send_email --- pay-api/src/pay_api/services/auth.py | 7 ++++--- pay-api/src/pay_api/services/eft_refund.py | 2 +- pay-api/src/pay_api/services/email_service.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pay-api/src/pay_api/services/auth.py b/pay-api/src/pay_api/services/auth.py index 29768f75c..7143799df 100644 --- a/pay-api/src/pay_api/services/auth.py +++ b/pay-api/src/pay_api/services/auth.py @@ -14,6 +14,7 @@ """This manages all of the authorization service.""" import base64 +from typing import List from flask import abort, current_app, g @@ -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: diff --git a/pay-api/src/pay_api/services/eft_refund.py b/pay-api/src/pay_api/services/eft_refund.py index 50f41aa4f..8a671f9a7 100644 --- a/pay-api/src/pay_api/services/eft_refund.py +++ b/pay-api/src/pay_api/services/eft_refund.py @@ -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 _: diff --git a/pay-api/src/pay_api/services/email_service.py b/pay-api/src/pay_api/services/email_service.py index d5328b340..11ccc826e 100644 --- a/pay-api/src/pay_api/services/email_service.py +++ b/pay-api/src/pay_api/services/email_service.py @@ -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() From b67c187ce11a36dd0e1ff9013a8acb09f4c97a71 Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Fri, 18 Oct 2024 13:55:01 -0700 Subject: [PATCH 2/4] lint fix --- pay-api/src/pay_api/services/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pay-api/src/pay_api/services/auth.py b/pay-api/src/pay_api/services/auth.py index 7143799df..e12b78177 100644 --- a/pay-api/src/pay_api/services/auth.py +++ b/pay-api/src/pay_api/services/auth.py @@ -154,7 +154,7 @@ def get_emails_with_keycloak_role(role: str) -> List[str]: 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").split(',') + return flags.value("override-eft-refund-emails").split(",") return [user["email"] for user in users] From 6205ee4c0c22f60c175273394744bdca0df1e639 Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Fri, 18 Oct 2024 13:59:17 -0700 Subject: [PATCH 3/4] Fix id filter --- pay-api/src/pay_api/models/eft_refund.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pay-api/src/pay_api/models/eft_refund.py b/pay-api/src/pay_api/models/eft_refund.py index 82d5e0e2e..88cb717b3 100644 --- a/pay-api/src/pay_api/models/eft_refund.py +++ b/pay-api/src/pay_api/models/eft_refund.py @@ -79,5 +79,5 @@ def find_refunds(cls, statuses: List[str], short_name_id: int = None): if statuses: query = cls.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() From 612f0e21de533f9152e675a27510d9ba07c2787d Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Fri, 18 Oct 2024 14:00:52 -0700 Subject: [PATCH 4/4] 1 more filter --- pay-api/src/pay_api/models/eft_refund.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pay-api/src/pay_api/models/eft_refund.py b/pay-api/src/pay_api/models/eft_refund.py index 88cb717b3..e6b88f6bb 100644 --- a/pay-api/src/pay_api/models/eft_refund.py +++ b/pay-api/src/pay_api/models/eft_refund.py @@ -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 = query.filter(EFTRefund.short_name_id == short_name_id) return query.all()