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

Connection: add partner codes to connection URLs & deprecate Partner package #33832

Merged
merged 21 commits into from
Nov 16, 2023

Conversation

jeherve
Copy link
Member

@jeherve jeherve commented Oct 27, 2023

Proposed changes:

This PR changes the way the Partner codes were added when connecting a site to a WordPress.com account, so this can work with standalone plugins.

This was previously only done in the Jetpack plugin, in 2 ways:

  • The Partner package is initialized on plugins_loaded in the main Jetpack class.
  • In Jetpack's build_authorize_url method we have a jetpack_build_authorize_url filter that is leveraged by the Partner package.

Standalone plugins, on the other hand, do not use Jetpack::build_authorize_url(). This method is obviously only available in the Jetpack plugin, and so standalone plugins do not have that jetpack_build_authorize_url filter.

We fix this discrepancy in this PR:

  • We now include the Partner package functionality directly in the connection package.
  • We initialize the Partner package in the connection package.
  • We add the jetpack_build_authorize_url filter to the connection package's get_authorization_url method, so the partner codes can be added to all URLs.
  • We stop initializing the Partner class in the Jetpack plugin, since it is now done in the connection package.

Note
This does not add the Partner package as a new dependency for the Connection package, since the Partner package already declares the connection package as a dependency.

Note
This PR is getting larger because we are deprecating the Partner package as part of this PR. It is no longer needed since the features it offered can be offered directly in the connection package.

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

  • pbtFPC-6ha-p2

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

  • No

Testing instructions:

There may be an easier way to test this, but here is how I went about it.

Warning
You will want to test the process in both the Jetpack plugin and a standalone plugin like Jetpack Protect

Warning
It would be useful to test with the Jetpack plugin running this branch, as well as another standalone plugin running a stable version, still using the Partner package.

  • On a brand new site,
  • Via WP CLI, set up an affiliate code and a subsiadiary code:
    • wp option update jetpack_partner_subsidiary_id jeremy
    • wp option update jetpack_affiliate_code 123456
  • Install a Jetpack plugin (Jetpack or something else).
  • Open your browser's network tools
  • Filter for jetpack.wordpress.com requests
  • Start the connection process
  • Check the arguments added to the jetpack.wordpress.com request
    • It should include both an aff and a subsidiaryId argument, using the values defined above.

This was previously only done in the Jetpack plugin, in 2 ways:

- The Partner package is initialized on plugins_loaded in the main Jetpack class.
- In Jetpack's `build_authorize_url` method we have a `jetpack_build_authorize_url` filter that is leveraged by the Partner package.

Standalone plugins, on the other hand, do not use `Jetpack::build_authorize_url()`. This method is obviously only available in the Jetpack plugin, and so standalone plugins do not have that `jetpack_build_authorize_url` filter.

We fix this discrepancy in this commit:

- We now initialize the Partner package in the connection package.
- We add the `jetpack_build_authorize_url` filter to the connection package's `get_authorization_url` method, so the partner codes can be added to all URLs.

