Skip to content

Commit

Permalink
Removed Sender from service (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcadam14 authored Apr 4, 2024
1 parent 1ccf0d6 commit 1af8eeb
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 10 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ poetry run pytest

## API
The API endpoints require authentication to access. The service uses the [regtech-api-commons](https://github.com/cfpb/regtech-api-commons) library to utilize OAuth2 authentication, currently using Keycloak.
To use either endpoint, you must first get an access token from Keycloak. The service will then use the name and email attributes from the token to populate the Sender field in the email.
To use either endpoint, you must first get an access token from Keycloak. The Contact Name and Email, derived from the Access Token, will be put into the body of the email.

To get an access token, run the following curl command, using the Keycloak user you wish to test with (see [LOCAL_DEV_COMPOSE](https://github.com/cfpb/sbl-project/blob/main/LOCAL_DEV_COMPOSE.md) for launching Keycloak):

Expand Down Expand Up @@ -70,7 +70,6 @@ http://localhost:8765/send | jq '.'
"subject": "Institution Profile Change",
"body": "lei: 1234567890ABCDEFGHIJ\ninstitution_name_1: Fintech 1\ntin_1: 12-3456789\nrssd_1: 1234567",
"from_addr": "[email protected]",
"sender": "<Keycloak user> <<Keycloak email>>",
"to": [
"[email protected]"
],
Expand Down
4 changes: 1 addition & 3 deletions src/regtech_mail_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,14 @@ async def send_email(request: Request):
type = request.headers["case-type"]
subject = f"[DEV BETA] SBL User Request for {type}"

sender = f"{sender_name} <{sender_addr}>" if sender_name else sender_addr

form_data = await request.form()

body_lines = [f"{k}: {v}" for k, v in form_data.items()]
email_body = f"Contact Email: {sender_addr}\n"
email_body += f"Contact Name: {sender_name}\n\n"
email_body += "\n".join(body_lines)

email = Email(subject, email_body, settings.from_addr, sender, to={settings.to})
email = Email(subject, email_body, settings.from_addr, to={settings.to})

mailer.send(email)

Expand Down
2 changes: 0 additions & 2 deletions src/regtech_mail_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Email:
subject: str
body: str
from_addr: str
sender: str
to: set[str]
cc: set[str] | None = None
bcc: set[str] | None = None
Expand All @@ -16,7 +15,6 @@ def to_email_message(self) -> EmailMessage:
message = EmailMessage()
message["Subject"] = self.subject
message["From"] = self.from_addr
message["Sender"] = self.sender
message["To"] = ",".join(self.to)

if self.cc:
Expand Down
1 change: 0 additions & 1 deletion tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def test_authed_endpoints(
"subject": "Institution Profile Change",
"body": "lei: 1234567890ABCDEFGHIJ\ninstitution_name_1: Fintech 1\ntin_1: 12-3456789\nrssd_1: 1234567",
"from_addr": "[email protected]",
"sender": "Jane Doe <[email protected]>",
"to": ["[email protected]"],
"cc": None,
"bcc": None,
Expand Down
2 changes: 0 additions & 2 deletions tests/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def test_send_no_profile(
"subject": "[DEV BETA] SBL User Request for Institution Profile Change",
"body": "Contact Email: [email protected]\nContact Name: \n\nlei: 1234567890ABCDEFGHIJ\ninstitution_name_1: Fintech 1\ntin_1: 12-3456789\nrssd_1: 1234567",
"from_addr": "[email protected]",
"sender": "[email protected]",
"to": ["[email protected]"],
"cc": None,
"bcc": None,
Expand Down Expand Up @@ -91,7 +90,6 @@ def test_send(
"subject": "[DEV BETA] SBL User Request for Institution Profile Change",
"body": "Contact Email: [email protected]\nContact Name: Test User\n\nlei: 1234567890ABCDEFGHIJ\ninstitution_name_1: Fintech 1\ntin_1: 12-3456789\nrssd_1: 1234567",
"from_addr": "[email protected]",
"sender": "Test User <[email protected]>",
"to": ["[email protected]"],
"cc": None,
"bcc": None,
Expand Down

0 comments on commit 1af8eeb

Please sign in to comment.