mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 14:09:43 -08:00
bb874012d9
Working mail from notification. Still requires testing/cleaning Add tests around checkout notification. This also removes the ability to check out an asset to a location|asset that requires acceptance/a Eula. For 4.1 we may think about how to support such a thing, but at present it seems to make sense to only alow such assets to be checked out to users, who can be responsible for the items.
123 lines
3.8 KiB
PHP
123 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Setting;
|
|
use App\Models\SnipeModel;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class CheckoutNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
/**
|
|
* @var
|
|
*/
|
|
private $params;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*
|
|
* @param $params
|
|
*/
|
|
public function __construct($params)
|
|
{
|
|
//
|
|
$this->params = $params;
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @return array
|
|
*/
|
|
public function via($notifiable)
|
|
{
|
|
$notifyBy = [];
|
|
if (Setting::getSettings()->slack_endpoint) {
|
|
$notifyBy[] = 'slack';
|
|
}
|
|
$item = $this->params['item'];
|
|
|
|
$notifyBy[]='mail';
|
|
// if ((method_exists($item, 'requireAcceptance') && ($item->requireAcceptance()=='1'))
|
|
// || (method_exists($item, 'getEula') && ($item->getEula()))
|
|
// ) {
|
|
// $notifyBy[] = 'mail';
|
|
// }
|
|
return $notifyBy;
|
|
}
|
|
|
|
public function toSlack($notifiable)
|
|
{
|
|
|
|
return (new SlackMessage)
|
|
->success()
|
|
->content(class_basename(get_class($this->params['item'])) . " Checked Out")
|
|
->attachment(function ($attachment) use ($notifiable) {
|
|
$item = $this->params['item'];
|
|
$admin_user = $this->params['admin'];
|
|
$target = $this->params['target'];
|
|
$fields = [
|
|
'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
|
|
'By' => '<'.$admin_user->present()->viewUrl().'|'.$admin_user->present()->fullName().'>'
|
|
];
|
|
array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note'];
|
|
|
|
$attachment->title($item->name, $item->present()->viewUrl())
|
|
->fields($fields);
|
|
});
|
|
}
|
|
/**
|
|
* Get the mail representation of the notification.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
*/
|
|
public function toMail($notifiable)
|
|
{
|
|
//TODO: Expand for non assets.
|
|
$item = $this->params['item'];
|
|
$admin_user = $this->params['admin'];
|
|
$target = $this->params['target'];
|
|
$data = [
|
|
'eula' => method_exists($item, 'getEula') ? $item->getEula() : '',
|
|
'first_name' => $target->present()->fullName(),
|
|
'item_name' => $item->present()->name(),
|
|
'checkout_date' => $item->last_checkout,
|
|
'expected_checkin' => $item->expected_checkin,
|
|
'item_tag' => $item->asset_tag,
|
|
'note' => $this->params['note'],
|
|
'item_serial' => $item->serial,
|
|
'require_acceptance' => $item->requireAcceptance(),
|
|
'log_id' => $this->params['log_id'],
|
|
];
|
|
return (new MailMessage)
|
|
->view('emails.accept-asset', $data)
|
|
->subject(trans('mail.Confirm_asset_delivery'));
|
|
// \Mail::send('emails.accept-asset', $data, function ($m) use ($target) {
|
|
// $m->to($target->email, $target->first_name . ' ' . $target->last_name);
|
|
// $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
|
|
// $m->subject(trans('mail.Confirm_asset_delivery'));
|
|
// });
|
|
}
|
|
|
|
/**
|
|
* Get the array representation of the notification.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @return array
|
|
*/
|
|
public function toArray($notifiable)
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
}
|