Skip to content

Commit

Permalink
Refactor threat history
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller committed Jul 8, 2024
1 parent e963395 commit 818d83b
Show file tree
Hide file tree
Showing 39 changed files with 877 additions and 918 deletions.
48 changes: 28 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/plugins/protect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"prop-types": "15.8.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-router-dom": "6.2.2"
"react-router-dom": "6.24.0"
},
"devDependencies": {
"@automattic/jetpack-webpack-config": "workspace:*",
Expand Down
1 change: 0 additions & 1 deletion projects/plugins/protect/src/class-jetpack-protect.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public function initial_state() {
'apiNonce' => wp_create_nonce( 'wp_rest' ),
'registrationNonce' => wp_create_nonce( 'jetpack-registration-nonce' ),
'status' => Status::get_status( $refresh_status_from_wpcom ),
'viewingScanHistory' => false,
'scanHistory' => Scan_History::get_scan_history( $refresh_status_from_wpcom ),
'installedPlugins' => Plugins_Installer::get_plugins(),
'installedThemes' => Sync_Functions::get_themes(),
Expand Down
73 changes: 22 additions & 51 deletions projects/plugins/protect/src/class-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ public static function register_rest_endpoints() {
)
);

register_rest_route(
'jetpack-protect/v1',
'scan-history',
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => __CLASS__ . '::api_get_scan_history',
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
)
);

register_rest_route(
'jetpack-protect/v1',
'toggle-waf',
Expand Down Expand Up @@ -198,30 +210,6 @@ public static function register_rest_endpoints() {
},
)
);

register_rest_route(
'jetpack-protect/v1',
'scan-history',
array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => __CLASS__ . '::api_get_scan_history',
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
)
);

register_rest_route(
'jetpack-protect/v1',
'clear-scan-history-cache',
array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => __CLASS__ . '::api_clear_scan_history_cache',
'permission_callback' => function () {
return current_user_can( 'manage_options' );
},
)
);
}

/**
Expand Down Expand Up @@ -317,6 +305,16 @@ public static function api_scan() {
return new WP_REST_Response( 'Scan enqueued.' );
}

/**
* Return Scan History for the API endpoint
*
* @return WP_REST_Response
*/
public static function api_get_scan_history() {
$scan_history = Scan_History::get_scan_history( false );
return rest_ensure_response( $scan_history, 200 );
}

/**
* Toggles the WAF module on or off for the API endpoint
*
Expand Down Expand Up @@ -433,31 +431,4 @@ public static function api_complete_onboarding_steps( $request ) {

return new WP_REST_Response( 'Onboarding step(s) completed.' );
}

/**
* Return Scan History for the API endpoint
*
* @param WP_REST_Request $request The request object.
*
* @return WP_REST_Response
*/
public static function api_get_scan_history( $request ) {
$scan_history = Scan_History::get_scan_history( false, $request['filter'] );
return rest_ensure_response( $scan_history, 200 );
}

/**
* Clear the Scan_History cache for the API endpoint
*
* @return WP_REST_Response
*/
public static function api_clear_scan_history_cache() {
$cache_cleared = Scan_History::delete_option();

if ( ! $cache_cleared ) {
return new WP_REST_Response( 'An error occured while attempting to clear the Jetpack Scan history cache.', 500 );
}

return new WP_REST_Response( 'Jetpack Scan history cache cleared.' );
}
}
Loading

0 comments on commit 818d83b

Please sign in to comment.