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

User invitation: Mail the newly added user with WPCom invite #35234

Merged
merged 14 commits into from
Jan 29, 2024

Conversation

renancarvalho
Copy link
Contributor

@renancarvalho renancarvalho commented Jan 24, 2024

Fixes Automattic/wp-calypso#86737 and Automattic/wp-calypso#86738
This is part of the pdDR7T-1ja-p2

Proposed changes:

Currently, when adding a new user to a site via wp-admin, it only creates the user in the site context (locally) therefore these users a not mapped as WPCom users.
This PR:

  • improves it by intercepting the core email functionality and sending an invitation to the user via email. Once accepted, the user will not only be a local user but a WPCom user.
  • It informs the site owner that the invite will be sent.

Testing instructions:

  • Pull this branch
  • Sync the changes with your atomic site sync jetpack rsync
  • Navigate to your atomic site {YOUR_SITE}/wp-admin/user-new.php
  • You should see this message informing about the email invitation
image - When adding a new user, the user should get an email invite image

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Copy link
Contributor

github-actions bot commented Jan 24, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the improve_invite_form branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack improve_invite_form
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress labels Jan 24, 2024
Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for February 6, 2024 (scheduled code freeze on February 5, 2024).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@renancarvalho renancarvalho self-assigned this Jan 25, 2024
@renancarvalho renancarvalho changed the title User invitation: Mail the newly added user User invitation: Mail the newly added user with WPCom invite Jan 25, 2024
@renancarvalho renancarvalho marked this pull request as ready for review January 25, 2024 10:55
Copy link
Member

@alshakero alshakero left a comment

Choose a reason for hiding this comment

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

Pretty clean! We just have to handle errors very gracefully.

projects/plugins/jetpack/modules/sso.php Outdated Show resolved Hide resolved
projects/plugins/jetpack/modules/sso.php Outdated Show resolved Hide resolved
Comment on lines 118 to 134
Client::wpcom_json_api_request_as_user(
$url,
'2', // Api version
array(
'method' => 'POST',
),
array(
'invitees' => array(
array(
'email_or_username' => $email,
'role' => $role,
),
),
)
);
// returning false prevents the user to be notified by the core email.
return false;
Copy link
Member

Choose a reason for hiding this comment

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

We should investigate some error handling. We may want to block adding a user unless the invite works because otherwise the user won't be able to log in any way.

@escapemanuele
Copy link
Contributor

image

@crisbusquets, visually the only change here is the banner before the button.

We need to inform the site owner that, when creating the user, an invitation to join WPcom will be sent. Do you have any idea regarding copy or design? 😄

@crisbusquets
Copy link
Contributor

@crisbusquets, visually the only change here is the banner before the button.

We need to inform the site owner that, when creating the user, an invitation to join WPcom will be sent. Do you have any idea regarding copy or design? 😄

The alert is fine: it's blue = informative.

Is it possible to place the alert at the top (above the first form input)? Can we make it the same width as the content?
About the copy, what about: New users will receive an invite to join WordPress.com.

If we can't place the alert at the top, This user will receive an invite to join WordPress.com

Do we have a Support Page where we can explain why they'll receive an invite?

@renancarvalho
Copy link
Contributor Author

@crisbusquets, visually the only change here is the banner before the button.
We need to inform the site owner that, when creating the user, an invitation to join WPcom will be sent. Do you have any idea regarding copy or design? 😄

The alert is fine: it's blue = informative.

Is it possible to place the alert at the top (above the first form input)? Can we make it the same width as the content? About the copy, what about: New users will receive an invite to join WordPress.com.

If we can't place the alert at the top, This user will receive an invite to join WordPress.com

Do we have a Support Page where we can explain why they'll receive an invite?

Addressed @crisbusquets 🙇

@alshakero
Copy link
Member

alshakero commented Jan 26, 2024

Do we have a Support Page where we can explain why they'll receive an invite?

Not exactly, but we have a general article here. Maybe we can make the message more encouraging like

"This user will receive an invitation to join WordPress.com, and they will be able to log in using Secure Sign On".

@renancarvalho renancarvalho changed the base branch from trunk to add/sso-improvements January 26, 2024 14:46
@crisbusquets
Copy link
Contributor

