mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Standardize on sending anonymous notifications for asset checkouts
This commit is contained in:
parent
1f664709ba
commit
2dcf4e3d16
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue