Skip to content

Commit

Permalink
Merge pull request #15763 from Godmartinz/no_to_email_check
Browse files Browse the repository at this point in the history
Fixed emails not being send if target has no email or if not instance of User. Cc_emails will still be sent.
  • Loading branch information
snipe authored Oct 31, 2024
2 parents 49de070 + 21a27dc commit 5897d37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
19 changes: 13 additions & 6 deletions app/Listeners/CheckoutableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ public function onCheckedOut($event)
* 2. The item has a EULA
* 3. The item should send an email at check-in/check-out
*/
if ($notifiable instanceof User && $notifiable->email != '') {

if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
if (!empty($notifiable->email)) {
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
} else {
Mail::cc($ccEmails)->send($mailable);
}
Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
}
}

// Send Webhook notification
if ($this->shouldSendWebhookNotification()) {
if (Setting::getSettings()->webhook_selected === 'microsoft') {
Expand Down Expand Up @@ -148,13 +152,16 @@ public function onCheckedIn($event)
* 3. The item should send an email at check-in/check-out
*/

if ($notifiable instanceof User && $notifiable->email != '') {
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
if (!empty($notifiable->email)) {
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
} else {
Mail::cc($ccEmails)->send($mailable);
}
Log::info('Sending email, Locale: ' . $event->checkedOutTo->locale);
}
}

// Send Webhook notification
if ($this->shouldSendWebhookNotification()) {
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
Expand Down
21 changes: 0 additions & 21 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
use App\Http\Controllers\Auth\ForgotPasswordController;
use App\Http\Controllers\Auth\ResetPasswordController;
use App\Livewire\Importer;
use App\Models\Asset;
use App\Models\User;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;

Expand Down Expand Up @@ -551,22 +549,3 @@
'/',
[DashboardController::class, 'index']
)->name('home');
Route::get('/test-email', function() {
$item = Asset::find(1); // Load some test data
$admin = User::find(1);
$target = User::find(2);
$acceptance = null; // Simulate acceptance data
$note = 'Test note';

$fields = [];
if (($item->model) && ($item->model->fieldset)) {
$fields = $item->model->fieldset->fields;
}

return new \App\Mail\CheckoutAssetMail(
$item,
$admin,
$target,
$acceptance,
$note);
});

0 comments on commit 5897d37

Please sign in to comment.