-
Notifications
You must be signed in to change notification settings - Fork 85
Move user and customer updates into a transaction, managed by a module #501
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
Conversation
|
We discussed that we're going to need to change this to push out connect customer email changes, but that we won't store the email on our server. |
|
Marked as needs work but still needs code review, too. |
e4758b6 to
2c3bfca
Compare
|
I am marking as low priority at the moment and removing the needs code review for the time being. There is no mechanism right now for a user to update their email through Code Corps, and that's the only change going to Stripe. Once we allow users to change their email – or once we have time to circle back – we can reprioritize this. Let's not let it get out of date. We still need the change mentioned above. |
|
I think we actually need to finish this up. Was wrong. |
3beb43a to
f4e361e
Compare
|
I made some updates to this, so it ought to be ready for review. When a user updates, if the updates contain an e-mail,
Considering the amount of potential overlap with #508, I would prefer to merge this before touching #508 further. |
5a4d168 to
4107099
Compare
joshsmith
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments.
| {:error, _failed_operation, _failed_value, _changes_so_far} -> | ||
| {:error, :unhandled} | ||
| other -> | ||
| IO.inspect(other, pretty: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs removed. Is there an other case that needs handled?
|
|
||
| defp do_update(%Changeset{} = changeset) do | ||
| with {:ok, user} <- Repo.update(changeset) do | ||
| {:ok, user, :nothing_to_update, :nothing_to_update} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return nil and nil here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:nothing_to_update seems overly specific here whereas nil is just as descriptive, IMO.
web/controllers/user_controller.ex
Outdated
| |> Repo.update | ||
| |> CodeCorps.Analytics.Segment.track(:updated_profile, conn) | ||
| def handle_update(conn, record, attributes) do | ||
| with {:ok, user, _platform_customer_updates, _connect_customer_updates} <- UserService.update(record, attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just go unnamed on the nil returns here, straight _. See no harm in that and easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like the UserService.update should probably happen in an asynchronous task rather than sync here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can either do it in a transaction, meaning we have to wait for sync, or we ditch the transaction, update the user, respond with that and do the propagation async. I don't think we can do both.
|
|
||
| def update_changeset(struct, params) do | ||
| struct | ||
| |> cast(params, [:email]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no validate_required here? as there is with platform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That changeset should go away completely, actually. I added it by mistake, before realising there is nothing to update with the local record.
| {:ok, customer} = StripePlatformCustomerService.update(customer, %{email: "mail@mail.com"}) | ||
| assert customer.email == "mail@mail.com" | ||
|
|
||
| # TODO: Figure out testing if stripe API request was made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this TODO leftover or intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's intentional. I'm not sure how to check if a stripe API update was made. Maybe the function should return both the updated local record and the updated stripe record?
I'm starting to think we should avoid "side effects" in our functions as much as we can. I added a response containing updated platform and connect customer records to the user service for basically the same reason.
| Handles CRUD operations for users. | ||
| When operations happen on `CodeCorps.User`, we need to make sure changes | ||
| are propagated to related records, ex., `CodeCorps.StripePlatformCustomer` or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be and, right?
| """ | ||
|
|
||
| alias CodeCorps.{Repo, StripeConnectCustomer, StripePlatformCustomer, User} | ||
| alias CodeCorps.StripeService.{StripeConnectCustomerService,StripePlatformCustomerService} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after comma.
|
@begedin feel free to merge even if there are unresolved questions here, but if so (like the async task), open in another issue and reference this. |
c9d7c6e to
64f568e
Compare
…latform and connect customer updates
64f568e to
631b556
Compare
What's in this PR?
Adds a
UserManagermodule, which, for now, is placed under lib/code_corps/user_manager.ex, but ought to probably moved into a new namespace, together withDonationGoalsmanager.This module, for now, exposes an
updatefunction, which receives a user and a set of attributes.The
updatefunction behaves in the following way:To update the platform customer, I've also implemented
StripeService.StripePlatformCustomer.update/2, which handles updating of both the local and the API record.The scope of the PR was unclear to me, so I implemented the whole process. Based on the issue title alone, the assumption would be we just need to pass in the parameters during customer creation. However, the issue description also mentions keeping it up to date so "we can search by user email".
Questions:
References
Fixes #489