/**
  * Toggles whether the user is checked in or not.
  *
  * @param \WP_REST_Request $request
  * @return \WP_Error|\WP_REST_Response
  */
 protected function _create_checkin_checkout_object(\WP_REST_Request $request)
 {
     $reg_id = $request->get_param('REG_ID');
     $dtt_id = $request->get_param('DTT_ID');
     $force = $request->get_param('force');
     if ($force == 'true') {
         $force = true;
     } else {
         $force = false;
     }
     $reg = \EEM_Registration::instance()->get_one_by_ID($reg_id);
     if (!$reg instanceof \EE_Registration) {
         return $this->send_response(new \WP_Error('rest_registration_toggle_checkin_invalid_id', sprintf(__('You cannot checkin registration with ID %1$s because it doesn\'t exist.', 'event_espresso'), $reg_id), array('status' => 422)));
     }
     if (!\EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
         return $this->send_response(new \WP_Error('rest_user_cannot_toggle_checkin', sprintf(__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), $reg_id), array('status' => 403)));
     }
     $success = $reg->toggle_checkin_status($dtt_id, !$force);
     if ($success === false) {
         //rely on EE_Error::add_error messages to have been added to give more data about hwy it failed
         return $this->send_response(new \WP_Error('rest_toggle_checkin_failed', __('Registration checkin failed. Please see additional error data.', 'event_espresso')));
     }
     $checkin = \EEM_Checkin::instance()->get_one(array(array('REG_ID' => $reg_id, 'DTT_ID' => $dtt_id), 'order_by' => array('CHK_timestamp' => 'DESC')));
     if (!$checkin instanceof \EE_Checkin) {
         return $this->send_response(new \WP_Error('rest_toggle_checkin_error', sprintf(__('Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', 'event_espresso'), $reg_id, $dtt_id)));
     }
     $requested_version = $this->get_requested_version($request->get_route());
     $get_request = new \WP_REST_Request('GET', \EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID());
     $get_request->set_url_params(array('id' => $checkin->ID()));
     return Read::handle_request_get_one($get_request);
 }
