| @@ 26-41 (lines=16) @@ | ||
| 23 | */ |
|
| 24 | protected function verifyCurrentUserCan($required_permission, $attempted_calculation) |
|
| 25 | { |
|
| 26 | if (! current_user_can($required_permission)) { |
|
| 27 | throw new RestException( |
|
| 28 | 'permission_denied', |
|
| 29 | sprintf( |
|
| 30 | __( |
|
| 31 | // @codingStandardsIgnoreStart |
|
| 32 | 'Permission denied, you cannot calculate %1$s on %2$s because you do not have the capability "%3$s"', |
|
| 33 | // @codingStandardsIgnoreEnd |
|
| 34 | 'event_espresso' |
|
| 35 | ), |
|
| 36 | $attempted_calculation, |
|
| 37 | EEH_Inflector::pluralize_and_lower($this->getResourceName()), |
|
| 38 | $required_permission |
|
| 39 | ) |
|
| 40 | ); |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||
| 44 | ||
| @@ 137-151 (lines=15) @@ | ||
| 134 | { |
|
| 135 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create'); |
|
| 136 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
| 137 | if (! current_user_can($default_cap_to_check_for)) { |
|
| 138 | throw new RestException( |
|
| 139 | 'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
| 140 | sprintf( |
|
| 141 | esc_html__( |
|
| 142 | // @codingStandardsIgnoreStart |
|
| 143 | 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to insert data into Event Espresso.', |
|
| 144 | // @codingStandardsIgnoreEnd |
|
| 145 | 'event_espresso' |
|
| 146 | ), |
|
| 147 | $default_cap_to_check_for |
|
| 148 | ), |
|
| 149 | array('status' => 403) |
|
| 150 | ); |
|
| 151 | } |
|
| 152 | $submitted_json_data = array_merge((array) $request->get_body_params(), (array) $request->get_json_params()); |
|
| 153 | $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
| 154 | $submitted_json_data, |
|
| @@ 189-203 (lines=15) @@ | ||
| 186 | { |
|
| 187 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
| 188 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
| 189 | if (! current_user_can($default_cap_to_check_for)) { |
|
| 190 | throw new RestException( |
|
| 191 | 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
| 192 | sprintf( |
|
| 193 | esc_html__( |
|
| 194 | // @codingStandardsIgnoreStart |
|
| 195 | 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to update data into Event Espresso.', |
|
| 196 | // @codingStandardsIgnoreEnd |
|
| 197 | 'event_espresso' |
|
| 198 | ), |
|
| 199 | $default_cap_to_check_for |
|
| 200 | ), |
|
| 201 | array('status' => 403) |
|
| 202 | ); |
|
| 203 | } |
|
| 204 | $obj_id = $request->get_param('id'); |
|
| 205 | if (! $obj_id) { |
|
| 206 | throw new RestException( |
|
| @@ 243-257 (lines=15) @@ | ||
| 240 | { |
|
| 241 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete'); |
|
| 242 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
| 243 | if (! current_user_can($default_cap_to_check_for)) { |
|
| 244 | throw new RestException( |
|
| 245 | 'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
| 246 | sprintf( |
|
| 247 | esc_html__( |
|
| 248 | // @codingStandardsIgnoreStart |
|
| 249 | 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to delete data into Event Espresso.', |
|
| 250 | // @codingStandardsIgnoreEnd |
|
| 251 | 'event_espresso' |
|
| 252 | ), |
|
| 253 | $default_cap_to_check_for |
|
| 254 | ), |
|
| 255 | array('status' => 403) |
|
| 256 | ); |
|
| 257 | } |
|
| 258 | $obj_id = $request->get_param('id'); |
|
| 259 | // this is where we would apply more fine-grained caps |
|
| 260 | $model_obj = $model->get_one_by_ID($obj_id); |
|
| @@ 567-581 (lines=15) @@ | ||
| 564 | // Check generic caps. For now, we're only allowing access to this endpoint to full admins. |
|
| 565 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
| 566 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
| 567 | if (! current_user_can($default_cap_to_check_for)) { |
|
| 568 | throw new RestException( |
|
| 569 | 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
| 570 | sprintf( |
|
| 571 | esc_html__( |
|
| 572 | // @codingStandardsIgnoreStart |
|
| 573 | 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to add relations in Event Espresso.', |
|
| 574 | // @codingStandardsIgnoreEnd |
|
| 575 | 'event_espresso' |
|
| 576 | ), |
|
| 577 | $default_cap_to_check_for |
|
| 578 | ), |
|
| 579 | array('status' => 403) |
|
| 580 | ); |
|
| 581 | } |
|
| 582 | // Get the main model object. |
|
| 583 | $model_obj = $this->getOneOrThrowException($model, $request->get_param('id')); |
|
| 584 | // For now, we require the other model object to exist too. This might be relaxed later. |
|