Skip to content

Commit 9ce1e78

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 95dba6c + 654f67b commit 9ce1e78

File tree

12 files changed

+132
-94
lines changed

12 files changed

+132
-94
lines changed

.github/workflows/tests-mysql.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,3 @@ jobs:
7777
DB_PORT: ${{ job.services.mysql.ports[3306] }}
7878
DB_USERNAME: root
7979
run: php artisan test
80-
81-
- name: Test failure
82-
if: ${{ failure() }}
83-
run: docker exec "$PROJECT_NAME-php-fpm" cat storage/logs/laravel.log

.github/workflows/tests-postgres.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,3 @@ jobs:
7575
DB_USERNAME: snipeit
7676
DB_PASSWORD: password
7777
run: php artisan test
78-
79-
- name: Test failure
80-
if: ${{ failure() }}
81-
run: docker exec "$PROJECT_NAME-php-fpm" cat storage/logs/laravel.log

.github/workflows/tests-sqlite.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,3 @@ jobs:
5959
env:
6060
DB_CONNECTION: sqlite_testing
6161
run: php artisan test
62-
63-
- name: Test failure
64-
if: ${{ failure() }}
65-
run: docker exec "$PROJECT_NAME-php-fpm" cat storage/logs/laravel.log

app/Listeners/CheckoutableListener.php

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use App\Models\Component;
1717
use App\Models\Consumable;
1818
use App\Models\LicenseSeat;
19+
use App\Models\Location;
1920
use App\Models\Setting;
2021
use App\Models\User;
2122
use App\Notifications\CheckinAccessoryNotification;
@@ -60,14 +61,14 @@ public function onCheckedOut($event)
6061
$adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail));
6162
}
6263
$ccEmails = array_filter($adminCcEmailsArray);
63-
$notifiable = $event->checkedOutTo;
6464
$mailable = $this->getCheckoutMailType($event, $acceptance);
65+
$notifiable = $this->getNotifiables($event);
66+
67+
if (!$event->checkedOutTo->locale){
68+
$mailable->locale($event->checkedOutTo->locale);
69+
}
6570
// Send email notifications
6671
try {
67-
if (!$event->checkedOutTo->locale){
68-
$mailable->locale($event->checkedOutTo->locale);
69-
}
70-
7172
/**
7273
* Send an email if any of the following conditions are met:
7374
* 1. The asset requires acceptance
@@ -77,15 +78,20 @@ public function onCheckedOut($event)
7778

7879
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
7980
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
80-
if (!empty($notifiable->email)) {
81+
if (!empty($notifiable)) {
8182
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
82-
} else {
83+
} elseif (!empty($ccEmails)) {
8384
Mail::cc($ccEmails)->send($mailable);
8485
}
85-
Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
86-
}
87-
86+
Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
87+
}
88+
} catch (ClientException $e) {
89+
Log::debug("Exception caught during checkout email: " . $e->getMessage());
90+
} catch (Exception $e) {
91+
Log::debug("Exception caught during checkout email: " . $e->getMessage());
92+
}
8893
// Send Webhook notification
94+
try{
8995
if ($this->shouldSendWebhookNotification()) {
9096
if (Setting::getSettings()->webhook_selected === 'microsoft') {
9197
$message = $this->getCheckoutNotification($event)->toMicrosoftTeams();
@@ -137,38 +143,43 @@ public function onCheckedIn($event)
137143
$adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail));
138144
}
139145
$ccEmails = array_filter($adminCcEmailsArray);
140-
$notifiable = $event->checkedOutTo;
141146
$mailable = $this->getCheckinMailType($event);
147+
$notifiable = $this->getNotifiables($event);
142148

149+
if (!$event->checkedOutTo->locale){
150+
$mailable->locale($event->checkedOutTo->locale);
151+
}
143152
// Send email notifications
144153
try {
145-
if (!$event->checkedOutTo->locale){
146-
$mailable->locale($event->checkedOutTo->locale);
147-
}
148154
/**
149155
* Send an email if any of the following conditions are met:
150156
* 1. The asset requires acceptance
151157
* 2. The item has a EULA
152158
* 3. The item should send an email at check-in/check-out
153159
*/
154-
155160
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
156161
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
157-
if (!empty($notifiable->email)) {
162+
if (!empty($notifiable)) {
158163
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
159-
} else {
164+
} elseif (!empty($ccEmails)){
160165
Mail::cc($ccEmails)->send($mailable);
161166
}
162167
Log::info('Sending email, Locale: ' . $event->checkedOutTo->locale);
163168
}
169+
} catch (ClientException $e) {
170+
Log::debug("Exception caught during checkin email: " . $e->getMessage());
171+
} catch (Exception $e) {
172+
Log::debug("Exception caught during checkin email: " . $e->getMessage());
173+
}
164174