Not exactly, but we have a general article here. Maybe we can make a message more encouraging like

"This user will receive an invitation to join WordPress.com, and they will be able to log in using Secure Sign On".

Got it!

What about this? To reinforce the security part:
New users will receive an invite to join WordPress.com, so they can log in securely using [Secure Sign On].

Copy link
Member

@alshakero alshakero left a comment

Choose a reason for hiding this comment

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

This looks terrific now. Besides the notice width (should be limited to 550px), this looks great to me.

Copy link
Member

@alshakero alshakero left a comment

Choose a reason for hiding this comment

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

Very close. Left a few comments.

wp_enqueue_style( 'jetpack-sso-admin-create-user', plugins_url( 'modules/sso/jetpack-sso-admin-create-user.css', JETPACK__PLUGIN_FILE ), array(), time() );

wp_admin_notice(
__( 'New users will receive an invite to join WordPress.com, so they can log in securely using [Secure Sign On].', 'jetpack' ),
Copy link
Member

@alshakero alshakero Jan 26, 2024

Choose a reason for hiding this comment

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

Secure Sign On should be a link to SSO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, I misunderstood that, added the link 👍

@@ -55,6 +55,12 @@ private function __construct() {
add_action( 'jetpack_site_before_disconnected', array( static::class, 'disconnect' ) );
add_action( 'wp_login', array( 'Jetpack_SSO', 'clear_cookies_after_login' ) );

// If the user has no errors on creation, send an invite to WordPress.com.
add_filter( 'user_profile_update_errors', array( $this, 'send_wpcom_mail_user_invite' ), 10, 3 );
// Don't send core invitation email when adding a new user via the admin.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Don't send core invitation email when adding a new user via the admin.
// Don't send core invitation email when SSO is activated. They will get an email from WP.com.

Comment on lines 5 to 8
/* Select the second-to-last tr in the table */
#createuser .form-table tr:nth-last-child(2) {
display: none;
}
Copy link
Member

@alshakero alshakero Jan 26, 2024

Choose a reason for hiding this comment

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

I would do this and change the code comment, currently the comment just compiles the code to the reader, it should explain the reasoning.

Suggested change
/* Select the second-to-last tr in the table */
#createuser .form-table tr:nth-last-child(2) {
display: none;
}
/* Hide the checkbox to send WP core invitation emails when SSO is on */
#createuser .form-table tr:has( #send_user_notification ) {
display: none;
}

Comment on lines 222 to 228
$message = sprintf(
'%s<a class="%s" rel="noopener noreferrer" target="_blank" href="%s">%s</a>',
__( 'New users will receive an invite to join WordPress.com, so they can log in securely using', 'jetpack' ),
'jetpack-sso-admin-create-user-invite-message-link-sso',
esc_url( 'https://jetpack.com/support/sso/' ),
__( 'Secure Sign On.', 'jetpack' )
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is working great, a few notes:

  • Let's use %1$s, %2$s, %3$s instead, to have more clarity.
  • After that let's add the * translators: %1$s is the message, %2$2 is ....

@escapemanuele escapemanuele self-requested a review January 29, 2024 10:56
Copy link
Contributor

@escapemanuele escapemanuele left a comment

Choose a reason for hiding this comment

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

Works great, what an improvement! LGTM

@renancarvalho renancarvalho merged commit b1b8a02 into add/sso-improvements Jan 29, 2024
50 checks passed
@renancarvalho renancarvalho deleted the improve_invite_form branch January 29, 2024 11:11
Comment on lines +224 to +229
__( 'New users will receive an invite to join WordPress.com, so they can log in securely using %s', 'jetpack' ),
sprintf(
'<a class="jetpack-sso-admin-create-user-invite-message-link-sso" rel="noopener noreferrer" target="_blank" href="%s">%s</a>',
'https://jetpack.com/support/sso/',
__( 'Secure Sign On.', 'jetpack' )
)
Copy link
Member

@alshakero alshakero Jan 29, 2024

Choose a reason for hiding this comment

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

Sadly, this is still incorrect.

And there is no variables here at all, you can remove sprintf and put everything inside one call of __().

@alshakero alshakero mentioned this pull request Feb 5, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] SSO [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User Invitation wp-admin: Inform site owner about email invitation
4 participants