-
Notifications
You must be signed in to change notification settings - Fork 809
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
Connection: move the connection owner deletion notice to the Connection package #17136
Conversation
…on package A notice displays when a user attempts to delete the connection owner. Move this notice and the endpoint for setting the connection owner to the connection package. With this change, the connection owner deletion notice will be displayed for all consumers of the connection package.
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.
Here are some suggested test cases for this PR.
Connection
- In-place connection with free plan
- In-place connection with paid plan
- In-place connection with product purchase
- Classic connection. Use Safari, or set a constant
JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME
to true - Disconnect/reconnect connection
- Secondary user connection
- Connection on multisite
If you think that suggestions should be improved please edit the configuration file here. You can also modify/add test-suites to be used in the configuration file.
Scheduled Jetpack release: October 6, 2020. E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-17136 Thank you for the great PR description! When this PR is ready for review, please apply the |
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 tested well for me. 🚢
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.
Asking a few questions to try to understand this better.
$.ajax( { | ||
type : "POST", | ||
url : "<?php echo esc_url( get_rest_url() . 'jetpack/v4/connection/owner' ); ?>", | ||
data : formData, | ||
headers : { | ||
'X-WP-Nonce': "<?php echo esc_js( wp_create_nonce( 'wp_rest' ) ); ?>", | ||
}, | ||
success: function() { | ||
results.innerHTML = "<?php esc_html_e( 'Success!', 'jetpack' ); ?>"; | ||
setTimeout( function() { | ||
$( '#jetpack-notice-switch-connection-owner' ).hide( 'slow' ); | ||
}, 1000 ); | ||
}, | ||
} ).done( function() { | ||
submitBtn.disabled = false; | ||
} ); |
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 don't see any error handling in this ajax call, it looks like if it fails it'll just sit there forever with a disabled button, never informing the user. Am I missing something?
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.
In commit e6540b8, I added error handling to the Ajax call. If the call fails, an error message will be displayed and the button will be enabled.
@@ -960,40 +960,78 @@ public function test_fetch_not_registered_widget_data() { | |||
} | |||
|
|||
/** | |||
* Test changing the master user. | |||
* Test changing the master user without the owner parameter. |
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.
Do these tests still belong here, or should they be moved along with the implementation of the endpoint they're testing?
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 don't think it's currently possible to implement these tests in the Connection package tests. These tests require creating users and saving them in the database. The Connection package tests do not run in a full WordPress environment with a database. Instead, they use the WorDBless package, which provides WordPress core functions without a database.
So, I left the tests the require a WordPress environment in the Jetpack plugin's tests and added a few tests that do not require the WordPress environment to the Connection package.
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.
Hmm. I see test_change_owner_with_permission()
is able to have a current user that has the necessary capability to get into set_connection_owner()
.
Looks like test_change_owner_with_invalid_param()
tests the same thing as test_change_owner_with_permission()
. It's just calling into the code differently.
It looks like test_change_owner_with_bad_user()
is trying to change to a nonexistent ID, which seems like it should work the same there too.
test_change_owner_to_same_user()
is trying to change to the same user, which again should work the same there.
The last test, test_change_owner_to_valid_user()
, does seem to need an actual second user, which wordbless doesn't seem to support yet other than by low-level hacking up of the DB queries.
- Remove the `method_exists` check for Tracking:::record_user_event. - Add error handling for the Ajax request. - Use Tracking::class insstead of the full class name. - Remove a duplicate unit test and update the unit test comments.
@@ -960,40 +960,78 @@ public function test_fetch_not_registered_widget_data() { | |||
} | |||
|
|||
/** | |||
* Test changing the master user. | |||
* Test changing the master user without the owner parameter. |
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.
Hmm. I see test_change_owner_with_permission()
is able to have a current user that has the necessary capability to get into set_connection_owner()
.
Looks like test_change_owner_with_invalid_param()
tests the same thing as test_change_owner_with_permission()
. It's just calling into the code differently.
It looks like test_change_owner_with_bad_user()
is trying to change to a nonexistent ID, which seems like it should work the same there too.
test_change_owner_to_same_user()
is trying to change to the same user, which again should work the same there.
The last test, test_change_owner_to_valid_user()
, does seem to need an actual second user, which wordbless doesn't seem to support yet other than by low-level hacking up of the DB queries.
submitBtn.disabled = false; | ||
} ).fail( function() { | ||
results.classList.add( 'error-message' ); | ||
results.innerHTML = "<?php esc_html_e( 'Something went wrong. Please try again.', 'jetpack' ); ?>"; |
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.
Honest question: Is this the preferred behavior for error reporting? My inclination would be to try to relay a more specific message from the endpoint. But maybe that would be more confusing for a typical user?
This PR has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this PR has clear testing instructions, is it up to date with master, and it is still valid. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation. |
I'll close this PR for now because of the lack of activity on this. We can always reopen in the future if needed, but it will need a rebase, so it may be easier to start a new PR at this point. |
A notice displays when a user attempts to delete the connection owner. Move this notice and the endpoint for setting the connection owner to the connection package. With this change, the connection owner deletion notice will be displayed for all consumers of the connection package.
Fixes #15568
Changes proposed in this Pull Request:
delete_user_update_connection_owner_notice
method from the JITM package to the Connection package./connection/owner
endpoint, including the callback and permission callback, to the Connection package.Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
Attempt to delete the connection owner with a logged-out admin.
Users -> Add New
and create another administrator user. This user is the secondary admin. Don't connect this user yet.Connect to WordPress.com
button to connect the secondary admin to WPCOM.Set new connection owner
button to change the connection owner. (Don't delete the primary admin user, because we'll switch the connection owner back to that user in the next test.)Tools -> Site Health
, selecting theInfo
tab, and opening the Jetpack drop-down. TheJetpack Master User
(aka connection owner) should be the secondary admin.Attempt to delete the connection owner with a logged-in admin.
Set new connection owner
button in the notice. Click that button.Tools -> Site Health
, selecting theInfo
tab, and opening the Jetpack drop-down. TheJetpack Master User
(aka connection owner) should be the primary admin.After conducting these tests, verify that no errors were generated in the debug.log. You can also verify that the
jetpack_connection_owner_notice_view
andjetpack_set_connection_owner_success
tracks events were recorded.Verify that the
connection/owner
endpoint checks user permissions properly.jetpack/v4/connection/owner
endpoint while not logged in.invalid_user_permission_set_connection_owner
.Proposed changelog entry for your changes: