Skip to content

Commit

Permalink
[issue tracker] Fix emailing bug (#8300)
Browse files Browse the repository at this point in the history
The logic to send emails to watchers and assignee was off. Watchers ended up receiving emails that an issue was assigned to them even though it was not. With this bug fix:

- an "issue assigned" email is sent to new assignees
- a 'issue changed' email is sent to watchers
  • Loading branch information
cmadjar committed Feb 15, 2023
1 parent ea50380 commit de5e460
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions modules/issue_tracker/php/edit.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class Edit extends \NDB_Page implements ETagCalculator
$db->replace('issues_watching', $nowWatching);

// sending email
$this->emailUser($issueID, $issueValues['assignee'], $user);
$this->emailUser($issueID, $issueValues['assignee'], '', $user);
}

// Adding others from multiselect to watching table.
Expand Down Expand Up @@ -519,7 +519,7 @@ class Edit extends \NDB_Page implements ETagCalculator
) {
continue;
}
$this->emailUser($issueID, $usersWatching, $user);
$this->emailUser($issueID, '', $usersWatching, $user);
}
}
}
Expand Down Expand Up @@ -550,12 +550,14 @@ class Edit extends \NDB_Page implements ETagCalculator
*
* @param int $issueID the issueID
* @param string $changed_assignee changed assignee
* @param string $changed_watcher changed watcher
* @param \User $user the user requesting the change
*
* @return void
*/
function emailUser(int $issueID, string $changed_assignee, \User $user)
{
function emailUser(int $issueID, string $changed_assignee,
string $changed_watcher, \User $user
) {
$db = $this->loris->getDatabaseConnection();
$baseurl = \NDB_Factory::singleton()->settings()->getBaseURL();

Expand Down Expand Up @@ -597,9 +599,6 @@ class Edit extends \NDB_Page implements ETagCalculator
$msg_data
);
}
} else {
// so query below doesn't break..
$changed_assignee = $user->getUsername();
}

$issue_change_emails = $db->pselect(
Expand All @@ -611,12 +610,12 @@ class Edit extends \NDB_Page implements ETagCalculator
INNER JOIN issues_watching w ON (w.userID = u.UserID)
WHERE
w.issueID = :issueID
AND w.userID = :uid
AND u.UserID = :assignee",
AND u.UserID = :watcher
AND u.UserID != :currentUser",
[
'issueID' => $issueID,
'uid' => $user->getUsername(),
'assignee' => $changed_assignee,
'issueID' => $issueID,
'watcher' => $changed_watcher,
'currentUser' => $user->getUserName(),
]
);

Expand Down

0 comments on commit de5e460

Please sign in to comment.