Skip to content

Commit

Permalink
Merge pull request #15808 from Godmartinz/check-license-for-email-boo…
Browse files Browse the repository at this point in the history
…lean

Fixed checkin/checkout email boolean check for Licenses
  • Loading branch information
snipe authored Nov 13, 2024
2 parents ada8e77 + 1061df8 commit 381c6e0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/Listeners/CheckoutableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function onCheckedOut($event)
*/

if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
$this->checkoutableShouldSendEmail($event)) {
Log::info('Sending checkout email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
if (!empty($notifiable)) {
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
Expand Down Expand Up @@ -146,7 +146,6 @@ public function onCheckedIn($event)
$ccEmails = array_filter($adminCcEmailsArray);
$mailable = $this->getCheckinMailType($event);
$notifiable = $this->getNotifiables($event);

if (!$event->checkedOutTo->locale){
$mailable->locale($event->checkedOutTo->locale);
}
Expand All @@ -159,7 +158,7 @@ public function onCheckedIn($event)
* 3. The item should send an email at check-in/check-out
*/
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
$this->checkoutableShouldSendEmail($event)) {
Log::info('Sending checkin email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
if (!empty($notifiable)) {
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
Expand Down Expand Up @@ -338,4 +337,12 @@ private function shouldSendWebhookNotification(): bool
{
return Setting::getSettings() && Setting::getSettings()->webhook_endpoint;
}

private function checkoutableShouldSendEmail($event): bool
{
if($event->checkoutable instanceof LicenseSeat){
return $event->checkoutable->license->checkin_email();
}
return (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email());
}
}

0 comments on commit 381c6e0

Please sign in to comment.