← All changes
|
jetpack_vendor/automattic/jetpack-licensing/src/class-endpoints.php
+6
-22
12.5.2
→
16.3-beta
View file →
| @@ -7,13 +7,14 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Licensing; |
| 9 | 9 | |
| 10 | 10 | use Automattic\Jetpack\Connection\Client; |
| 11 | -use Automattic\Jetpack\Connection\Manager as Connection_Manager; | |
| 12 | 11 | use Automattic\Jetpack\Licensing; |
| 13 | 12 | use Automattic\Jetpack\Status\Visitor; |
| 14 | 13 | use Jetpack_Options; |
| 15 | 14 | use WP_Error; |
| 15 | +use WP_REST_Request; | |
| 16 | +use WP_REST_Response; | |
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Class Endpoints. |
| 19 | 20 | * Helper class that is responsible for registering and responding to licensing endpoint requests. |
| @@ -106,9 +107,9 @@ | ||
| 106 | 107 | 'licensing/user/licenses', |
| 107 | 108 | array( |
| 108 | 109 | 'methods' => \WP_REST_Server::READABLE, |
| 109 | 110 | 'callback' => __CLASS__ . '::get_user_licenses', |
| 110 | - 'permission_callback' => __CLASS__ . '::user_licensing_permission_check', | |
| 111 | + 'permission_callback' => __CLASS__ . '::can_manage_options_check', | |
| 111 | 112 | ) |
| 112 | 113 | ); |
| 113 | 114 | |
| 114 | 115 | /** |
| @@ -119,9 +120,9 @@ | ||
| 119 | 120 | 'licensing/user/counts', |
| 120 | 121 | array( |
| 121 | 122 | 'methods' => \WP_REST_Server::READABLE, |
| 122 | 123 | 'callback' => __CLASS__ . '::get_user_license_counts', |
| 123 | - 'permission_callback' => __CLASS__ . '::user_licensing_permission_check', | |
| 124 | + 'permission_callback' => __CLASS__ . '::can_manage_options_check', | |
| 124 | 125 | ) |
| 125 | 126 | ); |
| 126 | 127 | |
| 127 | 128 | /** |
| @@ -132,9 +133,9 @@ | ||
| 132 | 133 | 'licensing/user/activation-notice-dismiss', |
| 133 | 134 | array( |
| 134 | 135 | 'methods' => \WP_REST_Server::EDITABLE, |
| 135 | 136 | 'callback' => __CLASS__ . '::update_licensing_activation_notice_dismiss', |
| 136 | - 'permission_callback' => __CLASS__ . '::user_licensing_permission_check', | |
| 137 | + 'permission_callback' => __CLASS__ . '::can_manage_options_check', | |
| 137 | 138 | 'args' => array( |
| 138 | 139 | 'last_detached_count' => array( |
| 139 | 140 | 'required' => true, |
| 140 | 141 | 'type' => 'integer', |
| @@ -152,9 +153,9 @@ | ||
| 152 | 153 | '/licensing/attach-licenses', |
| 153 | 154 | array( |
| 154 | 155 | 'methods' => \WP_REST_Server::EDITABLE, |
| 155 | 156 | 'callback' => __CLASS__ . '::attach_jetpack_licenses', |
| 156 | - 'permission_callback' => __CLASS__ . '::user_licensing_permission_check', | |
| 157 | + 'permission_callback' => __CLASS__ . '::can_manage_options_check', | |
| 157 | 158 | 'args' => array( |
| 158 | 159 | 'licenses' => array( |
| 159 | 160 | 'required' => true, |
| 160 | 161 | 'type' => 'array', |
| @@ -181,25 +182,8 @@ | ||
| 181 | 182 | return true; |
| 182 | 183 | } |
| 183 | 184 | |
| 184 | 185 | return new WP_Error( 'invalid_user_permission_set_jetpack_license_key', self::$user_permissions_error_msg, array( 'status' => rest_authorization_required_code() ) ); |
| 185 | - } | |
| 186 | - | |
| 187 | - /** | |
| 188 | - * Verify that user can view and update user-licensing data. | |
| 189 | - * | |
| 190 | - * @since 1.7.0 | |
| 191 | - * | |
| 192 | - * @return bool Whether the user is currently connected and they are the connection owner. | |
| 193 | - */ | |
| 194 | - public static function user_licensing_permission_check() { | |
| 195 | - $connection_manager = new Connection_Manager( 'jetpack' ); | |
| 196 | - | |
| 197 | - if ( $connection_manager->is_user_connected() && $connection_manager->is_connection_owner() ) { | |
| 198 | - return true; | |
| 199 | - } | |
| 200 | - | |
| 201 | - return new WP_Error( 'invalid_permission_manage_user_licenses', self::$user_permissions_error_msg, array( 'status' => rest_authorization_required_code() ) ); | |
| 202 | 186 | } |
| 203 | 187 | |
| 204 | 188 | /** |
| 205 | 189 | * Verify that user can manage_options |