Skip to content

Commit

Permalink
Adds /stats endpoints to whitelist for Blaze (#39995)
Browse files Browse the repository at this point in the history
  • Loading branch information
j6ll authored and matticbot committed Nov 4, 2024
1 parent 79b85d9 commit fede8a2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.23.3-alpha] - unreleased
## [0.24.0-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Added
- Adds /stats endpoints to the whitelist
- Enable test coverage.

## [0.23.2] - 2024-10-21
Expand Down Expand Up @@ -477,7 +478,7 @@ This is an alpha version! The changes listed here are not final.
### Changed
- Updated package dependencies. [#27906]

[0.23.3-alpha]: https://github.com/automattic/jetpack-blaze/compare/v0.23.2...v0.23.3-alpha
[0.24.0-alpha]: https://github.com/automattic/jetpack-blaze/compare/v0.23.2...v0.24.0-alpha
[0.23.2]: https://github.com/automattic/jetpack-blaze/compare/v0.23.1...v0.23.2
[0.23.1]: https://github.com/automattic/jetpack-blaze/compare/v0.23.0...v0.23.1
[0.23.0]: https://github.com/automattic/jetpack-blaze/compare/v0.22.12...v0.23.0
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"link-template": "https://github.com/automattic/jetpack-blaze/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "0.23.x-dev"
"dev-trunk": "0.24.x-dev"
},
"textdomain": "jetpack-blaze",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-blaze",
"version": "0.23.3-alpha",
"version": "0.24.0-alpha",
"description": "Attract high-quality traffic to your site using Blaze. Using this service, you can advertise a post or page on some of the millions of pages across WordPress.com and Tumblr from just $5 per day.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/blaze/#readme",
"bugs": {
Expand Down
45 changes: 45 additions & 0 deletions src/class-dashboard-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@ public function register_rest_routes() {
)
);

// WordAds DSP API Site Stats routes
register_rest_route(
static::$namespace,
sprintf( '/sites/%d/wordads/dsp/api/(?P<api_version>v[0-9]+\.?[0-9]*)/stats(?P<sub_path>[a-zA-Z0-9-_\/]*)(\?.*)?', $site_id ),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_dsp_stats' ),
'permission_callback' => array( $this, 'can_user_view_dsp_callback' ),
)
);

register_rest_route(
static::$namespace,
sprintf( '/sites/%d/wordads/dsp/api/(?P<api_version>v[0-9]+\.?[0-9]*)/stats(?P<sub_path>[a-zA-Z0-9-_\/]*)', $site_id ),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'edit_dsp_stats' ),
'permission_callback' => array( $this, 'can_user_view_dsp_callback' ),
)
);

// WordAds DSP API Search routes
register_rest_route(
static::$namespace,
Expand Down Expand Up @@ -556,6 +577,30 @@ public function get_dsp_site_campaigns( $req ) {
return $this->get_dsp_generic( sprintf( 'v1/sites/%d/campaigns', $site_id ), $req );
}

/**
* Redirect GET requests to WordAds DSP Stats endpoint for the site.
*
* @param WP_REST_Request $req The request object.
*
* @return array|WP_Error
*/
public function get_dsp_stats( $req ) {
$version = $req->get_param( 'api_version' ) ?? 'v1';
return $this->get_dsp_generic( "{$version}/stats", $req );
}

/**
* Redirect POST requests to WordAds DSP Stats endpoint for the site.
*
* @param WP_REST_Request $req The request object.
*
* @return array|WP_Error
*/
public function edit_dsp_stats( $req ) {
$version = $req->get_param( 'api_version' ) ?? 'v1';
return $this->get_dsp_generic( "{$version}/stats", $req );
}

/**
* Redirect GET requests to WordAds DSP Search endpoint for the site.
*
Expand Down
2 changes: 1 addition & 1 deletion src/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Dashboard {
*
* @var string
*/
const PACKAGE_VERSION = '0.23.3-alpha';
const PACKAGE_VERSION = '0.24.0-alpha';

/**
* List of dependencies needed to render the dashboard in wp-admin.
Expand Down

0 comments on commit fede8a2

Please sign in to comment.