2017-08-25 10:04:19 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications;
|
|
|
|
|
|
|
|
use App\Models\Setting;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
|
|
|
class AuditNotification extends Notification
|
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
private $params;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new notification instance.
|
|
|
|
*
|
|
|
|
* @param $params
|
|
|
|
*/
|
|
|
|
public function __construct($params)
|
|
|
|
{
|
|
|
|
//
|
2023-06-02 02:59:47 -07:00
|
|
|
$this->settings = Setting::getSettings();
|
2017-08-25 10:04:19 -07:00
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2020-05-23 11:56:56 -07:00
|
|
|
public function via()
|
2017-08-25 10:04:19 -07:00
|
|
|
{
|
|
|
|
$notifyBy = [];
|
2023-03-22 14:43:00 -07:00
|
|
|
if (Setting::getSettings()->webhook_endpoint) {
|
2017-08-25 10:04:19 -07:00
|
|
|
$notifyBy[] = 'slack';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $notifyBy;
|
|
|
|
}
|
|
|
|
|
2020-05-23 11:56:56 -07:00
|
|
|
public function toSlack()
|
2017-08-25 10:04:19 -07:00
|
|
|
{
|
2023-06-02 02:59:47 -07:00
|
|
|
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
|
2017-08-25 10:04:19 -07:00
|
|
|
return (new SlackMessage)
|
|
|
|
->success()
|
2021-06-10 13:15:52 -07:00
|
|
|
->content(class_basename(get_class($this->params['item'])).' Audited')
|
2023-06-02 02:59:47 -07:00
|
|
|
->from(($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot')
|
|
|
|
->to($channel)
|
2020-05-23 11:56:56 -07:00
|
|
|
->attachment(function ($attachment) {
|
2017-08-25 10:04:19 -07:00
|
|
|
$item = $this->params['item'];
|
|
|
|
$admin_user = $this->params['admin'];
|
|
|
|
$fields = [
|
2021-06-10 13:15:52 -07:00
|
|
|
'By' => '<'.$admin_user->present()->viewUrl().'|'.$admin_user->present()->fullName().'>',
|
2017-08-25 10:04:19 -07:00
|
|
|
];
|
|
|
|
array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note'];
|
2017-08-31 21:30:38 -07:00
|
|
|
array_key_exists('location', $this->params) && $fields['Location'] = $this->params['location'];
|
2017-08-25 10:04:19 -07:00
|
|
|
|
2017-08-31 21:30:38 -07:00
|
|
|
$attachment->title($item->present()->name, $item->present()->viewUrl())
|
2017-08-25 10:04:19 -07:00
|
|
|
->fields($fields);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|