Repository navigation
Protect Dashboard: Add a feature-flagged module that takes over the Protect page - #53182
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
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: 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. Inspect 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. |
Code Coverage SummaryCoverage changed in 3 files.
3 files are newly checked for coverage.
Full summary · PHP report · JS report Coverage check overridden by
Covered by non-unit tests
|
| 'delivery' => array( | ||
| 'jetpack' => false, | ||
| // The flag is registered by the Jetpack plugin, which owns the `protect-dashboard` module. | ||
| 'jetpack' => Feature_Flags::is_enabled( 'jetpack-protect-dashboard' ), |
There was a problem hiding this comment.
Pushed two commits: one points My Jetpack's Protect manage link at the new page when the module is active without the standalone plugin (it was going to protect-details or Jetpack Cloud), the other adds tests for the flag gate and the menu takeover.
One thing I left alone. With the flag on, the Protect plugin active and the module off, the Features card reads Off while Protect is running. resolveFeatureState() takes the module branch as soon as in_jetpack is true and never looks at plugin_status. The switch then only flips the module, so turning it on swaps the plugin's working dashboard for the blank page.
I tried counting an active plugin as "on" in that branch (the plugin branch below already does), but it applies to every hybrid feature, not just Protect, and it leaves the card saying active while its own switch says off. Bulk on/off gets confused the same way. So I backed it out.
What should that switch mean when both the plugin and the module can deliver the feature? Fine to leave for the PR that fills in the page, but I think it needs an answer before the flag defaults on.
| * | ||
| * @param bool $in_jetpack Whether the Jetpack plugin delivers Protect. Default false. | ||
| */ | ||
| 'jetpack' => (bool) apply_filters( 'jetpack_my_jetpack_protect_in_jetpack', false ), |
There was a problem hiding this comment.
This used to be just Feature_Flags::is_enabled( self::DASHBOARD ); Do we want to introduce another filter here?
|
Any reason not to go with Later PRs like #53190 and #53195 start bringing in supporting backend logic and rest routes that go outside the "UI Only" scope implied by the name. I think the package handling the whole of Protect's functionality (UX, API, Jetpack Backend) is correct - but the UI name seems misleading in that case. |
yeah I wish I could have went with I am open to naming suggestions though. |
Hmm. I was able to set it up: This gives us a "Protect" package with the slug This does some renaming for the jetapck-protect plugin to use the
This same rename pattern was used when the Search plugin introduced a corresponding package in #21502. Though, fortunately for us, the repo names are already correct and don't need to be changed for protect. |
…pack Protect plugin
With the protect-dashboard module active and no standalone plugin, the link went to protect-details or Jetpack Cloud instead of the Protect page.
My Jetpack no longer depends on the feature flags package, so the Jetpack plugin now reports the flag through jetpack_my_jetpack_protect_in_jetpack.
Drops the filter added earlier. The flag already removes protect-dashboard from the available modules, so My Jetpack can ask whether the module exists.
a170ed7 to
65fe55c
Compare
65fe55c to
f45f123
Compare
…t of Jetpack on Simple
kraftbj
left a comment
There was a problem hiding this comment.
Should this page opt out of JITMs the way Activity Log does (jetpack_display_jitms_on_screen)? There's no #jp-admin-notices here, so a fetched JITM would count a view without showing.
@kraftbj lets fix this in the follow up? unless there are somethings here that are not ready. |
Fixes JETPACK-2930
Part of JETPACK-2879, JETPACK-2884
Contributes to JETPACK-2872
Proposed changes
jetpack-protect-dashboardfeature flag, off by default. While it is off, it removes the newprotect-dashboardmodule fromjetpack_get_available_modules, so the module can't be activated, doesn't load, and isn't listed.protect-dashboardmodule. Its slug isn'tprotectbecause that is already Brute Force protection. When active, it registers a Protect sidebar item onadmin.php?page=jetpack-protect, the same address the Jetpack Protect plugin uses, so Protect's URL never changes._admin_menu; atadmin_menupriority 999 (before Admin_Menu registers items at 1000), the module removes that item and the plugin'sload-hooks for the page, then adds its own. The sidebar always shows one Protect item. The plugin's admin-bar link, threat-count badge and My Jetpack's manage link already point atpage=jetpack-protect, so they follow along.packages/protectpackage (automattic/jetpack-protect, added in Protect: Rename plugin Composer package and add packages/protect #53298), so the Jetpack plugin'sprotect-dashboardmodule and, later, the Jetpack Protect plugin can share it. The Protect plugin doesn't use it yet; that's a follow-up.routes/dashboard, page idjetpack-protect-dashboard), theAutomattic\Jetpack\Protect\Dashboardclass that adds the menu item and loads the package's ownbuild/, and its tests. For now the page only shows a "Protect" title.modules/protect-dashboard.php, which callsDashboard::init()with the module name so the menu item is tied to the module.delivery.jetpacknow follows the flag, by checking whether theprotect-dashboardmodule is on offer. With the flag on, the Features-tab Protect card treats Protect as part of Jetpack and switches theprotect-dashboardmodule, instead of offering to install the Jetpack Protect plugin.page=jetpack-protectonce the dashboard has loaded.Dashboard::init()firesjetpack_protect_dashboard_initializedfor this, the same way Backup signals its page.pnpm-lock.yamlchange is just the package's importer entry, which now has dependencies.Related product discussion/links
protect-dashboardmodule.Does this pull request change what data or activity we track or use?
No.
Testing instructions
JETPACK_AUTOLOAD_DEVset. Install and activate the Jetpack Protect plugin too.wp jetpack module activate protect-dashboardshould fail with "protect-dashboard is not a valid module".admin.php?page=jetpack-protectshould render the Jetpack Protect plugin's page.wp companion feature-flag enable jetpack-protect-dashboard.wp jetpack module activate protect-dashboard, or with the Protect switch in My Jetpack → Features.admin.php?page=jetpack-protect.wp companion feature-flag disable jetpack-protect-dashboard. The plugin's page should return even though the module is still stored as active.