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

feat!: Use interceptor before stripping the recipients with the formatter #682

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tarzan
Copy link

@tarzan tarzan commented Oct 15, 2024

I would like to use the interceptor to detect the preferences of the rich struct that is set as a receiver on the 'to:'

The (implemented) formatter strips all info from this struct and just set a {name, email} tuple instead which I cannot use at the interceptor level anymore.

I decided to swap them: interceptor first normalization and validation second - can't think of a reason this would result in unwanted behavior.

Could you take this under consideration?

@tarzan tarzan requested a review from a team as a code owner October 15, 2024 16:16
Copy link
Member

@doomspork doomspork left a comment

Choose a reason for hiding this comment

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

Thank you @tarzan! I looked this over and left a quick comment on the test changes.

While I can't immediately think of a negative impact here, I do suspect this could have unintended consequences to current users of Bamboo and would require a breaking changes. If so, that would warrant some more conversation 🤔

Comment on lines +6 to +20
def call(%{to: recipients} = email) when is_list(recipients) do
if Enum.any?(recipients, &(&1 in @deny_list)) do
Bamboo.Email.block(email)
else
email
end
end

def call(%{to: recipient} = email) when recipient in @deny_list do
Bamboo.Email.block(email)
end

def call(email) do
email
end
Copy link
Member

Choose a reason for hiding this comment

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

Hi @tarzan can you walk me through this part of the change? It's not immediately clear why we made these changes other than to use multi-function heads instead of the prior solution.

Copy link
Author

Choose a reason for hiding this comment

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

Of course. Previously this interceptor (created for test scenario's) would expect the to: field to be populated by a list of tuples: {name, email}.
The actual test scenario's just put strings containing the email(s) on the to: field, so I had to check for a single binary that is an email or a list of binaries.

@doomspork doomspork requested a review from a team October 15, 2024 19:03
@tarzan
Copy link
Author

tarzan commented Oct 15, 2024

Thank you @tarzan! I looked this over and left a quick comment on the test changes.

While I can't immediately think of a negative impact here, I do suspect this could have unintended consequences to current users of Bamboo and would require a breaking changes. If so, that would warrant some more conversation 🤔

You are absolutely right, this is a breaking change. Any custom interceptors might expect a tuple [{name, email}] as the value of to: in the Bamboo.Email struct. With this change it will now contain the value that was actually set during the construction of the Bamboo.Email before formatting takes place.

In our case the value on to: is a %User{} struct that holds values of a user in our app, one of its fields is some preferences on whether the user would want to receive certain emails. Setting this fully populated User struct as the receiver of the email allows us to abstract checking of preferences to an Interceptor - which I think is conceptually the goal of an interceptor.

I can totally understand that current users that have spend time in constructing their own interceptors would not be to thrilled about this change. Would it help if I wrote some simple instructings on what to look for and how to apply these changes - ie something like a (mini) migration guide?

@tarzan tarzan changed the title Use interceptor before stripping the recipients with the formatter feat!: Use interceptor before stripping the recipients with the formatter Oct 15, 2024
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