Use notifiables for slack audit notification

This commit is contained in:
snipe 2017-08-31 21:30:38 -07:00
parent 3518ea7e7d
commit 761371509d
3 changed files with 10 additions and 6 deletions

View file

@ -529,7 +529,11 @@ class AssetsController extends Controller
$asset->next_audit_date = $request->input('next_audit_date'); $asset->next_audit_date = $request->input('next_audit_date');
if ($asset->save()) { if ($asset->save()) {
$log = $asset->logAudit(request('note'),request('location_id')); $log = $asset->logAudit(request('note'),request('location_id'));
return response()->json(Helper::formatStandardApiResponse('success', ['asset_tag'=> e($asset->asset_tag), 'note'=> e($request->input('note')), 'next_audit_date' => Helper::getFormattedDateObject($log->calcNextAuditDate())], trans('admin/hardware/message.audit.success'))); return response()->json(Helper::formatStandardApiResponse('success', [
'asset_tag'=> e($asset->asset_tag),
'note'=> e($request->input('note')),
'next_audit_date' => Helper::getFormattedDateObject($log->calcNextAuditDate())
], trans('admin/hardware/message.audit.success')));
} }
} }

View file

@ -131,6 +131,7 @@ trait Loggable
public function logAudit($note, $location_id) public function logAudit($note, $location_id)
{ {
$log = new Actionlog; $log = new Actionlog;
$location = Location::find($location_id);
if (static::class == LicenseSeat::class) { if (static::class == LicenseSeat::class) {
$log->item_type = License::class; $log->item_type = License::class;
$log->item_id = $this->license_id; $log->item_id = $this->license_id;
@ -146,6 +147,7 @@ trait Loggable
$params = [ $params = [
'item' => $log->item, 'item' => $log->item,
'admin' => $log->user, 'admin' => $log->user,
'location' => ($location) ? $location->name : '',
'note' => $note 'note' => $note
]; ];
Setting::getSettings()->notify(new AuditNotification($params)); Setting::getSettings()->notify(new AuditNotification($params));

View file

@ -56,8 +56,9 @@ class AuditNotification extends Notification
'By' => '<'.$admin_user->present()->viewUrl().'|'.$admin_user->present()->fullName().'>' 'By' => '<'.$admin_user->present()->viewUrl().'|'.$admin_user->present()->fullName().'>'
]; ];
array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note']; array_key_exists('note', $this->params) && $fields['Notes'] = $this->params['note'];
array_key_exists('location', $this->params) && $fields['Location'] = $this->params['location'];
$attachment->title($item->name, $item->present()->viewUrl()) $attachment->title($item->present()->name, $item->present()->viewUrl())
->fields($fields); ->fields($fields);
}); });
} }
@ -69,10 +70,7 @@ class AuditNotification extends Notification
*/ */
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', 'https://laravel.com')
->line('Thank you for using our application!');
} }
/** /**