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

Protect: Update fixer UI to handle long running fixers #39301

Merged
merged 97 commits into from
Sep 23, 2024

Conversation

dkmyta
Copy link
Contributor

@dkmyta dkmyta commented Sep 9, 2024

Description

Identifies when an in_progress fixer has been running for more than 24 hours and displays as stale.

Dependant on 107053-ghe-Automattic/vaultpress

Proposed changes:

  • Use last_updated property to determine if an in_progress fixer is stale
  • Add a conditional IconTooltip to provide an explanation for this, prompt support request
  • Disable applicable actions when a fixer is in_progress or considered stale
  • Filter the fixableThreats list for the Fix all threat modal when we determine that in_progress or stale fixers exist (to avoid subsequent fixer attempts, and ignore action being triggered)
  • Add handling for the fixer status for threats that do not have a fixer queued but that might be returned in the fixer status response (not_started), to ensure that they are not included in the success and failure notice counts

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

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

  • No

Testing instructions:

  • Checkout this branch
  • Start Jurassic Tube
  • Install/activate Protect and upgrade
  • Activate the Jetpack Debug Tool and add fixable threats
  • Trigger a new scan to detect them
  • From dev console, log out jetpackProtectInitialState and identify the fixable threats IDs (status.fixable_threat_ids)
  • Update CredentialGate component to disable it
  • Update REST_Controller::api_fix_threats to return the following (be sure to replace $threat_id with the actual ID of the fixable threat, and $current_date accordingly) to disable actually fixing the threat:
[ 'ok' => true, 'threats' => [ $threat_id => [ 'status' => 'in_progress', 'last_updated' => $current_date ] ] ];
  • Update REST_Controller::api_fix_threats_status to return the following (be sure to replace $threat_id with the actual ID of the fixable threat) to simulate the return of a stale in_progress:
[ 'ok' => true, 'threats' => [ $threat_id => [ 'status' => 'in_progress', 'last_updated' => "2024-01-01 00:00:01" ] ] ];
  • Trigger the fixer(s) and verify that upon the completion of the first fixer status request the UI updates to display that the selected fixer is stale, fixer status polling stops, and an error notice is displayed
  • Ensure that you are unable to ignore and initiate a fix on any threats that has an in_progress or "stale" fixer status from either the main threats list threat card or the Fix all threats modal checklist
  • Test separately on a Jurassic Ninja site using the beta tester and the branch without the modifications and ensure that no regressions in functionality are introduced

Base automatically changed from add/protect-fixer-status-to-initial-state to trunk September 16, 2024 16:50
nateweller
nateweller previously approved these changes Sep 17, 2024
@dkmyta dkmyta merged commit cec62c8 into trunk Sep 23, 2024
54 checks passed
@dkmyta dkmyta deleted the update/protect-fixer-ui-to-handle-long-running-fixers branch September 23, 2024 18:00
gogdzl pushed a commit that referenced this pull request Oct 25, 2024
* Protect: React Query

changelog

changelog

* Add fixerStatus to initial state

* changelog

* Fix in_progress fixer state

* Fix tests

* Fix fixThreats apiFetch call

* Do not camelize fixerStatus in useFixersQuery initialData

* Protect: React Query

changelog

changelog

* Use fixableThreats prop from scan status

* Protect: React Query

changelog

changelog

* Protect: React Query

* Fix merge errors

* Ensure fixer status polling occurs when in_progress fixers exist

* Protect: React Query

* Invalidate scan status query on fixer status query success

* Protect: React Query

* Provide useFixersQuery threatIds default value

* Protect: React Query

* Reorder

* Account for fixerStatus being false in useFixers hook

* Protect: React Query

* Temporarily disable optimistically setting fixer status

* Protect: React Query

* Simplify QUERY_FIXERS_KEY, and update setQueryData return formatting

* Fixes and improvements

* Protect: React Query

* Update fixerInProgress logic

* Conflict corrections

* Fix fixInProgressThreatIds logic

* Fix fixable_threat_ids type

* Update property name

* Fix useFixersQuery cachedData check logic

* Protect: React Query

* Protect: React Query

* Protect: React Query

* Handle fixer status optimistically

* Add removed comment

* Remove file

* Fix types

* Fix docblocks

* Revert unintended changes

* Protect: React Query

* changelog

* Handle long running fixers

* Improve setting fixer status optimistically

* Handle possible API returns

* Handle statuses for nonexistent fixers

* Filter fixable threats list for fix all threats modal

* Fixes and improvements to existing code

* Disable threat actions when fixer is stale

* Changelog entry

* Revert fixers mutation update

* Improve use fixers query error handling

* Update notice message

* Readd removed comment

* Fix naming

* Update initial state default

* Update initial state default

* Ensure FixerStatus type matches response structure

* Fix typo

* Fix logic - fixer cannot be active and stale

* Improvements

* Improve useFixersQuery

* Add comments

* Apply dummy arg to avoid bad minification issues

* Use clsx for conditional class names

* Use memoized value for fixableList

* Remove memoization of date

* Remove memoization of initial query data from window

* Centralize fixer logic and attempt to simplify the hook implementation

* Fix syntax errors

* Move stale fixer check to top of renderFixerStatus logic

---------

Co-authored-by: Nate Weller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Protect Models [Package] Protect Status [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Tests] Includes Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants