Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
12.50% |
2 / 16 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| History | |
14.29% |
2 / 14 |
|
0.00% |
0 / 4 |
20.74 | |
0.00% |
0 / 1 |
| get_key | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_state | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| register_routes | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| get_history | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * The Protect dashboard's Scan history tab. |
| 4 | * |
| 5 | * @package automattic/jetpack-protect |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Protect\Sections; |
| 9 | |
| 10 | use Automattic\Jetpack\Protect\Dashboard; |
| 11 | use Automattic\Jetpack\Protect\Dashboard_Section; |
| 12 | use WP_Error; |
| 13 | use WP_REST_Server; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit( 0 ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Threats Scan has fixed or ignored, for sites with a Scan plan. |
| 21 | * |
| 22 | * @since $$next-version$$ |
| 23 | */ |
| 24 | class History implements Dashboard_Section { |
| 25 | |
| 26 | /** |
| 27 | * The key the section's state is printed under. |
| 28 | * |
| 29 | * @return string |
| 30 | */ |
| 31 | public function get_key() { |
| 32 | return 'history'; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * The section's state on page load. |
| 37 | * |
| 38 | * @return array |
| 39 | */ |
| 40 | public function get_state() { |
| 41 | return array( 'hasPlan' => Dashboard::has_scan_plan() ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Register the section's REST routes. |
| 46 | * |
| 47 | * @return void |
| 48 | */ |
| 49 | public function register_routes() { |
| 50 | register_rest_route( |
| 51 | 'jetpack/v4', |
| 52 | '/protect-dashboard/history', |
| 53 | array( |
| 54 | 'methods' => WP_REST_Server::READABLE, |
| 55 | 'callback' => array( __CLASS__, 'get_history' ), |
| 56 | 'permission_callback' => array( Dashboard::class, 'can_manage' ), |
| 57 | ) |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Threats Scan has fixed or ignored. |
| 63 | * |
| 64 | * @return array|WP_Error |
| 65 | */ |
| 66 | public static function get_history() { |
| 67 | if ( ! Dashboard::has_scan_plan() ) { |
| 68 | return new WP_Error( 'no_scan_plan', __( 'Scan history needs a Jetpack Scan plan.', 'jetpack-protect-pkg' ), array( 'status' => 403 ) ); |
| 69 | } |
| 70 | |
| 71 | return Scan::get_history_threats(); |
| 72 | } |
| 73 | } |