/** * @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; }
/** * Sends the assignee email. * * @param Gravity_Flow_Assignee $assignee */ public function send_assignee_notification($assignee) { $this->log_debug(__METHOD__ . '() starting. assignee: ' . $assignee->get_key()); $form = $this->get_form(); $notification['workflow_notification_type'] = 'assignee'; $notification['fromName'] = empty($this->assignee_notification_from_name) ? get_bloginfo() : $this->assignee_notification_from_name; $notification['from'] = empty($this->assignee_notification_from_email) ? get_bloginfo('admin_email') : $this->assignee_notification_from_email; $notification['replyTo'] = $this->assignee_notification_reply_to; $notification['bcc'] = $this->assignee_notification_bcc; $notification['subject'] = empty($this->assignee_notification_subject) ? $form['title'] . ': ' . $this->get_name() : $this->assignee_notification_subject; $notification['message'] = $this->assignee_notification_message; if (defined('PDF_EXTENDED_VERSION') && version_compare(PDF_EXTENDED_VERSION, '4.0-beta2', '>=')) { if ($this->assignee_notification_gpdfEnable) { $gpdf_id = $this->assignee_notification_gpdfValue; $notification = $this->gpdf_add_notification_attachment($notification, $gpdf_id); } } $assignee_type = $assignee->get_type(); $assignee_id = $assignee->get_id(); if ($assignee_type == 'email') { $email = $assignee_id; $notification['id'] = 'workflow_step_' . $this->get_id() . '_user_' . $email; $notification['name'] = $notification['id']; $notification['to'] = $email; $notification['message'] = $this->replace_variables($this->assignee_notification_message, $assignee); $this->send_notification($notification); return; } if ($assignee_type == 'role') { $users = get_users(array('role' => $assignee_id)); } else { $users = get_users(array('include' => array($assignee_id))); } $this->log_debug(__METHOD__ . sprintf('() sending assignee notifications to %d users', count($users))); foreach ($users as $user) { $notification['id'] = 'workflow_step_' . $this->get_id() . '_user_' . $user->ID; $notification['name'] = $notification['id']; $notification['to'] = $user->user_email; $notification['message'] = $this->replace_variables($this->assignee_notification_message, $assignee); $this->send_notification($notification); } }
/** * @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; }