/**
  * @param Gravity_Flow_Assignee $assignee
  * @param $new_status
  * @param $form
  *
  * @return bool|string If processed return a message to be displayed to the user.
  */
 public function process_assignee_status($assignee, $new_status, $form)
 {
     $feedback = false;
     if (!in_array($new_status, array('pending', 'approved', 'rejected', 'revert'))) {
         return $feedback;
     }
     $current_user_status = $assignee->get_status();
     $current_role_status = false;
     $role = false;
     foreach (gravity_flow()->get_user_roles() as $role) {
         $current_role_status = $this->get_role_status($role);
         if ($current_role_status == 'pending') {
             break;
         }
     }
     if ($current_user_status != 'pending' && $current_role_status != 'pending') {
         return esc_html__('The status could not be changed because this step has already been processed.', 'gravityflow');
     }
     if ($new_status == 'revert') {
         if ($this->revertEnable) {
             $step = gravity_flow()->get_step($this->revertValue, $this->get_entry());
             if ($step) {
                 $this->end();
                 $note = $this->get_name() . ': ' . esc_html__('Reverted to step', 'gravityflow') . ' - ' . $step->get_label();
                 $user_note = rgpost('gravityflow_note');
                 if (!empty($user_note)) {
                     $note .= sprintf("\n%s: %s", __('Note', 'gravityflow'), $user_note);
                 }
                 $this->add_note($note);
                 $step->start();
                 $feedback = esc_html__('Reverted to step:', 'gravityflow') . ' ' . $step->get_label();
             }
         }
         return $feedback;
     }
     if ($current_user_status == 'pending') {
         $assignee->update_status($new_status);
     }
     if ($current_role_status == 'pending') {
         $this->update_role_status($role, $new_status);
     }
     $note = '';
     if ($new_status == 'approved') {
         $note = $this->get_name() . ': ' . __('Approved.', 'gravityflow');
         $this->send_approval_notification();
     } elseif ($new_status == 'rejected') {
         $note = $this->get_name() . ': ' . __('Rejected.', 'gravityflow');
         $this->send_rejection_notification();
     }
     if (!empty($note)) {
         $user_note = rgpost('gravityflow_note');
         if (!empty($user_note)) {
             $note .= sprintf("\n%s: %s", __('Note', 'gravityflow'), $user_note);
         }
         $user_id = $assignee->get_type() == 'user_id' ? $assignee->get_id() : 0;
         $this->add_note($note, $user_id, $assignee->get_display_name());
     }
     $status = $this->evaluate_status();
     $this->update_step_status($status);
     $entry = $this->refresh_entry();
     GFAPI::send_notifications($form, $entry, 'workflow_approval');
     switch ($new_status) {
         case 'approved':
             $feedback = __('Entry Approved', 'gravityflow');
             break;
         case 'rejected':
             $feedback = __('Entry Rejected', 'gravityflow');
             break;
     }
     return $feedback;
 }
Ejemplo n.º 2
0
 /**
  * @param Gravity_Flow_Assignee $assignee
  *
  * @return array
  */
 function get_assignee_array($assignee)
 {
     return array('key' => $assignee->get_key(), 'id' => $assignee->get_id(), 'type' => $assignee->get_type(), 'display_name' => $assignee->get_display_name(), 'status' => $assignee->get_status());
 }
 /**
  * Loosely based on the JWT spec.
  *
  * @param Gravity_Flow_Assignee $assignee
  * @param array $scopes
  * @param string $expiration_timestamp
  *
  * @return string
  */
 public function generate_access_token($assignee, $scopes = array(), $expiration_timestamp = false)
 {
     if (empty($scopes)) {
         $scopes = array('pages' => array('inbox', 'status'));
     }
     if (empty($expiration_timestamp)) {
         $expiration_timestamp = strtotime('+30 days');
     }
     $jti = uniqid();
     $token_array = array('iat' => time(), 'exp' => $expiration_timestamp, 'sub' => $assignee->get_key(), 'scopes' => $scopes, 'jti' => $jti);
     $token = rawurlencode(base64_encode(json_encode($token_array)));
     $secret = get_option('gravityflow_token_secret');
     if (empty($secret)) {
         $secret = wp_generate_password(64);
         update_option('gravityflow_token_secret', $secret);
     }
     $sig = hash_hmac('sha256', $token, $secret);
     $token .= '.' . $sig;
     $this->log_event('token', 'generated', 0, 0, json_encode($token_array), 0, 0, $assignee->get_id(), $assignee->get_type(), $assignee->get_display_name());
     return $token;
 }