Пример #2
0
 /**
  * @param \WP_REST_Request $request
  * @return \EE_Config|\WP_Error
  */
 public static function handle_request(\WP_REST_Request $request)
 {
     $cap = \EE_Restriction_Generator_Base::get_default_restrictions_cap();
     if (\EE_Capabilities::instance()->current_user_can($cap, 'read_over_api')) {
         return \EE_Config::instance();
     } else {
         return new \WP_Error('cannot_read_config', sprintf(__('You do not have the necessary capabilities (%s) to read Event Espresso Configuration data', 'event_espresso'), $cap), array('status' => 403));
     }
 }
 public function create_job(JobParameters $job_parameters)
 {
     if (!\EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) {
         throw new BatchRequestException(__('You do not have permission to view contacts', 'event_espresso'));
     }
     $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(), __('contact-list-report.csv', 'event_espresso'));
     $job_parameters->add_extra_data('filepath', $filepath);
     $job_parameters->set_job_size($this->count_units_to_process());
     //we should also set the header columns
     $csv_data_for_row = $this->get_csv_data(0, 1);
     \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
     //if we actually processed a row there, record it
     if ($job_parameters->job_size()) {
         $job_parameters->mark_processed(1);
     }
     return new JobStepResponse($job_parameters, __('Contacts report started successfully...', 'event_espresso'));
 }
 /**
  * Performs any necessary setup for starting the job. This is also a good
  * place to setup the $job_arguments which will be used for subsequent HTTP requests
  * when continue_job will be called
  * @param JobParameters $job_parameters
  * @throws BatchRequestException
  * @return JobStepResponse
  */
 public function create_job(JobParameters $job_parameters)
 {
     $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
     if (!\EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
         throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
     }
     $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(), $this->get_filename_from_event($event_id));
     $job_parameters->add_extra_data('filepath', $filepath);
     $question_data_for_columns = $this->_get_questions_for_report($event_id);
     $job_parameters->add_extra_data('questions_data', $question_data_for_columns);
     $job_parameters->set_job_size($this->count_units_to_process($event_id));
     //we should also set the header columns
     $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('questions_data'));
     \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
     //if we actually processed a row there, record it
     if ($job_parameters->job_size()) {
         $job_parameters->mark_processed(1);
     }
     return new JobStepResponse($job_parameters, __('Registrations report started successfully...', 'event_espresso'));
 }
 /**
  * Creates a WP user with standard admin caps PLUS all EE CAPS (default)
  * @param array $ee_capabilities array of EE CAPS if you don't want the user to have ALL EE CAPS
  * @return WP_User
  */
 public function wp_admin_with_ee_caps($ee_capabilities = array())
 {
     /** @type WP_User $user */
     $user = $this->factory->user->create_and_get(array('role' => 'administrator'));
     $ee_capabilities = (array) $ee_capabilities;
     if (empty($ee_capabilities)) {
         EE_Registry::instance()->load_core('Capabilities');
         $ee_capabilities = EE_Capabilities::instance()->get_ee_capabilities();
     }
     foreach ($ee_capabilities as $ee_capability) {
         $user->add_cap($ee_capability);
     }
     return $user;
 }
 /**
  * Gets all the caps that are missing which impose a restriction on
  * queries made in this context
  * @param string $context one of EEM_Base::caps_ constants
  * @return EE_Default_Where_Conditions[] indexed by capability name
  */
 public function caps_missing($context = EEM_Base::caps_read)
 {
     $missing_caps = array();
     $cap_restrictions = $this->cap_restrictions($context);
     foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
         if (!EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name() . '_model_applying_caps')) {
             $missing_caps[$cap] = $restriction_if_no_cap;
         }
     }
     return $missing_caps;
 }
 /**
  * Utility function to just setup valid capabilities for tests in this suite.
  *
  * @since 1.0.0
  *
  * @return void
  */
 private function _pretend_capabilities_registered()
 {
     EE_Registry::instance()->load_core('Capabilities');
     EE_Capabilities::instance()->init_caps();
     //validate caps were registered and init saved.
     $admin_caps_init = EE_Capabilities::instance()->get_ee_capabilities('administrator');
     $this->assertArrayContains('edit_thing', $admin_caps_init);
     //verify new caps are in the role
     $role = get_role('administrator');
     $this->assertContains(array('edit_thing', 'edit_things', 'edit_others_things', 'edit_private_things'), $role->capabilities);
 }
 function test_capability_maps_registered_numeric()
 {
     $this->_pretend_capabilities_registered(false);
     //the best way to test this is to ensure the registered maps work.  So let's author an event by the user.
     //main users event.
     $event = $this->factory->event->create(array('EVT_wp_user' => $this->_user->ID));
     //other users event (checking others event caps).
     $user_id = $this->factory->user->create();
     $other_user = $this->factory->user->get_object_by_id($user_id);
     $other_event = $this->factory->event->create(array('EVT_wp_user' => $other_user->ID));
     //make sure we have an event
     $this->assertInstanceOf('EE_Event', $event);
     $this->assertInstanceOf('EE_Event', $other_event);
     //check map items for event.
     $this->assertTrue(EE_Capabilities::instance()->user_can($this->_user, 'test_read', 'testing_read', $event->ID()));
     $this->assertTrue(EE_Capabilities::instance()->user_can($this->_user, 'test_write', 'testing_edit', $event->ID()));
     $this->assertTrue(EE_Capabilities::instance()->user_can($this->_user, 'test_read', 'testing_read', $other_event->ID()));
     $this->assertTrue(EE_Capabilities::instance()->user_can($this->_user, 'test_write', 'testing_edit', $other_event->ID()));
 }
 public static function deregister($cap_reference = NULL)
 {
     if (!empty(self::$_registry[$cap_reference])) {
         unset(self::$_registry[$cap_reference]);
     }
     //re init caps to grab the changes due to removed caps.
     EE_Capabilities::instance()->init_caps();
 }