From f40284c413e6288746f9ba03825cbbd80424c8d5 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 15 May 2024 13:04:58 -0700 Subject: [PATCH 1/5] adds acceptance reminder command --- .../Commands/SendAcceptanceReminder.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 app/Console/Commands/SendAcceptanceReminder.php diff --git a/app/Console/Commands/SendAcceptanceReminder.php b/app/Console/Commands/SendAcceptanceReminder.php new file mode 100644 index 000000000000..c23d2cbf5035 --- /dev/null +++ b/app/Console/Commands/SendAcceptanceReminder.php @@ -0,0 +1,84 @@ +where('checkoutable_type', 'App\Models\Asset')->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser'])->get(); + + $count = 0; + $unacceptedAssets = $acceptances + ->filter(function($acceptance) { + return $acceptance->checkoutable_type == 'App\Models\Asset'; + }) + ->map(function($acceptance) { + return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance]; + }); + + foreach($unacceptedAssets as $unacceptedAsset) { + if ($unacceptedAsset['acceptance']->assignedTo) { + + if (!$unacceptedAsset['acceptance']->assignedTo->locale) { + Notification::locale(Setting::getSettings()->locale)->send( + $unacceptedAsset['acceptance']->assignedTo, + new CheckoutAssetNotification($unacceptedAsset['assetItem'], $unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['assetItem']->adminuser, $unacceptedAsset['acceptance'], '') + ); + } else { + Notification::send( + $unacceptedAsset['acceptance']->assignedTo, + new CheckoutAssetNotification($unacceptedAsset['assetItem'], $unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['assetItem']->adminuser, $unacceptedAsset['acceptance'], '') + ); + } + $count++; + } + } + + if ($unacceptedAsset['acceptance']->assignedTo->email == ''){ + return "no email"; + } + + + + $this->info($count.' users notified.'); + } +} From c658a0fcb467cf48419c9db900a7aef77d748f5d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 15 May 2024 13:20:05 -0700 Subject: [PATCH 2/5] fixes description --- app/Console/Commands/SendAcceptanceReminder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/SendAcceptanceReminder.php b/app/Console/Commands/SendAcceptanceReminder.php index c23d2cbf5035..8c19b49e6eeb 100644 --- a/app/Console/Commands/SendAcceptanceReminder.php +++ b/app/Console/Commands/SendAcceptanceReminder.php @@ -25,7 +25,7 @@ class SendAcceptanceReminder extends Command * * @var string */ - protected $description = 'This will send users with unaccepted assets a reminder to accept them.'; + protected $description = 'This will resend users with unaccepted assets a reminder to accept or decline them.'; /** * Create a new command instance. From 8a0afae90f2d9039cab4184f02a4e1ac49deacf9 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 21 May 2024 09:42:00 -0700 Subject: [PATCH 3/5] fixed query, fixed no email logic, needs new markdown --- .../Commands/SendAcceptanceReminder.php | 24 ++++++++++--- .../markdown/asset-reminder.blade.php | 34 +++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 resources/views/notifications/markdown/asset-reminder.blade.php diff --git a/app/Console/Commands/SendAcceptanceReminder.php b/app/Console/Commands/SendAcceptanceReminder.php index 8c19b49e6eeb..ac46c87ede03 100644 --- a/app/Console/Commands/SendAcceptanceReminder.php +++ b/app/Console/Commands/SendAcceptanceReminder.php @@ -44,18 +44,30 @@ public function __construct() */ public function handle() { - $acceptances = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset')->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser'])->get(); + $pending = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset') + ->whereHas('checkoutable', function($query) { + $query->where('archived', 0); + }) + ->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser']) + ->get(); $count = 0; - $unacceptedAssets = $acceptances + $unacceptedAssets = $pending ->filter(function($acceptance) { return $acceptance->checkoutable_type == 'App\Models\Asset'; }) ->map(function($acceptance) { return ['assetItem' => $acceptance->checkoutable, 'acceptance' => $acceptance]; + }) + ->groupBy(function($item) { + return $item['acceptance']->assignedTo ? $item['acceptance']->assignedTo->id : ''; }); + $no_mail_address = []; foreach($unacceptedAssets as $unacceptedAsset) { + if ($unacceptedAsset['acceptance']->assignedTo->email == ''){ + $no_mail_address[] = $unacceptedAsset['checkoutable']->assignedTo->present()->fullName; + } if ($unacceptedAsset['acceptance']->assignedTo) { if (!$unacceptedAsset['acceptance']->assignedTo->locale) { @@ -73,8 +85,12 @@ public function handle() } } - if ($unacceptedAsset['acceptance']->assignedTo->email == ''){ - return "no email"; + if (!empty($no_mail_address)) { + foreach($no_mail_address as $user) { + return $user.' has no email.'; + } + + } diff --git a/resources/views/notifications/markdown/asset-reminder.blade.php b/resources/views/notifications/markdown/asset-reminder.blade.php new file mode 100644 index 000000000000..204793fe053f --- /dev/null +++ b/resources/views/notifications/markdown/asset-reminder.blade.php @@ -0,0 +1,34 @@ +@component('mail::message') + # {{ trans('mail.hello') }}, + + {{ $intro_text }}. + + @component('mail::table') + | | | + | ------------- | ------------- | + | **{{ trans('mail.user') }}** | {{ $assigned_to }} | + @if (isset($accepted_date)) + | **{{ ucfirst(trans('general.accepted')) }}** | {{ $accepted_date }} | + @endif + @if (isset($declined_date)) + | **{{ ucfirst(trans('general.declined')) }}** | {{ $declined_date }} | + @endif + @if ((isset($item_tag)) && ($item_tag!='')) + | **{{ trans('mail.asset_tag') }}** | {{ $item_tag }} | + @endif + @if ((isset($item_model)) && ($item_model!='')) + | **{{ trans('mail.asset_name') }}** | {{ $item_model }} | + @endif + @if (isset($item->model)) + | **{{ trans('general.asset_model') }}** | {{ $item->model->name }} | + @endif + @if (isset($item_serial)) + | **{{ trans('mail.serial') }}** | {{ $item_serial }} | + @endif + @endcomponent + + {{ trans('mail.best_regards') }} + + {{ $snipeSettings->site_name }} + +@endcomponent From d3ab152d3009ff9e3276d6d4f944502a01c7414e Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 23 May 2024 12:47:02 -0700 Subject: [PATCH 4/5] adds reminder notification constructor and updates markdown --- .../Commands/SendAcceptanceReminder.php | 41 ++++++----- .../UnacceptedAssetReminderNotification.php | 69 +++++++++++++++++++ resources/lang/en-US/mail.php | 2 + .../markdown/asset-reminder.blade.php | 28 +------- 4 files changed, 96 insertions(+), 44 deletions(-) create mode 100644 app/Notifications/UnacceptedAssetReminderNotification.php diff --git a/app/Console/Commands/SendAcceptanceReminder.php b/app/Console/Commands/SendAcceptanceReminder.php index ac46c87ede03..dd9e59f611d0 100644 --- a/app/Console/Commands/SendAcceptanceReminder.php +++ b/app/Console/Commands/SendAcceptanceReminder.php @@ -8,6 +8,7 @@ use App\Models\User; use App\Notifications\CheckoutAssetNotification; use App\Notifications\CurrentInventory; +use App\Notifications\UnacceptedAssetReminderNotification; use Illuminate\Console\Command; use Illuminate\Support\Facades\Notification; @@ -52,7 +53,7 @@ public function handle() ->get(); $count = 0; - $unacceptedAssets = $pending + $unacceptedAssetGroups = $pending ->filter(function($acceptance) { return $acceptance->checkoutable_type == 'App\Models\Asset'; }) @@ -62,26 +63,30 @@ public function handle() ->groupBy(function($item) { return $item['acceptance']->assignedTo ? $item['acceptance']->assignedTo->id : ''; }); + $no_mail_address = []; - foreach($unacceptedAssets as $unacceptedAsset) { - if ($unacceptedAsset['acceptance']->assignedTo->email == ''){ - $no_mail_address[] = $unacceptedAsset['checkoutable']->assignedTo->present()->fullName; - } - if ($unacceptedAsset['acceptance']->assignedTo) { - - if (!$unacceptedAsset['acceptance']->assignedTo->locale) { - Notification::locale(Setting::getSettings()->locale)->send( - $unacceptedAsset['acceptance']->assignedTo, - new CheckoutAssetNotification($unacceptedAsset['assetItem'], $unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['assetItem']->adminuser, $unacceptedAsset['acceptance'], '') - ); - } else { - Notification::send( - $unacceptedAsset['acceptance']->assignedTo, - new CheckoutAssetNotification($unacceptedAsset['assetItem'], $unacceptedAsset['acceptance']->assignedTo, $unacceptedAsset['assetItem']->adminuser, $unacceptedAsset['acceptance'], '') - ); + foreach($unacceptedAssetGroups as $unacceptedAssetGroup) { + $item_count = $unacceptedAssetGroup->count(); + foreach ($unacceptedAssetGroup as $unacceptedAsset) { +// if ($unacceptedAsset['acceptance']->assignedTo->email == ''){ +// $no_mail_address[] = $unacceptedAsset['checkoutable']->assignedTo->present()->fullName; +// } + if ($unacceptedAsset['acceptance']->assignedTo) { + + if (!$unacceptedAsset['acceptance']->assignedTo->locale) { + Notification::locale(Setting::getSettings()->locale)->send( + $unacceptedAsset['acceptance']->assignedTo, + new UnacceptedAssetReminderNotification($unacceptedAsset['assetItem'], $count) + ); + } else { + Notification::send( + $unacceptedAsset['acceptance']->assignedTo, + new UnacceptedAssetReminderNotification($unacceptedAsset, $item_count) + ); + } + $count++; } - $count++; } } diff --git a/app/Notifications/UnacceptedAssetReminderNotification.php b/app/Notifications/UnacceptedAssetReminderNotification.php new file mode 100644 index 000000000000..47511681954a --- /dev/null +++ b/app/Notifications/UnacceptedAssetReminderNotification.php @@ -0,0 +1,69 @@ +count = $count; + $this->target = $checkout_info['acceptance']->assignedTo; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via() + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail() + { + $message = (new MailMessage)->markdown('notifications.markdown.asset-reminder', + [ + 'count' => $this->count, + 'assigned_to' => $this->target->present()->fullName, + 'link' => route('account.accept') + ]) + ->subject(trans('mail.unaccepted_asset_reminder')); + + return $message; + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index 759ff0f5e8b2..affc305df6ea 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -56,6 +56,7 @@ 'i_have_read' => 'I have read and agree to the terms of use, and have received this item.', 'inventory_report' => 'Inventory Report', 'item' => 'Item:', + 'item_checked_reminder' => 'This is a reminder that you currently have :count items checked out to you that you have not accepted or declined. Please click here to review your items.', 'license_expiring_alert' => 'There is :count license expiring in the next :threshold days.|There are :count licenses expiring in the next :threshold days.', 'link_to_update_password' => 'Please click on the following link to update your :web password:', 'login' => 'Login:', @@ -86,6 +87,7 @@ 'upcoming-audits' => 'There is :count asset that is coming up for audit within :threshold days.|There are :count assets that are coming up for audit within :threshold days.', 'user' => 'User', 'username' => 'Username', + 'unaccepted_asset_reminder' => 'You have Unnaccepted Assets.', 'welcome' => 'Welcome :name', 'welcome_to' => 'Welcome to :web!', 'your_assets' => 'View Your Assets', diff --git a/resources/views/notifications/markdown/asset-reminder.blade.php b/resources/views/notifications/markdown/asset-reminder.blade.php index 204793fe053f..876e9c6c96eb 100644 --- a/resources/views/notifications/markdown/asset-reminder.blade.php +++ b/resources/views/notifications/markdown/asset-reminder.blade.php @@ -1,31 +1,7 @@ @component('mail::message') - # {{ trans('mail.hello') }}, + # {{ trans('mail.hello') }} {{ $assigned_to}}, - {{ $intro_text }}. - - @component('mail::table') - | | | - | ------------- | ------------- | - | **{{ trans('mail.user') }}** | {{ $assigned_to }} | - @if (isset($accepted_date)) - | **{{ ucfirst(trans('general.accepted')) }}** | {{ $accepted_date }} | - @endif - @if (isset($declined_date)) - | **{{ ucfirst(trans('general.declined')) }}** | {{ $declined_date }} | - @endif - @if ((isset($item_tag)) && ($item_tag!='')) - | **{{ trans('mail.asset_tag') }}** | {{ $item_tag }} | - @endif - @if ((isset($item_model)) && ($item_model!='')) - | **{{ trans('mail.asset_name') }}** | {{ $item_model }} | - @endif - @if (isset($item->model)) - | **{{ trans('general.asset_model') }}** | {{ $item->model->name }} | - @endif - @if (isset($item_serial)) - | **{{ trans('mail.serial') }}** | {{ $item_serial }} | - @endif - @endcomponent + {{ trans('mail.item_checked_reminder', ['link' => $link, 'count' => $count]) }} {{ trans('mail.best_regards') }} From 442903ea5e3f5d181a8b705d62cc8a1f73bd7a6f Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 23 May 2024 16:08:18 -0700 Subject: [PATCH 5/5] trying to get link to work, fixed up markup and url --- app/Notifications/UnacceptedAssetReminderNotification.php | 6 +++++- resources/lang/en-US/mail.php | 4 ++-- .../views/notifications/markdown/asset-reminder.blade.php | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Notifications/UnacceptedAssetReminderNotification.php b/app/Notifications/UnacceptedAssetReminderNotification.php index 47511681954a..e05b007033cf 100644 --- a/app/Notifications/UnacceptedAssetReminderNotification.php +++ b/app/Notifications/UnacceptedAssetReminderNotification.php @@ -22,6 +22,8 @@ public function __construct($checkout_info, $count) { $this->count = $count; $this->target = $checkout_info['acceptance']->assignedTo; + $this->acceptance = $checkout_info['acceptance']; + } /** @@ -43,11 +45,13 @@ public function via() */ public function toMail() { + $accept_url = route('account.accept'); $message = (new MailMessage)->markdown('notifications.markdown.asset-reminder', [ 'count' => $this->count, 'assigned_to' => $this->target->present()->fullName, - 'link' => route('account.accept') + 'link' => route('account.accept'), + 'accept_url' => $accept_url, ]) ->subject(trans('mail.unaccepted_asset_reminder')); diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index affc305df6ea..706f92bbec02 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -56,7 +56,7 @@ 'i_have_read' => 'I have read and agree to the terms of use, and have received this item.', 'inventory_report' => 'Inventory Report', 'item' => 'Item:', - 'item_checked_reminder' => 'This is a reminder that you currently have :count items checked out to you that you have not accepted or declined. Please click here to review your items.', + 'item_checked_reminder' => 'This is a reminder that you currently have :count items checked out to you that you have not accepted or declined. Please click the link below to confirm your decision.', 'license_expiring_alert' => 'There is :count license expiring in the next :threshold days.|There are :count licenses expiring in the next :threshold days.', 'link_to_update_password' => 'Please click on the following link to update your :web password:', 'login' => 'Login:', @@ -87,7 +87,7 @@ 'upcoming-audits' => 'There is :count asset that is coming up for audit within :threshold days.|There are :count assets that are coming up for audit within :threshold days.', 'user' => 'User', 'username' => 'Username', - 'unaccepted_asset_reminder' => 'You have Unnaccepted Assets.', + 'unaccepted_asset_reminder' => 'You have Unaccepted Assets.', 'welcome' => 'Welcome :name', 'welcome_to' => 'Welcome to :web!', 'your_assets' => 'View Your Assets', diff --git a/resources/views/notifications/markdown/asset-reminder.blade.php b/resources/views/notifications/markdown/asset-reminder.blade.php index 876e9c6c96eb..408c3847f4c7 100644 --- a/resources/views/notifications/markdown/asset-reminder.blade.php +++ b/resources/views/notifications/markdown/asset-reminder.blade.php @@ -1,7 +1,8 @@ @component('mail::message') # {{ trans('mail.hello') }} {{ $assigned_to}}, - {{ trans('mail.item_checked_reminder', ['link' => $link, 'count' => $count]) }} + {{trans('mail.item_checked_reminder', ['count' => $count])}} + [{{ trans('general.click_here')}}]({{$accept_url}}) {{ trans('mail.best_regards') }}