Repository navigation
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Premium Analytics plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Stats Data plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
…-woocommerce-stats-tab-on-self-hosted Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # projects/packages/woocommerce-stats/src/class-analytics-dashboard.php # projects/packages/woocommerce-stats/tests/php/Analytics_Dashboard_Test.php
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 2 files.
|
chihsuan
left a comment
There was a problem hiding this comment.
Thanks @retrofox! Since this gate is temporary until history limits and billing ship, would it make sense to use a feature flag that's off by default and turned on from wpcomsh? That keeps host checks out of the package, like classic Stats retirement. Left a couple of inline notes too.
| */ | ||
| public function check_permission() { | ||
| return Analytics_Dashboard::current_user_can_view_store_reports(); | ||
| return Analytics_Dashboard::is_enabled() && Analytics_Dashboard::current_user_can_view_store_reports(); |
There was a problem hiding this comment.
Is the 403 meant to block the report data, or mainly to back up hiding the tab? I noticed the same request still returns 200 through the Premium Analytics proxy, which CSV export also uses. That includes a shop manager who can no longer open the dashboard.
There was a problem hiding this comment.
It is meant to block the data, not only to back up the hidden tab. Good catch on the Premium Analytics proxy.
The gate moved into the store reports rule, current_user_can_view_store_reports(), so the tab, the widgets, and this proxy all follow it.
And while the flag is off, the package now refuses the two routes Premium Analytics still serves: the analytics group of its proxy and the CSV export.
It reads endpoint the way that proxy does, so a query-string endpoint cannot get around it. A shop manager gets a 403 on both.
I did it from this package on purpose, so Premium Analytics learns nothing new about WooCommerce. It goes away once the CSV export moves here 🤞
It is still the plugin refusing its own routes. A limit on the data itself has to live on the WordPress.com side.
| #[PreserveGlobalState( false )] | ||
| public function test_script_data_adds_the_store_currency_beside_existing_keys() { | ||
| require_once __DIR__ . '/mocks/woocommerce-mock.php'; | ||
| add_filter( Analytics_Dashboard::ENABLED_FILTER, '__return_true' ); |
There was a problem hiding this comment.
Should test_script_data_is_unchanged_without_woocommerce turn the gate on too? Right now it never reaches the WooCommerce checks.
There was a problem hiding this comment.
Yes, good catch again :-)
It turns the flag on now and runs in its own process, so it gets to the WooCommerce checks.
replaces the host check and its filter; the gate sits in the store reports rule
refuses the dashboard proxy's analytics group and its csv export while the flag is off
louwie17
left a comment
There was a problem hiding this comment.
Thanks @retrofox, this tested well on a local Docker site and @chihsuan's points look addressed. The main thing is merge order, should we merge #55498 first before we merge this one? ( left an inline comment ) The description also still mentions the Host check and the old filter, worth a quick update.
Co-reviewed and tested with Claude and Codex.
| Feature_Flags::register( | ||
| self::FLAG, | ||
| array( | ||
| 'default' => false, |
There was a problem hiding this comment.
Should we merge #55498 first before we merge this one? It looks independent of these changes, and would avoid an accidental late merge that leaves Atomic sites without their Woo tab.
There was a problem hiding this comment.
Yes, #55498 goes first. It does nothing until this one lands, and wpcomsh reaches Atomic twice a day, so I will merge this only after checking it is live there. Marked this PR as blocked until then, and updated the description.
| public static function data_dashboard_store_routes() { | ||
| return array( | ||
| 'the analytics group of the proxy' => array( 'GET', '/jetpack-premium-analytics/v1/proxy/v2/analytics/reports/orders/by-date', array() ), | ||
| 'a route in another letter case' => array( 'GET', '/Jetpack-Premium-Analytics/v1/Proxy/v2/analytics/reports/orders/by-date', array() ), |
There was a problem hiding this comment.
Small nit, maybe capitalize Analytics too, so this row covers the strtolower() on endpoint.
| 'a route in another letter case' => array( 'GET', '/Jetpack-Premium-Analytics/v1/Proxy/v2/analytics/reports/orders/by-date', array() ), | |
| 'a route in another letter case' => array( 'GET', '/Jetpack-Premium-Analytics/v1/Proxy/v2/Analytics/reports/orders/by-date', array() ), |
the mixed-case row now fails if the group is not lowercased
…-woocommerce-stats-tab-on-self-hosted # Conflicts: # projects/plugins/jetpack/composer.lock # projects/plugins/premium-analytics/composer.lock # projects/plugins/stats/composer.lock
|
I merged trunk into this branch to unblock #55483. Only the |
Fixes WOOA7S-2539
Proposed changes
A feature flag turns WooCommerce Stats on
The WooCommerce Stats package registers
jetpack-woocommerce-stats, off by default.Analytics_Dashboard::is_enabled()reads it.While it is off, nobody may read store reports: the gate sits in
current_user_can_view_store_reports(). So the WooCommerce tab, its widget types, the Bookings metric and the reports proxy go away together. The store currency is left out of the script data too.The store reports Premium Analytics still serves
While the flag is off, the package also refuses the
analyticsgroup of the Premium Analytics proxy and its CSV export. Premium Analytics itself does not change.WordPress.com keeps the tab
wpcomsh turns the flag on in #55498. That one has to be deployed to Atomic before this PR is merged.
Not here
Sync_ConfigurationandWooCommerce_Analytics_Trackerare untouched. Tracking is WOOA7S-2538, which can readAnalytics_Dashboard::is_enabled().The package now requires
automattic/jetpack-feature-flags, hence the three plugin lock files.Related product discussion/links
Does this pull request change what data or activity we track or use?
No. Front-end store tracking changes are tracked separately in WOOA7S-2538.
Testing instructions
Self-hosted store: hidden
Use a self-hosted site (Jurassic Ninja or local Docker) with Jetpack, Stats v2 on and WooCommerce active. Open Jetpack → Stats as an administrator.
The WooCommerce tab is not there, the dashboard opens on Traffic, and the inserter offers no WooCommerce widgets.
wp-admin/admin.php?page=jetpack-premium-analytics-wp-admin§ion=woocommercefalls back to the first available tab.A Shop Manager without
view_statscannot open the Stats dashboard.The reports answer 403
Both of these answer
403:Flag on: everything is back
On Jurassic Ninja:
wp companion feature-flag enable jetpack-woocommerce-statsAnywhere else, in a mu-plugin:
Reload Jetpack → Stats: the WooCommerce tab, its widgets, the currency formatting and the reports work as before.
Atomic
With this branch alone the tab is gone on Atomic, until #55498 is there.
Automated tests
jp test php packages/woocommerce-stats jp phan packages/woocommerce-stats