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

Jetpack Connect: Redirect Pressable partner plan connection after authorize #20025

Merged
merged 8 commits into from
Nov 29, 2017

Conversation

ebinnion
Copy link
Contributor

@ebinnion ebinnion commented Nov 20, 2017

As part of activity log and rewind, we need users to approve credential collection after authorizing the connection to their new site. This PR will redirect all Pressable sites that are connecting for a partner plan to a separate authorize screen to approve the rewind connection.

To test:

  • Checkout branch locally
  • Run npm start.
    • If you already have Calypso running, stop it and restart so that you get the updated config flags
  • Create a new Pressable site
  • Connect your site
  • This is janky, but grab the full connection URL once you're at WP.com, before the authorization details are taken out.
  • Replace wordpress.com with calypso.localhost:3000 and then go to that URL 🤦‍♂️
  • On the authorization page, ensure you see a co-branded form
  • After authorizing, ensure you're redirected to proper URL (at time of this PR being created, it's redirecting to /me. We need the updated URL from the Activity Log folks

@matticbot
Copy link
Contributor


// Redirect sites hosted on Pressable with a partner plan to some URL.
// 51652 is a testing partner ID.
if ( 49640 === partnerId || 51652 === partnerId ) {
Copy link
Contributor

@johnHackworth johnHackworth Nov 21, 2017

Choose a reason for hiding this comment

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

Can we move those magic numbers to a constant somewhere ( for example,

) labeling as what they are? 😺

@rcoll
Copy link
Member

rcoll commented Nov 24, 2017

I added the correct URL in 71e9c16.

Please remember to wall off that flow from non-a12s until we ship to customers.

@ebinnion ebinnion force-pushed the update/jpc-redirect-pressable-to-url branch from 71e9c16 to 739ca22 Compare November 27, 2017 16:58
@ebinnion ebinnion added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Nov 27, 2017
@ebinnion
Copy link
Contributor Author

I've updated the PR per your feedback @johnHackworth. This should be ready for review now.

@sirreal
Copy link
Member

sirreal commented Nov 28, 2017

This is janky, but grab the full connection URL once you're at WP.com, before the authorization details are taken out.

You can append &calypso_env=development to the URL on the connect button to hit calypso.localhost directly.

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

I've left some questions and suggestions.

Testing works well for me, I see a branded connect page and I'm sent to a NUX flow I've never seen before after connect.

Connecting a "normal" site continues to work… normally 🙂

@@ -185,6 +197,18 @@ class LoggedInForm extends Component {
return startsWith( get( props, [ 'authorizationData', 'queryObject', 'from' ] ), 'jpo' );
}

shouldRedirectJetpackStart( props ) {
const partnerId = parseInt( get( props, 'partnerId' ), 10 );
Copy link
Member

Choose a reason for hiding this comment

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

props should always be an object, get(...) shouldn't add any value, we can access directly, often we'll use destructuring assignment:

shouldRedirectJetpackStart( props ) {
  const { partnerId } = props;
  // …
}

// or even

shouldRedirectJetpackStart( { partnerId } ) {
  // partnerId is already assigned!
  // …
}

parseInt should be redundant, it's in the selector:

export default function getJetpackConnectPartnerId( state ) {
return parseInt( get( getAuthorizationRemoteQueryData( state ), 'partner_id', 0 ), 10 );
}

// Redirect sites hosted on Pressable with a partner plan to some URL.
if (
config.isEnabled( 'jetpack/connect-redirect-pressable-credential-approval' ) &&
PRESSABLE_CLIENT_ID === parseInt( partnerId, 10 )
Copy link
Member

Choose a reason for hiding this comment

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

parseInt is redundant, it's in the selector:

export default function getJetpackConnectPartnerId( state ) {
return parseInt( get( getAuthorizationRemoteQueryData( state ), 'partner_id', 0 ), 10 );
}


/**
* Constants
*/
const MAX_AUTH_ATTEMPTS = 3;
const PLANS_PAGE = '/jetpack/connect/plans/';
const debug = debugModule( 'calypso:jetpack-connect:authorize-form' );
const PRESSABLE_CLIENT_ID = 49640;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be PRESSABLE_PARTNER_ID?

@@ -41,6 +41,7 @@
"help/courses": true,
"jetpack/activity-log": true,
"jetpack/api-cache": true,
"jetpack/connect-redirect-pressable-credential-approval": true,
Copy link
Member

Choose a reason for hiding this comment

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

This is a public environment. Is that OK?

@@ -39,6 +39,7 @@
"help/courses": true,
"jetpack/activity-log": true,
"jetpack/api-cache": true,
"jetpack/connect-redirect-pressable-credential-approval": true,
Copy link
Member

Choose a reason for hiding this comment

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

This is a public environment. Is that OK?

@ebinnion ebinnion force-pushed the update/jpc-redirect-pressable-to-url branch from e75c6c1 to 52d2bfd Compare November 28, 2017 16:48
@ebinnion ebinnion self-assigned this Nov 28, 2017
@ebinnion
Copy link
Contributor Author

Thanks for the review @sirreal. I've updated the PR per your feedback and have rebased against master to get rid of a merge conflict.

@sirreal sirreal self-requested a review November 28, 2017 17:33
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

I followed the testing instructions and this works well. I left a comment regarding a block that was tricky for me to decipher, feel free to do with that as you wish.

Ready to 🚢 at will, thanks!

// If the redirect flag is set, then we conditionally redirect the Pressable client to
// a credential approval screen. Otherwise, we need to redirect all other partners back
// to wp-admin.
return partnerRedirectFlag ? partnerId && PRESSABLE_PARTNER_ID !== partnerId : partnerId;
Copy link
Member

Choose a reason for hiding this comment

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

It's taken me several readings to appreciate what's going on here. This should return true if we have a partnerId and it's not the PRESSABLE_PARTNER_ID, otherwise false. Is that right?

Do you think something like the following better expresses the intent?

shouldRedirectJetpackStart( { partnerId } ) {
  if ( ! partnerId ) {
    return false;
  }

  // Pressable sites have a special NUX behind a flag
  if ( config.isEnabled( 'jetpack/connect-redirect-pressable-credential-approval' ) ) {
    return PRESSABLE_PARTNER_ID !== partnerId
  }

  return true;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for that. I'd prefer to merge for now, but will be glad to address in a follow-up PR.

@ebinnion ebinnion merged commit cce731d into master Nov 29, 2017
@ebinnion ebinnion deleted the update/jpc-redirect-pressable-to-url branch November 29, 2017 15:55
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants