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

Display notice when user has unactivated product license keys #21474

Merged
merged 41 commits into from
Nov 11, 2021

Conversation

elliottprogrammer
Copy link
Contributor

@elliottprogrammer elliottprogrammer commented Oct 20, 2021

This PR displays a ""You have an inactive product. Activate now" notice in the dashboard if the user has unactivated product license keys available.

Note: This PR is a "re-do", based off #21426 which was closed because of complications with failing build checks. You can reference #21426 to view the original comments.

Changes proposed in this Pull Request:

  • Register API route (/jetpack/v4/licensing/user/counts) for fetching user license counts.
  • Fetch user license counts and store them in initialState.
  • Register API route (/jetpack/v4/licensing/user/activation-notice-dismiss) for storing activation notice dismissal info.
  • Create reducer, actions, and selectors for retrieving and updating user license counts and notice dismissal info in redux state.
  • Persists the notice's custom dismissal info in wp_options.
  • Displays the notice when the user acquires a new license, or when the user has an available license(s), but has dismissed the notice and it's been over 2 weeks without activating it.
  • Removes notice after a license key is activated, or if the notice is dismissed.

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

No

Testing instructions:

  • Spin up a site using this Jetpack branch.
  • Connect Jetpack to your WordPress.com user account.
  • Enable the license-key input box UI on the "My plan" page by adding add_filter( 'jetpack_licensing_ui_enabled', '__return_true' ); into Jetpack.
  • Go to /wp-admin/?page=jetpack#/dashboard#/my-plan (aka "My plan" page)
  • Verify you do not see a notice at the top that says, "You have an inactive product. Activate now." (Assuming you don't have any unattached user-licenses associated to your user account, which you shouldn't...yet..)
  • Verify you can see the License Key input field (at the bottom of the "My Plan" section).

Now obtain a 'user' product license key:

  • log into your wpcom sandbox, and in file wp-content/mu-plugins/0-sandbox.php add: add_filter( 'jetpack_license_checkout_m2_enabled', '__return_true' );. (Enabling this flag makes Jetpack checkout issue you a license when completing checkout).
  • Open a new command-line window in your sandbox and tail -f /tmp/php-errors
  • Point public-api.wordpress.com to your sandbox IP (in your hosts file).
  • Make sure you are proxied and go to https://wordpress.com/checkout/jetpack/jetpack_scan (siteless checkout flow).
  • Complete checkout (using credits is fine).
  • View your error log, you should see the output: Jetpack user license was created for subscription_id:17829922, belonging to user_id:78351100 and blog_id:198416894, but with different id values corresponding to your user and site. And you'll also see, License key is: jetpack_scan_monthly_oRhIEF4ckyVP6mCuHaD1vYnw5, but with your unique key.
  • Copy the license key from the error log output, and paste it somewhere for reference. We'll need this license key in a later step.
  • un-sandbox public-api.wordpress.com.

Now test that the notice appears now that you have been provisioned a detached license

  • Go to your Jetpack site and reload /wp-admin/?page=jetpack#/dashboard#/my-plan (aka "My plan" page).
  • Verify that you see a notice at the top that says, "You have an inactive product. Activate now."

Now test the notice dismiss behavior:
Prerequisite: You'll need Redux DevTools installed into your browser for this.

  • Open your browser developer tools and open Redux DevTools. (you may need to reload the page.) Inspect the state tree and locate state.licensing.activationNoticeDismiss
  • Click the notification dismiss button (x), verify that the notice disappears. and the values for last_detached_count and last_dismissed_time are updated.
  • Now, to verify that the notice reappears when a new detached license in acquired, in Redux DevTools, dispatch the action below: (replacing the value of detached with the value of <last_detached_count + 1>.
{
	type: 'JETPACK_LICENSING_USER_LICENSE_COUNTS_UPDATE',
	counts: {
		attached: 0,
		detached: <enter the value of `activationNoticeDismiss.last_detached_count` + 1(plus one) here>,
		revoked: 0,
		not_revoked: 0,
	}
}
  • Verify the notice appears again after the above action is dispatched (when a new detached license is added).
  • Now reload the page, reloading the persisted activationNoticeDismissed values in state. The notice should currently be dismissed from when you clicked dismiss(x) button before.
  • Now we'll dispatch another action, changing the last_dismissed_time to over 2 weeks ago: (2021-10-13T16:59:22+00:00)
{
	type: 'JETPACK_LICENSING_ACTIVATION_NOTICE_DISMISS_UPDATE',
	dismissData: {
		last_detached_count: <the current value in state, do not change>,
		last_dismissed_time: '2021-10-13T16:59:22+00:00' // <--change to this>
	}
}
  • Verify the notice reappears (because the last_dismiss_date is set to over 2 weeks ago).

Now test the notice disappears when you activate(submit) a license key:

  • First log into the site's wp-shell: (If using jurassic.ninja, ssh into the site using the ssh user and pass that is displayed in the Dashboard, then run wpsh. If using local docker env, run jetpack docker wp shell)
  • run command: update_option('jetpack_licensing_activation_notice_dismiss', array('last_detached_count' => null, 'last_dismissed_time' => null) ); . This will reset the dismiss notice.
  • Go to your Jetpack site and reload /wp-admin/?page=jetpack#/dashboard#/my-plan (aka "My plan" page). Verify the activation notice is visible.
  • Go back to Calypso, https://wordpress.com/purchases/subscriptions/:site, and copy the license key you purchased in the beginning steps.
  • Paste the license key into the License Key input box and submit.
  • Verify the "You have an inactive product. Activate now." notice disappears (Also you should see that the Jetpack Scan product has been provisioned for your site(You may need to refresh the page to see that))

Screenshot showing the new notice ("You have an inactive product. Activate now"):

Markup 2021-10-29 at 07 25 37

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello elliottprogrammer! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D68751-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions bot added [JS Package] API [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Admin Page React-powered dashboard under the Jetpack menu labels Oct 20, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2021

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.
  • ⚠️ All commits were linted before commit.
  • ✅ 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 (other than "Required review") 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 you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Beta plugin:

  • Next scheduled release: December 7, 2021.
  • Scheduled code freeze: November 29, 2021.

Jetpack plugin:

  • Next scheduled release: December 7, 2021.
  • Scheduled code freeze: November 30, 2021.

Debug Helper plugin:

  • Next scheduled release: December 7, 2021.
  • Scheduled code freeze: November 29, 2021.

Backup plugin:

  • Next scheduled release: December 7, 2021.
  • Scheduled code freeze: November 29, 2021.

Vaultpress plugin:

  • Next scheduled release: December 7, 2021.
  • Scheduled code freeze: November 29, 2021.

Boost plugin:

  • Next scheduled release: November 30, 2021.
  • Scheduled code freeze: November 23, 2021.

Search plugin:

  • Next scheduled release: December 7, 2021.
  • Scheduled code freeze: November 29, 2021.

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Oct 20, 2021
@github-actions github-actions bot added [JS Package] Connection [JS Package] IDC [Package] Connection UI This package no longer exists in the monorepo. [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. labels Oct 20, 2021
@elliottprogrammer
Copy link
Contributor Author

This PR is a "re-do", based off #21426 which I ended up closing because of complications with failing build checks. You can reference #21426 to view the original comments.

Thankfully, I got all the checks passing in this PR and it's now ready for review. 👍

rcanepa
rcanepa previously approved these changes Oct 20, 2021
Copy link
Contributor

@rcanepa rcanepa left a comment

Choose a reason for hiding this comment

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

LGTM.

In a follow-up PR we can improve the behavior of the dismiss button and make the CTA point to the right place.

@rcanepa
Copy link
Contributor

rcanepa commented Oct 20, 2021

@jeherve, we will release these changes as part of version 10.4. I wanted to tag this PR with that milestone tag but I couldn't find it. Will it get added once 10.3 gets released?

@elliottprogrammer elliottprogrammer added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] In Progress labels Nov 4, 2021
@github-actions github-actions bot added [Plugin] Beta For serving live branches and the beta versions. https://github.com/automattic/jetpack-beta [Plugin] Debug Helper Debug Tools plugin [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] VaultPress labels Nov 10, 2021
@elliottprogrammer elliottprogrammer removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Nov 10, 2021
@elliottprogrammer
Copy link
Contributor Author

So the status of this PR is that all the essential functionality is in place, working correctly, and ready for Crew re-review. @jeherve

Then after this PR is merged, we'll need to add into #21551 a function call to updateLicensingActivationNoticeDismiss in projects/js-packages/licensing/components/activation-screen/index.jsx inside the .then() block here.

Doing this will make sure that the "You have an inactive product. Activate now." notice gets dismissed every time the user submits(activates) their license key (even if the user owns additional unattached licenses). The notice will then stay dismissed until either: the user obtains a new license key for a new product, or if the user still has any unattched licenses that have not been attached for over 2 weeks (reminding them that they have an unused product license key waiting to be activated).

Copy link
Member

@jeherve jeherve 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 good and tests well for me. I only have one question left, but I'll approve this PR anyway since I think this can be addressed in a follow-up PR.

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Nov 11, 2021
@elliottprogrammer elliottprogrammer merged commit 1372569 into master Nov 11, 2021
@elliottprogrammer elliottprogrammer deleted the add/user-license-activate-notice-2 branch November 11, 2021 17:55
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Nov 11, 2021
@github-actions
Copy link
Contributor

Great news! One last step: head over to your WordPress.com diff, D68751-code, and commit it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@jeherve jeherve added the [Status] Needs Testing We need to add this change to the testing call for this month's release label Nov 11, 2021
davidlonjon added a commit that referenced this pull request Nov 16, 2021
* master: (22 commits)
  VideoPress: reload block on rating change (#21653)
  Assets: Changelog for package version 1.12.0 (#21744)
  assets: Add `wp_register_script` wrapper (and then use it everywhere) (#21689)
  eslint-config-target-es: Configure mirror repo (#21731)
  Use monorepo `validate-es` script to validate Webpack builds (#21729)
  Backup: Replace daily backup references/upsell links with new real-time products (#21715)
  Likes: reimplement non-admin portions without jQuery (#21726)
  Autoloader: Not activated autoload queue is false (#21517)
  Sync: add a new method, do_only_first_initial_sync (#21676)
  webpack-config: Configure minifier to preserve translator comments (#21667)
  webpack-config: Use `@automattic/babel-plugin-preserve-i18n` (#21700)
  Create eslint-config-target-es JS package (#21660)
  webpack-config: Fork calypso-build's mini-css-with-rtl plugin (#21595)
  Allow /sites/${site}/external-media/copy/pexels to insert post meta data  (#21659)
  jetpack: Don't set Webpack's `output.pathinfo` in production builds (#21727)
  Boost: Implement support for loading stylesheets when JavaScript is disabled in the context Critical CSS being enabled (#21713)
  RNA: export the Connection store (#21388)
  Display notice when user has unactivated product license keys (#21474)
  Gardening: ensure it can use Composer (#21712)
  Nav Unification: Display the stats sparkline on WP Admin for Atomic sites (#21655)
  ...
@elliottprogrammer
Copy link
Contributor Author

r234892-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Page React-powered dashboard under the Jetpack menu E2E Tests [JS Package] API [JS Package] Connection [JS Package] IDC [JS Package] Storybook [Package] Connection UI This package no longer exists in the monorepo. [Package] Licensing [Package] Options This package no longer exists in the monorepo. It was merged into [Package] Connection. [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Beta For serving live branches and the beta versions. https://github.com/automattic/jetpack-beta [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Debug Helper Debug Tools plugin [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] VaultPress RNA Touches WP.com Files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants