Skip to content

Commit 95dba6c

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 931ab10 + 5897d37 commit 95dba6c

18 files changed

+331
-124
lines changed

app/Helpers/Helper.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Illuminate\Contracts\Encryption\DecryptException;
1717
use Carbon\Carbon;
1818
use Illuminate\Support\Facades\Log;
19+
use Illuminate\Support\Str;
1920
use Intervention\Image\ImageManagerStatic as Image;
2021
use Illuminate\Support\Facades\Session;
2122

@@ -708,6 +709,28 @@ public static function generateRandomString($length = 10)
708709

709710
return $randomString;
710711
}
712+
/**
713+
* A method to be used to handle deprecations notifications, currently handling MS Teams. more can be added when needed.
714+
*
715+
*
716+
* @author [Godfrey Martinez]
717+
* @since [v7.0.14]
718+
* @return array
719+
*/
720+
public static function deprecationCheck() : array {
721+
// The check and message that the user is still using the deprecated version
722+
$deprecations = [
723+
'ms_teams_deprecated' => array(
724+
'check' => !Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows'),
725+
'message' => 'The Microsoft Teams webhook URL being used will be deprecated Jan 31st, 2025. <a class="btn btn-primary" href="' . route('settings.slack.index') . '">Change webhook endpoint</a>'),
726+
];
727+
728+
// if item of concern is being used and its being used with the deprecated values return the notification array.
729+
if(Setting::getSettings()->webhook_selected === 'microsoft' && $deprecations['ms_teams_deprecated']['check']) {
730+
return $deprecations;
731+
}
732+
return [];
733+
}
711734

712735
/**
713736
* This nasty little method gets the low inventory info for the

app/Http/Requests/StoreNotificationSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function rules(): array
2525
{
2626
return [
2727
'alert_email' => 'email_array|nullable',
28-
'admin_cc_email' => 'email|nullable',
28+
'admin_cc_email' => 'email_array|nullable',
2929
'alert_threshold' => 'numeric|nullable|gt:0',
3030
'alert_interval' => 'numeric|nullable|gt:0',
3131
'audit_warning_days' => 'numeric|nullable|gt:0',

app/Listeners/CheckoutableListener.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Illuminate\Support\Facades\Notification;
3131
use Exception;
3232
use Illuminate\Support\Facades\Log;
33+
use Osama\LaravelTeamsNotification\TeamsNotification;
3334

3435
class CheckoutableListener
3536
{
@@ -73,18 +74,27 @@ public function onCheckedOut($event)
7374
* 2. The item has a EULA
7475
* 3. The item should send an email at check-in/check-out
7576
*/
76-
if ($notifiable instanceof User && $notifiable->email != '') {
77+
7778
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
7879
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
79-
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
80+
if (!empty($notifiable->email)) {
81+
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
82+
} else {
83+
Mail::cc($ccEmails)->send($mailable);
84+
}
8085
Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
8186
}
82-
}
8387

8488
// Send Webhook notification
8589
if ($this->shouldSendWebhookNotification()) {
86-
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
87-
->notify($this->getCheckoutNotification($event, $acceptance));
90+
if (Setting::getSettings()->webhook_selected === 'microsoft') {
91+
$message = $this->getCheckoutNotification($event)->toMicrosoftTeams();
92+
$notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint);
93+
$notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams
94+
} else {
95+
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
96+
->notify($this->getCheckoutNotification($event, $acceptance));
97+
}
8898
}
8999
} catch (ClientException $e) {
90100
Log::debug("Exception caught during checkout notification: " . $e->getMessage());
@@ -142,13 +152,16 @@ public function onCheckedIn($event)
142152
* 3. The item should send an email at check-in/check-out
143153
*/
144154

145-
if ($notifiable instanceof User && $notifiable->email != '') {
146155
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
147156
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
148-
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
157+
if (!empty($notifiable->email)) {
158+
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
159+
} else {
160+
Mail::cc($ccEmails)->send($mailable);
161+
}
149162
Log::info('Sending email, Locale: ' . $event->checkedOutTo->locale);
150163
}
151-
}
164+
152165
// Send Webhook notification
153166
if ($this->shouldSendWebhookNotification()) {
154167
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)

