Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Template Variables in Ticket Filter #5283

Merged
merged 2 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions include/class.filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,14 @@ function getActions() {
* If the matches() method returns TRUE, send the initial ticket to this
* method to apply the filter actions defined
*/
function apply(&$ticket, $vars) {
function apply(&$ticket, $vars, $postCreate=false) {
foreach ($this->getActions() as $a) {
//control when certain actions should be applied
//if action is send email and postCreate == false, skip
//if action is not send email and postCreate == true, skip
if ((($a->type == 'email') ? !$postCreate : $postCreate))
protich marked this conversation as resolved.
Show resolved Hide resolved
continue;

$a->setFilter($this);
$a->apply($ticket, $vars);
}
Expand Down Expand Up @@ -848,9 +854,9 @@ function getMatchingFilterList() {
* should be rejected, the first filter that matches and has reject
* ticket set is returned.
*/
function apply(&$ticket) {
function apply(&$ticket, $postCreate=false) {
foreach ($this->getMatchingFilterList() as $filter) {
$filter->apply($ticket, $this->vars);
$filter->apply($ticket, $this->vars, $postCreate);
if ($filter->stopOnMatch()) break;
}
}
Expand Down
15 changes: 10 additions & 5 deletions include/class.filter_action.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,18 @@ class FA_SendEmail extends TriggerAction {
function apply(&$ticket, array $info) {
global $ost;

if (!$ticket['ticket'])
return false;

$config = $this->getConfiguration();
$info = array('subject' => $config['subject'],
'message' => $config['message']);
$info = $ost->replaceTemplateVariables(
$info, array('ticket' => $ticket)
$vars = array(
'url' => $ost->getConfig()->getBaseUrl(),
'ticket' => $ticket['ticket'],
);
$info = $ost->replaceTemplateVariables(array(
'subject' => $config['subject'],
'message' => $config['message'],
), $vars);

// Honor FROM address settings
if (!$config['from'] || !($mailer = Email::lookup($config['from'])))
Expand Down Expand Up @@ -558,7 +564,6 @@ function apply(&$ticket, array $info) {
$I = $replacer->replaceVars($info);
$mailer->send($recipient, $I['subject'], $I['message']);
}

}

static function getVarScope() {
Expand Down
9 changes: 6 additions & 3 deletions include/class.ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -3902,7 +3902,7 @@ function getUserStats($user) {
return db_fetch_array(db_query($sql));
}

protected function filterTicketData($origin, $vars, $forms, $user=false) {
protected function filterTicketData($origin, $vars, $forms, $user=false, $postCreate=false) {
global $cfg;

// Unset all the filter data field data in case things change
Expand Down Expand Up @@ -3960,7 +3960,7 @@ protected function filterTicketData($origin, $vars, $forms, $user=false) {

// Init ticket filters...
$ticket_filter = new TicketFilter($origin, $vars);
$ticket_filter->apply($vars);
$ticket_filter->apply($vars, $postCreate);
}
catch (FilterDataChanged $ex) {
// Don't pass user recursively, assume the user has changed
Expand Down Expand Up @@ -4098,7 +4098,7 @@ static function create($vars, &$errors, $origin, $autorespond=true,

try {
$vars = self::filterTicketData($origin, $vars,
array_merge(array($form), $topic_forms), $user);
array_merge(array($form), $topic_forms), $user, false);
}
catch (RejectedException $ex) {
return $reject_ticket(
Expand Down Expand Up @@ -4299,6 +4299,9 @@ static function create($vars, &$errors, $origin, $autorespond=true,
return null;

/* -------------------- POST CREATE ------------------------ */
$vars['ticket'] = $ticket;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use only certain filters with actions like Send Email, etc.

self::filterTicketData($origin, $vars,
array_merge(array($form), $topic_forms), $user, true);

// Save the (common) dynamic form
// Ensure we have a subject
Expand Down