mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-30 07:59:50 -08:00
8a6713d5c0
* WIP - beginning of improved requested assets - Use Ajax tables for faster loading - Use new notifications for requesting an asset TODO: - Use ajax tables for requestable asset models - Use new notifications for canceling an asset request - Expire requests once the asset has been checked out to the requesting user * Only show asset name in email if it has one * Refactor requested method to only include non-canceled requests * Refactored requestable assets to log request and cancelation * Added softdeletes on checkout requests * Differentiate between canceling and deleting requests * Added asset request cancelation notification * Added timestamps and corrected unique key on requests table * Improved requests view * Re-use blade for cancel/request email * Refactored BS table formatter for requested assets * Location name min reduced to 2 * Added PAT test as maintenance option This needs to be refactored into database-driven options with a UI * Better slack message * Added getImageUrl method for assets * Include qty in request notifications TODO: - Try to pull requested info from original request for cancelation, otherwise it will default to 1 * Removed old asset request/cancel emails * Added user profile asset request routes * Added profile controller requested assets method * Added blade link to requested assets for profile view * Sort user history desc * Added requested assets blade * Added canceled at to checkoutRequest method * Include qty in request * Fixed comment, removed allowed_columns * Removed Queable methods, since we don’t use a queue * Fixed return type in method doc * Fixed version number * Changed id to user_id for clarity
138 lines
3.8 KiB
PHP
138 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Setting;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class RequestAssetCancelationNotification extends Notification
|
|
{
|
|
/**
|
|
* @var
|
|
*/
|
|
private $params;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*
|
|
* @param $params
|
|
*/
|
|
public function __construct($params)
|
|
{
|
|
$this->target = $params['target'];
|
|
$this->item = $params['item'];
|
|
$this->note = '';
|
|
$this->last_checkout = '';
|
|
$this->item_quantity = $params['item_quantity'];
|
|
$this->expected_checkin = '';
|
|
$this->requested_date = \App\Helpers\Helper::getFormattedDateObject($params['requested_date'], 'datetime',
|
|
false);
|
|
$this->settings = Setting::getSettings();
|
|
|
|
if (array_key_exists('note', $params)) {
|
|
$this->note = $params['note'];
|
|
}
|
|
|
|
if ($this->item->last_checkout) {
|
|
$this->last_checkout = \App\Helpers\Helper::getFormattedDateObject($this->item->last_checkout, 'date',
|
|
false);
|
|
}
|
|
|
|
if ($this->item->expected_checkin) {
|
|
$this->expected_checkin = \App\Helpers\Helper::getFormattedDateObject($this->item->expected_checkin, 'date',
|
|
false);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @return array
|
|
*/
|
|
public function via()
|
|
{
|
|
|
|
$notifyBy = [];
|
|
|
|
if (Setting::getSettings()->slack_endpoint!='') {
|
|
\Log::debug('use slack');
|
|
$notifyBy[] = 'slack';
|
|
}
|
|
|
|
|
|
$notifyBy[] = 'mail';
|
|
|
|
return $notifyBy;
|
|
}
|
|
|
|
public function toSlack()
|
|
{
|
|
|
|
|
|
$target = $this->target;
|
|
$item = $this->item;
|
|
$note = $this->note;
|
|
$qty = $this->item_quantity;
|
|
$botname = ($this->settings->slack_botname) ? $this->settings->slack_botname : 'Snipe-Bot' ;
|
|
|
|
$fields = [
|
|
'QTY' => $qty,
|
|
'Canceled By' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
|
|
];
|
|
|
|
if (($this->expected_checkin) && ($this->expected_checkin!='')) {
|
|
$fields['Expected Checkin'] = $this->expected_checkin;
|
|
}
|
|
|
|
return (new SlackMessage)
|
|
->content( trans('mail.a_user_canceled'))
|
|
->from($botname)
|
|
->attachment(function ($attachment) use ($item, $note, $fields) {
|
|
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
|
|
->fields($fields)
|
|
->content($note);
|
|
});
|
|
}
|
|
/**
|
|
* Get the mail representation of the notification.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
*/
|
|
public function toMail()
|
|
{
|
|
|
|
$fields = [];
|
|
|
|
// Check if the item has custom fields associated with it
|
|
if (($this->item->model) && ($this->item->model->fieldset)) {
|
|
$fields = $this->item->model->fieldset->fields;
|
|
}
|
|
|
|
$message = (new MailMessage)->markdown('notifications.markdown.asset-requested',
|
|
[
|
|
'item' => $this->item,
|
|
'note' => $this->note,
|
|
'requested_by' => $this->target,
|
|
'requested_date' => $this->requested_date,
|
|
'fields' => $fields,
|
|
'qty' => $this->item_quantity,
|
|
'last_checkout' => $this->last_checkout,
|
|
'expected_checkin' => $this->expected_checkin,
|
|
'intro_text' => trans('mail.a_user_canceled'),
|
|
])
|
|
->subject(trans('Item Request Canceled'));
|
|
|
|
|
|
return $message;
|
|
|
|
|
|
}
|
|
|
|
}
|