app/Livewire/SlackSettingsForm.php

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use GuzzleHttp\Client;
66
use Illuminate\Support\Facades\Http;
7+
use Illuminate\Support\Str;
78
use Livewire\Component;
89
use App\Models\Setting;
910
use App\Helpers\Helper;
10-
11+
use Osama\LaravelTeamsNotification\TeamsNotification;
1112
class SlackSettingsForm extends Component
1213
{
1314
public $webhook_endpoint;
@@ -19,6 +20,7 @@ class SlackSettingsForm extends Component
1920
public $webhook_placeholder;
2021
public $webhook_icon;
2122
public $webhook_selected;
23+
public $teams_webhook_deprecated;
2224
public array $webhook_text;
2325

2426
public Setting $setting;
@@ -62,7 +64,7 @@ public function mount() {
6264
"name" => trans('admin/settings/general.ms_teams'),
6365
"icon" => "fa-brands fa-microsoft",
6466
"placeholder" => "https://abcd.webhook.office.com/webhookb2/XXXXXXX",
65-
"link" => "https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet#create-incoming-webhooks-1",
67+
"link" => "https://support.microsoft.com/en-us/office/create-incoming-webhooks-with-workflows-for-microsoft-teams-8ae491c7-0394-4861-ba59-055e33f75498",
6668
"test" => "msTeamTestWebhook"
6769
),
6870
];
@@ -79,15 +81,17 @@ public function mount() {
7981
$this->webhook_channel = $this->setting->webhook_channel;
8082
$this->webhook_botname = $this->setting->webhook_botname;
8183
$this->webhook_options = $this->setting->webhook_selected;
82-
if($this->webhook_selected == 'microsoft' || $this->webhook_selected == 'google'){
84+
$this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows');
85+
if($this->webhook_selected === 'microsoft' || $this->webhook_selected === 'google'){
8386
$this->webhook_channel = '#NA';
8487
}
8588

86-
8789
if($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null){
8890
$this->isDisabled= '';
8991
}
90-
92+
if($this->webhook_selected === 'microsoft' && $this->teams_webhook_deprecated) {
93+
session()->flash('warning', 'The selected Microsoft Teams webhook URL will be deprecated Jan 31st, 2025. Please use a workflow URL. Microsofts Documentation on creating a workflow can be found <a href="https://support.microsoft.com/en-us/office/create-incoming-webhooks-with-workflows-for-microsoft-teams-8ae491c7-0394-4861-ba59-055e33f75498" target="_blank"> here.</a>');
94+
}
9195
}
9296
public function updated($field) {
9397

@@ -109,7 +113,6 @@ public function updatedWebhookSelected() {
109113
if($this->webhook_selected == 'microsoft' || $this->webhook_selected == 'google'){
110114
$this->webhook_channel = '#NA';
111115
}
112-
113116
}
114117

115118
private function isButtonDisabled() {
@@ -126,7 +129,9 @@ private function isButtonDisabled() {
126129
public function render()
127130
{
128131
$this->isButtonDisabled();
132+
129133
return view('livewire.slack-settings-form');
134+
130135
}
131136

132137
public function testWebhook(){
@@ -236,20 +241,32 @@ public function googleWebhookTest(){
236241
}
237242
public function msTeamTestWebhook(){
238243

239-
$payload =
240-
[
241-
"@type" => "MessageCard",
242-
"@context" => "http://schema.org/extensions",
243-
"summary" => trans('mail.snipe_webhook_summary'),
244-
"title" => trans('mail.snipe_webhook_test'),
245-
"text" => trans('general.webhook_test_msg', ['app' => $this->webhook_name]),
246-
];
244+
try {
247245

248-
try {
249-
$response = Http::withHeaders([
250-
'content-type' => 'applications/json',
251-
])->post($this->webhook_endpoint,
252-
$payload)->throw();
246+
if($this->teams_webhook_deprecated){
247+
//will use the deprecated webhook format
248+
$payload =
249+
[
250+
"@type" => "MessageCard",
251+
"@context" => "http://schema.org/extensions",
252+
"summary" => trans('mail.snipe_webhook_summary'),
253+
"title" => trans('mail.snipe_webhook_test'),
254+
"text" => trans('general.webhook_test_msg', ['app' => $this->webhook_name]),
255+
];
256+
$response = Http::withHeaders([
257+
'content-type' => 'applications/json',
258+
])->post($this->webhook_endpoint,
259+
$payload)->throw();
260+
}
261+
else {
262+
$notification = new TeamsNotification($this->webhook_endpoint);
263+
$message = trans('general.webhook_test_msg', ['app' => $this->webhook_name]);
264+
$notification->success()->sendMessage($message);
265+
266+
$response = Http::withHeaders([
267+
'content-type' => 'applications/json',
268+
])->post($this->webhook_endpoint);
269+
}
253270

254271
if(($response->getStatusCode() == 302)||($response->getStatusCode() == 301)){
255272
return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint]));

app/Models/License.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public static function adjustSeatCount($license, $oldSeats, $newSeats)
184184
$logAction->item_type = self::class;
185185
$logAction->item_id = $license->id;
186186
$logAction->created_by = auth()->id() ?: 1; // We don't have an id while running the importer from CLI.
187-
$logAction->note = "deleted ${change} seats";
187+
$logAction->note = "deleted {$change} seats";
188188
$logAction->target_id = null;
189189
$logAction->logaction('delete seats');
190190

@@ -216,7 +216,7 @@ public static function adjustSeatCount($license, $oldSeats, $newSeats)
216216
$logAction->item_type = self::class;
217217
$logAction->item_id = $license->id;
218218
$logAction->created_by = auth()->id() ?: 1; // Importer.
219-
$logAction->note = "added ${change} seats";
219+
$logAction->note = "added {$change} seats";
220220
$logAction->target_id = null;
221221
$logAction->logaction('add seats');
222222
}
@@ -743,4 +743,4 @@ public function scopeOrderByCreatedBy($query, $order)
743743
{
744744
return $query->leftJoin('users as admin_sort', 'licenses.created_by', '=', 'admin_sort.id')->select('licenses.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
745745
}
746-
}
746+
}

app/Notifications/CheckinAccessoryNotification.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Notifications\Messages\MailMessage;
1111
use Illuminate\Notifications\Messages\SlackMessage;
1212
use Illuminate\Notifications\Notification;
13+
use Illuminate\Support\Str;
1314
use NotificationChannels\GoogleChat\Card;
1415
use NotificationChannels\GoogleChat\GoogleChatChannel;
1516
use NotificationChannels\GoogleChat\GoogleChatMessage;
@@ -91,18 +92,29 @@ public function toMicrosoftTeams()
9192
$admin = $this->admin;
9293
$item = $this->item;
9394
$note = $this->note;
95+
if(!Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {
96+
return MicrosoftTeamsMessage::create()
97+
->to($this->settings->webhook_endpoint)
98+
->type('success')
99+
->addStartGroupToSection('activityTitle')
100+
->title(trans('Accessory_Checkin_Notification'))
101+
->addStartGroupToSection('activityText')
102+
->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle')
103+
->fact(trans('mail.checked_into'), $item->location->name ? $item->location->name : '')
104+
->fact(trans('mail.Accessory_Checkin_Notification')." by ", $admin->present()->fullName())
105+
->fact(trans('admin/consumables/general.remaining'), $item->numRemaining())
106+
->fact(trans('mail.notes'), $note ?: '');
107+
}
94108

95-
return MicrosoftTeamsMessage::create()
96-
->to($this->settings->webhook_endpoint)
97-
->type('success')
98-
->addStartGroupToSection('activityTitle')
99-
->title(trans('Accessory_Checkin_Notification'))
100-
->addStartGroupToSection('activityText')
101-
->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle')
102-
->fact(trans('mail.checked_into'), $item->location->name ? $item->location->name : '')
103-
->fact(trans('mail.Accessory_Checkin_Notification')." by ", $admin->present()->fullName())
104-
->fact(trans('admin/consumables/general.remaining'), $item->numRemaining())
105-
->fact(trans('mail.notes'), $note ?: '');
109+
$message = trans('mail.Accessory_Checkin_Notification');
110+
$details = [
111+
trans('mail.accessory_name') => htmlspecialchars_decode($item->present()->name),
112+
trans('mail.checked_into') => $item->location->name ? $item->location->name : '',
113+
trans('mail.Accessory_Checkin_Notification'). ' by' => $admin->present()->fullName(),
114+
trans('admin/consumables/general.remaining')=> $item->numRemaining(),
115+
trans('mail.notes') => $note ?: '',
116+
];
117+
return array($message, $details);
106118
}
107119
public function toGoogleChat()
108120
{

app/Notifications/CheckinAssetNotification.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Notifications\Messages\MailMessage;
1111
use Illuminate\Notifications\Messages\SlackMessage;
1212
use Illuminate\Notifications\Notification;
13+
use Illuminate\Support\Str;
1314
use NotificationChannels\GoogleChat\Card;
1415
use NotificationChannels\GoogleChat\GoogleChatChannel;
1516
use NotificationChannels\GoogleChat\GoogleChatMessage;
@@ -97,16 +98,30 @@ public function toMicrosoftTeams()
9798
$item = $this->item;
9899
$note = $this->note;
99100

100-
return MicrosoftTeamsMessage::create()
101-
->to($this->settings->webhook_endpoint)
102-
->type('success')
103-
->title(trans('mail.Asset_Checkin_Notification'))
104-
->addStartGroupToSection('activityText')
105-
->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText')
106-
->fact(trans('mail.checked_into'), $item->location->name ? $item->location->name : '')
107-
->fact(trans('mail.Asset_Checkin_Notification')." by ", $admin->present()->fullName())
108-
->fact(trans('admin/hardware/form.status'), $item->assetstatus->name)
109-
->fact(trans('mail.notes'), $note ?: '');
101+
if(!Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {
102+
return MicrosoftTeamsMessage::create()
103+
->to($this->settings->webhook_endpoint)
104+
->type('success')
105+
->title(trans('mail.Asset_Checkin_Notification'))
106+
->addStartGroupToSection('activityText')
107+
->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText')
108+
->fact(trans('mail.checked_into'), $item->location->name ? $item->location->name : '')
109+
->fact(trans('mail.Asset_Checkin_Notification') . " by ", $admin->present()->fullName())
110+
->fact(trans('admin/hardware/form.status'), $item->assetstatus->name)
111+
->fact(trans('mail.notes'), $note ?: '');
112+
}
113+
114+
115+
$message = trans('mail.Asset_Checkin_Notification');
116+
$details = [
117+
trans('mail.asset') => htmlspecialchars_decode($item->present()->name),
118+
trans('mail.checked_into') => $item->location->name ? $item->location->name : '',
119+
trans('mail.Asset_Checkin_Notification')." by " => $admin->present()->fullName(),
120+
trans('admin/hardware/form.status') => $item->assetstatus->name,
121+
trans('mail.notes') => $note ?: '',
122+
];
123+
124+
return array($message, $details);
110125
}
111126
public function toGoogleChat()
112127
{

app/Notifications/CheckinLicenseSeatNotification.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Notifications\Messages\MailMessage;
1111
use Illuminate\Notifications\Messages\SlackMessage;
1212
use Illuminate\Notifications\Notification;
13+
use Illuminate\Support\Str;
1314
use NotificationChannels\GoogleChat\Card;
1415
use NotificationChannels\GoogleChat\GoogleChatChannel;
1516
use NotificationChannels\GoogleChat\GoogleChatMessage;
@@ -102,18 +103,30 @@ public function toMicrosoftTeams()
102103
$admin = $this->admin;
103104
$item = $this->item;
104105
$note = $this->note;
106+
if(!Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {
107+
return MicrosoftTeamsMessage::create()
108+
->to($this->settings->webhook_endpoint)
109+
->type('success')
110+
->addStartGroupToSection('activityTitle')
111+
->title(trans('mail.License_Checkin_Notification'))
112+
->addStartGroupToSection('activityText')
113+
->fact(htmlspecialchars_decode($item->present()->name), '', 'header')
114+
->fact(trans('mail.License_Checkin_Notification')." by ", $admin->present()->fullName() ?: 'CLI tool')
115+
->fact(trans('mail.checkedin_from'), $target->present()->fullName())
116+
->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count())
117+
->fact(trans('mail.notes'), $note ?: '');
118+
}
105119

106-
return MicrosoftTeamsMessage::create()
107-
->to($this->settings->webhook_endpoint)
108-
->type('success')
109-
->addStartGroupToSection('activityTitle')
110-
->title(trans('mail.License_Checkin_Notification'))
111-
->addStartGroupToSection('activityText')
112-
->fact(htmlspecialchars_decode($item->present()->name), '', 'header')
113-
->fact(trans('mail.License_Checkin_Notification')." by ", $admin->present()->fullName() ?: 'CLI tool')
114-
->fact(trans('mail.checkedin_from'), $target->present()->fullName())
115-
->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count())
116-
->fact(trans('mail.notes'), $note ?: '');
120+
$message = trans('mail.License_Checkin_Notification');
121+
$details = [
122+
trans('mail.checkedin_from')=> $target->present()->fullName(),
123+
trans('mail.license_for') => htmlspecialchars_decode($item->present()->name),
124+
trans('mail.License_Checkin_Notification')." by " => $admin->present()->fullName() ?: 'CLI tool',
125+
trans('admin/consumables/general.remaining') => $item->availCount()->count(),
126+
trans('mail.notes') => $note ?: '',
127+
];
128+
129+
return array($message, $details);
117130
}
118131
public function toGoogleChat()
119132
{

0 commit comments

Comments
 (0)