Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Nov 6, 2024
2 parents 95dba6c + 654f67b commit 9ce1e78
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 94 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/tests-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,3 @@ jobs:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
DB_USERNAME: root
run: php artisan test

- name: Test failure
if: ${{ failure() }}
run: docker exec "$PROJECT_NAME-php-fpm" cat storage/logs/laravel.log
4 changes: 0 additions & 4 deletions .github/workflows/tests-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,3 @@ jobs:
DB_USERNAME: snipeit
DB_PASSWORD: password
run: php artisan test

- name: Test failure
if: ${{ failure() }}
run: docker exec "$PROJECT_NAME-php-fpm" cat storage/logs/laravel.log
4 changes: 0 additions & 4 deletions .github/workflows/tests-sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,3 @@ jobs:
env:
DB_CONNECTION: sqlite_testing
run: php artisan test

- name: Test failure
if: ${{ failure() }}
run: docker exec "$PROJECT_NAME-php-fpm" cat storage/logs/laravel.log
62 changes: 43 additions & 19 deletions app/Listeners/CheckoutableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Models\Component;
use App\Models\Consumable;
use App\Models\LicenseSeat;
use App\Models\Location;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
Expand Down Expand Up @@ -60,14 +61,14 @@ public function onCheckedOut($event)
$adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail));
}
$ccEmails = array_filter($adminCcEmailsArray);
$notifiable = $event->checkedOutTo;
$mailable = $this->getCheckoutMailType($event, $acceptance);
$notifiable = $this->getNotifiables($event);

if (!$event->checkedOutTo->locale){
$mailable->locale($event->checkedOutTo->locale);
}
// Send email notifications
try {
if (!$event->checkedOutTo->locale){
$mailable->locale($event->checkedOutTo->locale);
}

/**
* Send an email if any of the following conditions are met:
* 1. The asset requires acceptance
Expand All @@ -77,15 +78,20 @@ public function onCheckedOut($event)

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

Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
}
} catch (ClientException $e) {
Log::debug("Exception caught during checkout email: " . $e->getMessage());
} catch (Exception $e) {
Log::debug("Exception caught during checkout email: " . $e->getMessage());
}
// Send Webhook notification
try{
if ($this->shouldSendWebhookNotification()) {
if (Setting::getSettings()->webhook_selected === 'microsoft') {
$message = $this->getCheckoutNotification($event)->toMicrosoftTeams();
Expand Down Expand Up @@ -137,38 +143,43 @@ public function onCheckedIn($event)
$adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail));
}
$ccEmails = array_filter($adminCcEmailsArray);
$notifiable = $event->checkedOutTo;
$mailable = $this->getCheckinMailType($event);
$notifiable = $this->getNotifiables($event);

if (!$event->checkedOutTo->locale){
$mailable->locale($event->checkedOutTo->locale);
}
// Send email notifications
try {
if (!$event->checkedOutTo->locale){
$mailable->locale($event->checkedOutTo->locale);
}
/**
* Send an email if any of the following conditions are met:
* 1. The asset requires acceptance
* 2. The item has a EULA
* 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())) {
if (!empty($notifiable->email)) {
if (!empty($notifiable)) {
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
} else {
} elseif (!empty($ccEmails)){
Mail::cc($ccEmails)->send($mailable);
}
Log::info('Sending email, Locale: ' . $event->checkedOutTo->locale);
}
} catch (ClientException $e) {
Log::debug("Exception caught during checkin email: " . $e->getMessage());
} catch (Exception $e) {
Log::debug("Exception caught during checkin email: " . $e->getMessage());
}

// Send Webhook notification
// Send Webhook notification
try {
if ($this->shouldSendWebhookNotification()) {
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
->notify($this->getCheckinNotification($event));
}
} catch (ClientException $e) {
Log::warning("Exception caught during checkout notification: " . $e->getMessage());
Log::warning("Exception caught during checkin notification: " . $e->getMessage());
} catch (Exception $e) {
Log::warning("Exception caught during checkin notification: " . $e->getMessage());
}
Expand Down Expand Up @@ -278,6 +289,19 @@ private function getCheckinMailType($event){
return new $mailable($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note);

}
private function getNotifiables($event){

if($event->checkedOutTo instanceof Asset){
$event->checkedOutTo->load('assignedTo');
return $event->checkedOutTo->assignedto?->email ?? '';
}
else if($event->checkedOutTo instanceof Location) {
return $event->checkedOutTo->manager?->email ?? '';
}
else{
return $event->checkedOutTo->email;
}
}

/**
* Register the listeners for the subscriber.
Expand Down
5 changes: 3 additions & 2 deletions app/Mail/CheckinLicenseMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CheckinLicenseMail extends Mailable
public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedInBy, $note)
{
$this->target = $checkedOutTo;
$this->item = $licenseSeat->license;
$this->item = $licenseSeat;
$this->admin = $checkedInBy;
$this->note = $note;
$this->settings = Setting::getSettings();
Expand All @@ -50,7 +50,8 @@ public function content(): Content
return new Content(
markdown: 'mail.markdown.checkin-license',
with: [
'item' => $this->item,
'license_seat' => $this->item,
'license' => $this->item->license,
'admin' => $this->admin,
'note' => $this->note,
'target' => $this->target,
Expand Down
6 changes: 3 additions & 3 deletions app/Mail/CheckoutLicenseMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CheckoutLicenseMail extends Mailable
*/
public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
{
$this->item = $licenseSeat->license;
$this->item = $licenseSeat;
$this->admin = $checkedOutBy;
$this->note = $note;
$this->target = $checkedOutTo;
Expand Down Expand Up @@ -53,11 +53,11 @@ public function content(): Content
$req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;

$accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);

return new Content(
markdown: 'mail.markdown.checkout-license',
with: [
'item' => $this->item,
'license_seat' => $this->item,
'license' => $this->item->license,
'admin' => $this->admin,
'note' => $this->note,
'target' => $this->target,
Expand Down
3 changes: 2 additions & 1 deletion app/Notifications/CheckinAssetNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Setting;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Channels\SlackWebhookChannel;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function via()
}
if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general' ) {
Log::debug('use webhook');
$notifyBy[] = 'slack';
$notifyBy[] = SlackWebhookChannel::class;
}

return $notifyBy;
Expand Down
Loading

0 comments on commit 9ce1e78

Please sign in to comment.