Skip to content

Commit

Permalink
Ensure threats with in_progress or error fixers are not eligible for …
Browse files Browse the repository at this point in the history
…actions
  • Loading branch information
dkmyta committed Oct 28, 2024
1 parent 428e35c commit c822afe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export default function ThreatsDataViews( {
isThreatEligibleForFix?: ( threat: Threat ) => boolean;
isThreatEligibleForIgnore?: ( threat: Threat ) => boolean;
isThreatEligibleForUnignore?: ( threat: Threat ) => boolean;
onFixThreats?: ActionButton< Threat >[ 'callback' ];
onIgnoreThreats?: ActionButton< Threat >[ 'callback' ];
onUnignoreThreats?: ActionButton< Threat >[ 'callback' ];
onFixThreats?: ActionButton< string | number >[ 'callback' ];
onIgnoreThreats?: ActionButton< string | number >[ 'callback' ];
onUnignoreThreats?: ActionButton< string | number >[ 'callback' ];
} ): JSX.Element {
const baseView = {
sort: {
Expand Down Expand Up @@ -486,13 +486,21 @@ export default function ThreatsDataViews( {
id: 'fix',
label: __( 'Auto-fix', 'jetpack' ),
supportsBulk: true,
callback: items => onFixThreats( items.map( item => item.id ) ),
callback: items =>
onFixThreats(
items.map( item => item.id ),
null // TODO: is context: { registry: any, onActionPerformed?: ... } prop necessary?
),
isEligible( item ) {
// TODO: Account for this here, or in isThreatEligibleForFix?
if ( item.fixer?.status !== 'not_started' ) {
return false;
}

if ( ! onFixThreats ) {
return false;
}
if ( isThreatEligibleForFix ) {
// TODO: Should not be able to bulk select or individually select threats with in_progress/errored fixers
return isThreatEligibleForFix( item );
}
return !! item.fixable;
Expand All @@ -504,8 +512,17 @@ export default function ThreatsDataViews( {
result.push( {
id: 'ignore',
label: __( 'Ignore', 'jetpack' ),
callback: items => onIgnoreThreats( items.map( item => item.id ) ),
callback: items =>
onIgnoreThreats(
items.map( item => item.id ),
null // TODO: is context: { registry: any, onActionPerformed?: ... } prop necessary?
),
isEligible( item ) {
// TODO: Account for this here, or in isThreatEligibleForIgnore?
if ( item.fixer?.status !== 'not_started' ) {
return false;
}

if ( ! onIgnoreThreats ) {
return false;
}
Expand All @@ -521,7 +538,11 @@ export default function ThreatsDataViews( {
result.push( {
id: 'un-ignore',
label: __( 'Unignore', 'jetpack' ),
callback: items => onUnignoreThreats( items.map( item => item.id ) ),
callback: items =>
onUnignoreThreats(
items.map( item => item.id ),
null // TODO: is context: { registry: any, onActionPerformed?: ... } prop necessary?
),
isEligible( item ) {
if ( ! onUnignoreThreats ) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Default.args = {
file: '/var/www/html/wp-admin/index.php',
extensionStatus: '',
},
fixer: null,
fixer: { status: 'not_started' },
filename: '/var/www/html/wp-admin/index.php',
diff: "--- /tmp/wordpress/6.6.2/wordpress/wp-admin/index.php\t2024-10-07 20:40:04.887546480 +0000\n+++ /var/www/html/wp-admin/index.php\t2024-10-07 20:39:58.775512965 +0000\n@@ -210,3 +210,4 @@\n wp_print_community_events_templates();\n \n require_once ABSPATH . 'wp-admin/admin-footer.php';\n+if ( true === false ) exit();\n\\ No newline at end of file\n",
},
Expand Down

0 comments on commit c822afe

Please sign in to comment.