165-
// Send Webhook notification
175+
// Send Webhook notification
176+
try {
166177
if ($this->shouldSendWebhookNotification()) {
167178
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
168179
->notify($this->getCheckinNotification($event));
169180
}
170181
} catch (ClientException $e) {
171-
Log::warning("Exception caught during checkout notification: " . $e->getMessage());
182+
Log::warning("Exception caught during checkin notification: " . $e->getMessage());
172183
} catch (Exception $e) {
173184
Log::warning("Exception caught during checkin notification: " . $e->getMessage());
174185
}
@@ -278,6 +289,19 @@ private function getCheckinMailType($event){
278289
return new $mailable($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note);
279290

280291
}
292+
private function getNotifiables($event){
293+
294+
if($event->checkedOutTo instanceof Asset){
295+
$event->checkedOutTo->load('assignedTo');
296+
return $event->checkedOutTo->assignedto?->email ?? '';
297+
}
298+
else if($event->checkedOutTo instanceof Location) {
299+
return $event->checkedOutTo->manager?->email ?? '';
300+
}
301+
else{
302+
return $event->checkedOutTo->email;
303+
}
304+
}
281305

282306
/**
283307
* Register the listeners for the subscriber.

app/Mail/CheckinLicenseMail.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CheckinLicenseMail extends Mailable
2323
public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedInBy, $note)
2424
{
2525
$this->target = $checkedOutTo;
26-
$this->item = $licenseSeat->license;
26+
$this->item = $licenseSeat;
2727
$this->admin = $checkedInBy;
2828
$this->note = $note;
2929
$this->settings = Setting::getSettings();
@@ -50,7 +50,8 @@ public function content(): Content
5050
return new Content(
5151
markdown: 'mail.markdown.checkin-license',
5252
with: [
53-
'item' => $this->item,
53+
'license_seat' => $this->item,
54+
'license' => $this->item->license,
5455
'admin' => $this->admin,
5556
'note' => $this->note,
5657
'target' => $this->target,

app/Mail/CheckoutLicenseMail.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CheckoutLicenseMail extends Mailable
2222
*/
2323
public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
2424
{
25-
$this->item = $licenseSeat->license;
25+
$this->item = $licenseSeat;
2626
$this->admin = $checkedOutBy;
2727
$this->note = $note;
2828
$this->target = $checkedOutTo;
@@ -53,11 +53,11 @@ public function content(): Content
5353
$req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
5454

5555
$accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
56-
5756
return new Content(
5857
markdown: 'mail.markdown.checkout-license',
5958
with: [
60-
'item' => $this->item,
59+
'license_seat' => $this->item,
60+
'license' => $this->item->license,
6161
'admin' => $this->admin,
6262
'note' => $this->note,
6363
'target' => $this->target,

app/Notifications/CheckinAssetNotification.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\Setting;
88
use App\Models\User;
99
use Illuminate\Bus\Queueable;
10+
use Illuminate\Notifications\Channels\SlackWebhookChannel;
1011
use Illuminate\Notifications\Messages\MailMessage;
1112
use Illuminate\Notifications\Messages\SlackMessage;
1213
use Illuminate\Notifications\Notification;
@@ -62,7 +63,7 @@ public function via()
6263
}
6364
if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general' ) {
6465
Log::debug('use webhook');
65-
$notifyBy[] = 'slack';
66+
$notifyBy[] = SlackWebhookChannel::class;
6667
}
6768

6869
return $notifyBy;

0 commit comments

Comments
 (0)