Skip to content

Commit

Permalink
feat: suppress cancel emails in bulk upload
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton committed Jul 9, 2024
1 parent 435fc09 commit 9ad0c76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion classes/booking_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public function process() {
if (facetoface_user_cancel($session, $user->id, true, $cancelerr)) {
// Notify the user of the cancellation if the session hasn't started yet.
$timenow = time();
if (!facetoface_has_session_started($session, $timenow)) {
if (!facetoface_has_session_started($session, $timenow) && !$this->suppressemail) {
facetoface_send_cancellation_notice($this->facetoface, $session, $user->id);
}
} else {
Expand Down
21 changes: 16 additions & 5 deletions tests/upload_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,29 +550,40 @@ public function test_updates_for_previous_sessions() {
*/
public static function email_suppression_provider(): array {
return [
'no suppression' => [
'no suppression, booked' => [
'status' => 'booked',
'shouldsuppress' => false,
],
'suppressed emails' => [
'suppressed emails, booked' => [
'status' => 'booked',
'shouldsuppress' => true,
],
'no suppression, cancel' => [
'status' => 'cancelled',
'shouldsuppress' => false,
],
'suppressed emails, cancel' => [
'status' => 'cancelled',
'shouldsuppress' => true,
],
];
}

/**
* Tests that the email suppression property is considered when signing up users.
* @param string $status status of session to use in csv
* @param bool $shouldsuppress
* @dataProvider email_suppression_provider
*/
public function test_email_suppression($shouldsuppress) {
public function test_email_suppression(string $status, bool $shouldsuppress) {
/** @var \mod_facetoface_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_facetoface');

// Create f2f in course.
// Note the f2f must have a confirmation message & subject set, otherwise no emails will be sent ever.
$course = $this->getDataGenerator()->create_course();
$facetoface = $generator->create_instance(['course' => $course->id, 'confirmationmessage' => 'test',
'confirmationsubject' => 'test']);
'confirmationsubject' => 'test', 'cancellationmessage' => 'test', 'cancellationsubject' => 'test']);
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');

$this->setCurrentTimeStart();
Expand All @@ -595,7 +606,7 @@ public function test_email_suppression($shouldsuppress) {
$record = (object) [
'email' => $student->email,
'session' => $session->id,
'status' => 'booked',
'status' => $status,
];

$records = [$record];
Expand Down

0 comments on commit 9ad0c76

Please sign in to comment.