-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EVA-157 Conditional Endpoint Disabling #2101
Merged
pattihis
merged 6 commits into
bucket/plugin-consolidation
from
fix/EVA-157-Conditional-Endpoint-Disabling
Jun 12, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c1dfc8d
Disable Endpoints in the admin table when dependency is not there.
pattihis dbeb855
No action buttons when missing dependency.
pattihis 30eee11
EVA-158 Fix assets loading
pattihis 1fa1d96
Fix Tooltip assets in Common
pattihis f4084b5
PHPCS formatting
pattihis b59a60f
PHPCS formatting
pattihis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -234,37 +234,39 @@ public function swaggerize_args( array $args = [], array $defaults = [] ) { | |||||||||
} | ||||||||||
|
||||||||||
$no_description = _x( 'No description provided', 'Default description for integration endpoint.', 'tribe-common' ); | ||||||||||
$defaults = array_merge( [ | ||||||||||
'in' => 'body', | ||||||||||
'schema' => [ | ||||||||||
'type' => 'string', | ||||||||||
], | ||||||||||
'description' => $no_description, | ||||||||||
'required' => false, | ||||||||||
'items' => [ | ||||||||||
'type' => 'integer', | ||||||||||
$defaults = array_merge( | ||||||||||
[ | ||||||||||
'in' => 'body', | ||||||||||
'schema' => [ | ||||||||||
'type' => 'string', | ||||||||||
], | ||||||||||
'description' => $no_description, | ||||||||||
'required' => false, | ||||||||||
'items' => [ | ||||||||||
'type' => 'integer', | ||||||||||
], | ||||||||||
], | ||||||||||
], $defaults ); | ||||||||||
|
||||||||||
$defaults | ||||||||||
); | ||||||||||
|
||||||||||
$swaggerized = []; | ||||||||||
foreach ( $args as $name => $info ) { | ||||||||||
if ( isset( $info['swagger_type'] ) ) { | ||||||||||
$type = $info['swagger_type']; | ||||||||||
} else { | ||||||||||
$type = isset( $info['type'] ) ? $info['type'] : false; | ||||||||||
$type = $info['type'] ?? false; | ||||||||||
} | ||||||||||
|
||||||||||
$type = $this->convert_type( $type ); | ||||||||||
|
||||||||||
$read = [ | ||||||||||
'name' => $name, | ||||||||||
'in' => isset( $info['in'] ) ? $info['in'] : false, | ||||||||||
'description' => isset( $info['description'] ) ? $info['description'] : false, | ||||||||||
'schema' => [ | ||||||||||
'type' => $type, | ||||||||||
'name' => $name, | ||||||||||
'in' => $info['in'] ?? false, | ||||||||||
'description' => $info['description'] ?? false, | ||||||||||
'schema' => [ | ||||||||||
'type' => $type, | ||||||||||
], | ||||||||||
'required' => isset( $info['required'] ) ? $info['required'] : false, | ||||||||||
'required' => $info['required'] ?? false, | ||||||||||
]; | ||||||||||
|
||||||||||
if ( isset( $info['items'] ) ) { | ||||||||||
|
@@ -281,12 +283,12 @@ public function swaggerize_args( array $args = [], array $defaults = [] ) { | |||||||||
} | ||||||||||
|
||||||||||
// Copy in case we need to mutate default values for this field in args | ||||||||||
$defaultsCopy = $defaults; | ||||||||||
unset( $defaultsCopy['default'] ); | ||||||||||
unset( $defaultsCopy['items'] ); | ||||||||||
unset( $defaultsCopy['type'] ); | ||||||||||
$defaults_copy = $defaults; | ||||||||||
unset( $defaults_copy['default'] ); | ||||||||||
unset( $defaults_copy['items'] ); | ||||||||||
unset( $defaults_copy['type'] ); | ||||||||||
|
||||||||||
$swaggerized[] = array_merge( $defaultsCopy, array_filter( $read ) ); | ||||||||||
$swaggerized[] = array_merge( $defaults_copy, array_filter( $read ) ); | ||||||||||
} | ||||||||||
|
||||||||||
return $swaggerized; | ||||||||||
|
@@ -344,7 +346,7 @@ protected function load_api_key_pair( $consumer_id, $consumer_secret, $token = ' | |||||||||
} | ||||||||||
|
||||||||||
$app_name = empty( $token['app_name'] ) ? '' : $token['app_name']; | ||||||||||
$app_name = $app_header_id ? : $app_name; | ||||||||||
$app_name = $app_header_id ?: $app_name; | ||||||||||
$this->api->set_api_key_last_access( $consumer_id, $app_name ); | ||||||||||
$this->set_endpoint_last_access( $app_name ); | ||||||||||
|
||||||||||
|
@@ -369,9 +371,7 @@ protected function verify_token( $request ) { | |||||||||
return new WP_Error( 'missing_access_token', __( 'Missing access token.', 'tribe-common' ), [ 'status' => 401 ] ); | ||||||||||
} | ||||||||||
|
||||||||||
$key_pair = $this->api->decode_jwt( $access_token ); | ||||||||||
|
||||||||||
return $key_pair; | ||||||||||
return $this->api->decode_jwt( $access_token ); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
|
@@ -440,7 +440,7 @@ abstract protected function get_display_name(): string; | |||||||||
* @since TBD Migrated to Common from Event Automator | ||||||||||
*/ | ||||||||||
public function add_to_dashboard() { | ||||||||||
$api_id = $this->api::get_api_id(); | ||||||||||
$api_id = $this->api::get_api_id(); | ||||||||||
|
||||||||||
add_filter( "tec_event_automator_{$api_id}_endpoints", [ $this, 'add_endpoint_details' ], 10, 2 ); | ||||||||||
} | ||||||||||
|
@@ -483,33 +483,20 @@ public function get_endpoint_details() { | |||||||||
]; | ||||||||||
|
||||||||||
// Setup queue counts only on that endpoint type. | ||||||||||
if ( | ||||||||||
static::$type !== 'queue' | ||||||||||
|| ! isset( $this->trigger ) | ||||||||||
) { | ||||||||||
/** | ||||||||||
* Filters the integration endpoint details. | ||||||||||
* | ||||||||||
* @since TBD Migrated to Common from Event Automator | ||||||||||
* | ||||||||||
* @param array<string,array> $endpoint An array of the integration endpoint details. | ||||||||||
* @param Abstract_REST_Endpoint $this An instance of the endpoint. | ||||||||||
*/ | ||||||||||
return apply_filters( "tec_event_automator_{$api_id}_endpoint_details", $endpoint, $this ); | ||||||||||
if ( static::$type === 'queue' && isset( $this->trigger ) ) { | ||||||||||
$endpoint_queue = (array) $this->trigger->get_queue(); | ||||||||||
$endpoint['count'] = empty( $endpoint_queue ) ? 0 : count( $endpoint_queue ); | ||||||||||
} | ||||||||||
|
||||||||||
$endpoint_queue = (array) $this->trigger->get_queue(); | ||||||||||
$endpoint['count'] = empty( $endpoint_queue ) ? 0 : count( $endpoint_queue ); | ||||||||||
|
||||||||||
/** | ||||||||||
* Filters the integation queue type endpoint details. | ||||||||||
* Filters the integration endpoint details. | ||||||||||
* | ||||||||||
* @since TBD Migrated to Common from Event Automator | ||||||||||
* | ||||||||||
* @param array<string,array> $endpoint An array of the integration endpoint details. | ||||||||||
* @param Abstract_REST_Endpoint $this An instance of the endpoint. | ||||||||||
*/ | ||||||||||
return apply_filters( "tec_event_automator_{$api_id}_queue_endpoint_details", $endpoint, $this ); | ||||||||||
return apply_filters( "tec_event_automator_{$api_id}_endpoint_details", $endpoint, $this ); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
|
@@ -520,7 +507,13 @@ public function get_endpoint_details() { | |||||||||
* @return array<string,array> An array of saved details for an endpoint. | ||||||||||
*/ | ||||||||||
public function get_saved_details() { | ||||||||||
return get_option( $this->get_option_id(), [ 'last_access' => '', 'enabled' => true ] ); | ||||||||||
return get_option( | ||||||||||
$this->get_option_id(), | ||||||||||
[ | ||||||||||
'last_access' => '', | ||||||||||
'enabled' => true, | ||||||||||
] | ||||||||||
); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
|
@@ -590,7 +583,7 @@ public function add_to_queue( $post_id, $data ) { | |||||||||
return; | ||||||||||
} | ||||||||||
|
||||||||||
$api_id = $this->api::get_api_id(); | ||||||||||
$api_id = $this->api::get_api_id(); | ||||||||||
|
||||||||||
/** | ||||||||||
* Filters data passed to the trigger queue for an endpoint. | ||||||||||
|
@@ -703,8 +696,8 @@ public function pre_dispatch_verification( $result, $server, $request ) { | |||||||||
* @param WP_REST_Response|WP_Error $response Response to replace the requested version with. Can be anything | ||||||||||
* a normal endpoint can return, or a WP_Error if replacing the | ||||||||||
* response with an error. | ||||||||||
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server). | ||||||||||
* @param WP_REST_Request $request Request used to generate the response. | ||||||||||
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server). | ||||||||||
* @param WP_REST_Request $request Request used to generate the response. | ||||||||||
Comment on lines
+699
to
+700
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit pick:
Suggested change
|
||||||||||
* | ||||||||||
* @return WP_REST_Response|WP_Error The response. | ||||||||||
*/ | ||||||||||
|
@@ -713,7 +706,7 @@ public function modify_rest_api_params_before_validation( $response, $handler, $ | |||||||||
return $response; | ||||||||||
} | ||||||||||
|
||||||||||
if ( $request->get_route() !== '/' . $this->get_events_route_namespace() . $this->get_endpoint_path() ) { | ||||||||||
if ( $request->get_route() !== '/' . $this->get_events_route_namespace() . $this->get_endpoint_path() ) { | ||||||||||
return $response; | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -724,6 +717,6 @@ public function modify_rest_api_params_before_validation( $response, $handler, $ | |||||||||
$request->set_param( 'organizer', $organizer_array ); | ||||||||||
} | ||||||||||
|
||||||||||
return $response; | ||||||||||
return $response; | ||||||||||
} | ||||||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to deprecate the old filter in case of 3rd party usage? cc @jesseeproductions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being that the
@since
isTBD
doesn't that mean this is a new filter. Not in production, yet?