Skip to content

Commit

Permalink
Help Center: extend support interaction API (#40112)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcangelini authored and matticbot committed Nov 10, 2024
1 parent 4f5bf17 commit 65fd21a
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 87 deletions.
58 changes: 29 additions & 29 deletions composer.lock

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

1 change: 1 addition & 0 deletions vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This is an alpha version! The changes listed here are not final.
- Added a feature check to the Marketing Bar that updates the text and upgrade link for Global Styles
- Enable test coverage.
- Help Center: add new rest route for support interactions
- Help Center: extend support interaction API
- The notice and modal shown on the editor now displays the plan name and upgrade URL based on the GS gated plan type'

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ public function register_rest_route() {
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_support_interactions' ),
'permission_callback' => 'is_user_logged_in',
'args' => array(
'status' => array(
'type' => 'string',
'required' => false,
'enum' => array(
'open',
'resolved',
),
),
'page' => array(
'type' => 'integer',
'required' => false,
'default' => 1,
'minimum' => 1,
),
'per_page' => array(
'type' => 'integer',
'required' => false,
'default' => 10,
'minimum' => 1,
'maximum' => 100,
),
),
)
);

Expand All @@ -54,7 +77,7 @@ public function register_rest_route() {
'permission_callback' => 'is_user_logged_in',
'args' => array(
'event_external_id' => array(
'type' => 'int',
'type' => 'string',
'required' => true,
),
'event_source' => array(
Expand All @@ -78,7 +101,7 @@ public function register_rest_route() {
'permission_callback' => 'is_user_logged_in',
'args' => array(
'event_external_id' => array(
'type' => 'int',
'type' => 'string',
'required' => true,
),
'event_source' => array(
Expand All @@ -92,6 +115,26 @@ public function register_rest_route() {
),
)
);

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<support_interaction_id>[a-zA-Z0-9-]+)/status',
array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_support_interaction_status' ),
'permission_callback' => 'is_user_logged_in',
'args' => array(
'status' => array(
'type' => 'string',
'required' => true,
'enum' => array(
'open',
'resolved',
),
),
),
)
);
}

/**
Expand Down Expand Up @@ -173,4 +216,25 @@ public function create_support_interaction_event( \WP_REST_Request $request ) {

return rest_ensure_response( $response );
}

/**
* Update support interaction status.
*
* @param \WP_REST_Request $request The request sent to the API.
*/
public function update_support_interaction_status( \WP_REST_Request $request ) {
$support_interaction_id = isset( $request['support_interaction_id'] ) ? (int) $request['support_interaction_id'] : null;

$status = $request['status'];

$body = Client::wpcom_json_api_request_as_user( "/support-interactions/$support_interaction_id/status?status={$status}" );

if ( is_wp_error( $body ) ) {
return $body;
}

$response = json_decode( wp_remote_retrieve_body( $body ) );

return rest_ensure_response( $response );
}
}
Loading

0 comments on commit 65fd21a

Please sign in to comment.