Standardize on sending anonymous notifications for asset checkouts

This commit is contained in:
Marcus Moore 2023-03-23 16:31:40 -07:00
parent 1f664709ba
commit 2dcf4e3d16
No known key found for this signature in database
3 changed files with 15 additions and 37 deletions

View file

@ -34,25 +34,17 @@ class CheckoutableListener
// @todo: update docblock
/**
* When the item wasn't checked out to a user, we can't send notifications
*/
// @todo: update comment
if (! $event->checkedOutTo instanceof User) {
// @todo: comment
if (Setting::getSettings() && Setting::getSettings()->webhook_endpoint) {
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
->notify(new CheckoutAssetNotification(
$event->checkoutable,
$event->checkedOutTo,
$event->checkedOutBy,
null,
$event->note)
);
}
return;
// @todo: comment...we send this anonymously so that webhook notification still
// @todo: get sent for models that don't have email addresses associated...
if (Setting::getSettings() && Setting::getSettings()->webhook_endpoint) {
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
->notify(new CheckoutAssetNotification(
$event->checkoutable,
$event->checkedOutTo,
$event->checkedOutBy,
null,
$event->note)
);
}
/**

View file

@ -263,20 +263,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
return $this->last_name.', '.$this->first_name.' ('.$this->username.')';
}
/**
* The url for slack notifications.
* Used by Notifiable trait.
* @return mixed
*/
public function routeNotificationForSlack()
{
// At this point the endpoint is the same for everything.
// In the future this may want to be adapted for individual notifications.
$this->endpoint = \App\Models\Setting::getSettings()->webhook_endpoint;
return $this->endpoint;
}
/**
* Establishes the user -> assets relationship

View file

@ -27,10 +27,10 @@ class AssetCheckoutWebhookNotificationTest extends TestCase
);
Notification::assertSentTo(
$user,
function (CheckoutAssetNotification $notification, $channels) {
// @todo: is this actually accurate?
return in_array('slack', $channels);
new AnonymousNotifiable,
CheckoutAssetNotification::class,
function ($notification, $channels, $notifiable) {
return $notifiable->routes['slack'] === Setting::getSettings()->webhook_endpoint;
}
);
}