-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refactor updating user role to save local user asynchronously #20244
Conversation
You can test the changes in WordPress from this Pull Request by:
|
You can test the changes in Jetpack from this Pull Request by:
|
enum PeopleServiceError: Error { | ||
case userNotFoundLocally(User) | ||
} |
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.
What do you think of making this a nested type?
extension PeopleService {
enum Error: Swift.Error {
Probably not worth it because then every existing Error
usage in this file should be updated to Swift.Error
to avoid clashing.
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.
Yeah, that's why I didn't put the new Error
type under PeopleService
.
case let .failure(error): | ||
failure?(error, user) |
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.
Just to confirm I'm reading the diff correctly, this is a new behavior from the previous code and runs with error
equal .userNotFoundLocally
if managedPersonFromPerson(_:, in:)
doesn't find a match.
In the previous version, instead, the app would have called crashed when failure?(error, reloadedPerson)
because no value would have been assigned to var reloadedPerson: User!
due to the early return.
Is that correct?
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.
The app wouldn't crash, but neither the success
nor the failure
block would be called. With this new behaviour, as you noted, the failures
will be called if couldn't find the ManagedPerson
.
However, I don't think this error would actually happen though, since this function is called immediately after the user changes the ManagerPerson
instance's role on UI, it's not likely that the ManagedPerson
is deleted in that split second.
Similar to #20239, but this PR only changes the synchronous
performAndSave
to asynchronous one just in one place, since the diff is a bit messy. See pbArwn-5Qy-p2#how-does-this-apply-to-the-wp-and-jp-ios-apps for detailed reasoning.Test instructions
Go to My Sites -> People, invite new user and edit their role. Make sure the role is updated correctly.
Regression Notes
Potential unintended areas of impact
None. As the refactored function is only used in the "People" screen.
What I did to test those areas of impact (or what existing automated tests I relied on)
What described in the "Test instructions"
What automated tests I added (or what prevented me from doing so)
None.
PR submission checklist:
RELEASE-NOTES.txt
if necessary.