**Note**: this does not add the Partner package as a new dependency for the Connection package, since the Partner package already declares the connection package as a dependency.
It is no longer needed now that the package is set up as part of the connection package
@jeherve jeherve added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Pri] Normal [Package] Partner This package no longer exists in the monorepo. It was merged into [Package] Connection. [Status] Needs Team Review [Package] Connection [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Oct 27, 2023
@jeherve jeherve added this to the jetpack/12.8 milestone Oct 27, 2023
@jeherve jeherve requested a review from a team October 27, 2023 10:35
@jeherve jeherve self-assigned this Oct 27, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 27, 2023

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 fix/connection-partner-standalone-sites branch.

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

    bin/jetpack-downloader test jetpack fix/connection-partner-standalone-sites
    

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
Copy link
Contributor

github-actions bot commented Oct 27, 2023

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 December 5, 2023 (scheduled code freeze on November 28, 2023).

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


Backup plugin:

  • Next scheduled release: December 5, 2023.
  • Scheduled code freeze: November 27, 2023.

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


Boost plugin:

  • Next scheduled release: December 5, 2023.
  • Scheduled code freeze: November 27, 2023.

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


Search plugin:

  • Next scheduled release: December 5, 2023.
  • Scheduled code freeze: November 27, 2023.

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


Social plugin:

  • Next scheduled release: December 5, 2023.
  • Scheduled code freeze: November 27, 2023.

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


Starter Plugin plugin:

  • Next scheduled release: December 5, 2023.
  • Scheduled code freeze: November 27, 2023.

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


Protect plugin:

  • Next scheduled release: December 5, 2023.
  • Scheduled code freeze: November 27, 2023.

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


Videopress plugin:

  • Next scheduled release: December 5, 2023.
  • Scheduled code freeze: November 27, 2023.

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


Migration plugin:

  • Next scheduled release: December 5, 2023.
  • Scheduled code freeze: November 27, 2023.

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

monsieur-z
monsieur-z previously approved these changes Oct 27, 2023
Copy link
Contributor

@monsieur-z monsieur-z 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 instructions for testing both the Jetpack plugin and Boost and could see the query parameters. I appreciate how the code changes were documented 👍

@jeherve
Copy link
Member Author

jeherve commented Oct 27, 2023

The test failure outlines an interesting problem. It fails for the Inspect plugin, most likely because it doesn't include the My Jetpack package, so the Partner package is never required. I'm not quite sure how to fix that.

  • My initial thought was to add the Partner package as a dependency of the Connection package, since we use Partner in the connection package. But since the Partner package already has the connection package as a dependency, it would create a circular dependency. Maybe that's okay?
  • I could cheat and the Partner package as a dependency of the Inspect plugin, but that's not future-proof at all.

@anomiex Could I have your opinion about this?

@anomiex
Copy link
Contributor

anomiex commented Oct 27, 2023

My initial thought was to add the Partner package as a dependency of the Connection package, since we use Partner in the connection package. But since the Partner package already has the connection package as a dependency, it would create a circular dependency. Maybe that's okay?

Offhand I don't know how Composer would handle it, but I know our CI will complain about a circular dependency. We'll want to avoid that.

I could cheat and the Partner package as a dependency of the Inspect plugin, but that's not future-proof at all.

Yeah, that's cheating. We don't want that to be the long-term solution either, it'll just bite someone else who uses the Connection package in the future.

I see a few options that could work:

  • Move the necessary code from Partner to Connection, since Connection needs it. If that makes Partner empty, that's fine, we've done that before.
  • Make Connection "suggest" Partner, and guard any calls to it from Connection with appropriate checks (is_callable, class_exists, etc). Of course, that depends on whether working without Partner makes sense, and whether it might be confusing if e.g. Inspect's behavior differs based on whether some other plugin that provides Partner is also installed.

@jeherve jeherve added [Status] In Progress and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review labels Oct 30, 2023
@jeherve jeherve changed the title Connection: add partner codes are added to connection URLs Connection: add partner codes to connection URLs & deprecate Partner package Oct 30, 2023
@jeherve
Copy link
Member Author

jeherve commented Oct 30, 2023

I see a few options that could work:

* Move the necessary code from Partner to Connection, since Connection needs it. If that makes Partner empty, that's fine, we've done that before.

That's something I was thinking about, but I wasn't sure everyone was going to be okay with that. 👍
I've just done that in this PR.
I'll look at the test failures tomorrow, I have yet to understand what's causing the connection tests to fail now.

@jeherve jeherve removed this from the jetpack/12.8 milestone Oct 31, 2023
@sergeymitr
Copy link
Contributor

Hi @jeherve.
Brain\Monkey in Partner_Test did not count function mock calls correctly for some reason, which caused an error on the proper tear down attempt.
I adjusted the tests so they wouldn't need Brain\Monkey altogether, they seem to pass now.

@sergeymitr sergeymitr self-requested a review October 31, 2023 19:15
@jeherve jeherve added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review and removed [Status] In Progress labels Nov 14, 2023
@sergeymitr
Copy link
Contributor

Hi @jeherve.
Can you please fix the checks, and I'll give it a final look.

@sergeymitr sergeymitr added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Team Review labels Nov 15, 2023
sergeymitr
sergeymitr previously approved these changes Nov 15, 2023
@sergeymitr sergeymitr added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Nov 15, 2023
@jeherve jeherve merged commit bb1fa3d into trunk Nov 16, 2023
64 checks passed
@jeherve jeherve deleted the fix/connection-partner-standalone-sites branch November 16, 2023 10:26
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs [Package] Connection [Package] Jitm [Package] Partner 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] Boost A feature to speed up the site and improve performance. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Migration [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Pri] High [Tests] Includes Tests [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants