From 8e38b3898ecbb3f6216c5ff30913c267f31f3907 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 7 Jul 2025 15:38:36 +0100 Subject: [PATCH 1/4] Fixes #14295 - allow user to receive an email PDF upon signing Signed-off-by: snipe --- .../Account/AcceptanceController.php | 23 ++++-- ...eptanceAssetAcceptedToUserNotification.php | 79 +++++++++++++++++++ resources/lang/en-US/mail.php | 2 + .../views/account/accept/create.blade.php | 9 ++- 4 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 app/Notifications/AcceptanceAssetAcceptedToUserNotification.php diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index c041cfa6b2..75ccd5004f 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -21,6 +21,7 @@ use App\Models\License; use App\Models\Component; use App\Models\Consumable; use App\Notifications\AcceptanceAssetAcceptedNotification; +use App\Notifications\AcceptanceAssetAcceptedToUserNotification; use App\Notifications\AcceptanceAssetDeclinedNotification; use Exception; use Illuminate\Http\Request; @@ -151,6 +152,8 @@ class AcceptanceController extends Controller } } + + $assigned_user = User::find($acceptance->assigned_to_id); // this is horrible switch($acceptance->checkoutable_type){ case 'App\Models\Asset': @@ -160,35 +163,30 @@ class AcceptanceController extends Controller return redirect()->back()->with('error', trans('admin/models/message.does_not_exist')); } $display_model = $asset_model->name; - $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName; break; case 'App\Models\Accessory': $pdf_view_route ='account.accept.accept-accessory-eula'; $accessory = Accessory::find($item->id); $display_model = $accessory->name; - $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName; break; case 'App\Models\LicenseSeat': $pdf_view_route ='account.accept.accept-license-eula'; $license = License::find($item->license_id); $display_model = $license->name; - $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName; break; case 'App\Models\Component': $pdf_view_route ='account.accept.accept-component-eula'; $component = Component::find($item->id); $display_model = $component->name; - $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName; break; case 'App\Models\Consumable': $pdf_view_route ='account.accept.accept-consumable-eula'; $consumable = Consumable::find($item->id); $display_model = $consumable->name; - $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName; break; } // if ($acceptance->checkoutable_type == 'App\Models\Asset') { @@ -229,7 +227,7 @@ class AcceptanceController extends Controller 'note' => $request->input('note'), 'check_out_date' => Carbon::parse($acceptance->created_at)->format('Y-m-d'), 'accepted_date' => Carbon::parse($acceptance->accepted_at)->format('Y-m-d'), - 'assigned_to' => $assigned_to, + 'assigned_to' => $assigned_user->present()->fullName, 'company_name' => $branding_settings->site_name, 'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null, 'logo' => $path_logo, @@ -243,6 +241,19 @@ class AcceptanceController extends Controller } $acceptance->accept($sig_filename, $item->getEula(), $pdf_filename, $request->input('note')); + + // Send the PDF to the signing user + if (($request->input('send_copy') == '1') && ($assigned_user->email !='')) { + + // Add the attachment for the signing user into the $data array + $data['file'] = $pdf_filename; + + try { + $assigned_user->notify(new AcceptanceAssetAcceptedToUserNotification($data)); + } catch (\Exception $e) { + Log::warning($e); + } + } try { $acceptance->notify(new AcceptanceAssetAcceptedNotification($data)); } catch (\Exception $e) { diff --git a/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php b/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php new file mode 100644 index 0000000000..238b48f708 --- /dev/null +++ b/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php @@ -0,0 +1,79 @@ +item_tag = $params['item_tag']; + $this->item_model = $params['item_model']; + $this->item_serial = $params['item_serial']; + $this->item_status = $params['item_status']; + $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'date', false); + $this->assigned_to = $params['assigned_to']; + $this->note = $params['note']; + $this->company_name = $params['company_name']; + $this->settings = Setting::getSettings(); + $this->file = $params['file'] ?? null; + + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via() + { + + $notifyBy = ['mail']; + + return $notifyBy; + + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail() + { + $pdf_path = storage_path('private_uploads/eula-pdfs/'.$this->file); + $message = (new MailMessage)->markdown('notifications.markdown.asset-acceptance', + [ + 'item_tag' => $this->item_tag, + 'item_model' => $this->item_model, + 'item_serial' => $this->item_serial, + 'item_status' => $this->item_status, + 'note' => $this->note, + 'accepted_date' => $this->accepted_date, + 'assigned_to' => $this->assigned_to, + 'company_name' => $this->company_name, + 'intro_text' => trans('mail.acceptance_asset_accepted_to_user', ['site_name' => $this->settings->site_name]), + ]) + ->attach($pdf_path) + ->subject(trans('mail.acceptance_asset_accepted_to_user', ['site_name' => $this->settings->site_name])); + + return $message; + } + + + +} diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index 65b544b343..6878de1561 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -27,8 +27,10 @@ return [ 'Low_Inventory_Report' => 'Low Inventory Report', 'a_user_canceled' => 'A user has canceled an item request on the website', 'a_user_requested' => 'A user has requested an item on the website', + 'acceptance_asset_accepted_to_user' => 'You have accepted an item assigned to you by :site_name', 'acceptance_asset_accepted' => 'A user has accepted an item', 'acceptance_asset_declined' => 'A user has declined an item', + 'send_pdf_copy' => 'Send a copy of this acceptance to my email address', 'accessory_name' => 'Accessory Name', 'additional_notes' => 'Additional Notes', 'admin_has_created' => 'An administrator has created an account for you on the :web website.', diff --git a/resources/views/account/accept/create.blade.php b/resources/views/account/accept/create.blade.php index e811d48105..bf078969fd 100644 --- a/resources/views/account/accept/create.blade.php +++ b/resources/views/account/accept/create.blade.php @@ -43,7 +43,7 @@
-
+
@if ($acceptance->checkoutable->getEula())
{!! $acceptance->checkoutable->getEula() !!} @@ -87,6 +87,13 @@
+ +
+ +
@endif
From 24c6e836dd9785df04546fcdcb0dd00efebdbc44 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 7 Jul 2025 15:51:24 +0100 Subject: [PATCH 2/4] Added checkbox toggle Signed-off-by: snipe --- .../views/account/accept/create.blade.php | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/resources/views/account/accept/create.blade.php b/resources/views/account/accept/create.blade.php index bf078969fd..797c527535 100644 --- a/resources/views/account/accept/create.blade.php +++ b/resources/views/account/accept/create.blade.php @@ -88,12 +88,14 @@
-
- -
+ @if (auth()->user()->email!='') + + @endif @endif @@ -111,6 +113,9 @@ @stop From 8ebbcf6e80c38e3c722fd652a515aed755f2ddc4 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 7 Jul 2025 15:55:31 +0100 Subject: [PATCH 3/4] Removed console commands Signed-off-by: snipe --- resources/views/users/edit.blade.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 4e2293f59b..0062a7210e 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -639,11 +639,9 @@ $(document).ready(function() { @if (!config('app.lock_passwords')) if (this.value.length > 5){ - console.log('email field is ' + this.value.length + ' - enable the checkbox'); $('#email_user_checkbox').prop("disabled", false); $("#email_user_checkbox").parent().removeClass("form-control--disabled"); } else { - console.log('email field is ' + this.value.length + ' - DISABLE the checkbox'); $('#email_user_checkbox').prop("disabled", true); $('#email_user_checkbox').prop("checked", false); $("#email_user_checkbox").parent().addClass("form-control--disabled"); From 59de77feb0759570ecad14cc99ba9822608d8c92 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 7 Jul 2025 15:55:40 +0100 Subject: [PATCH 4/4] Use company name if provided instead of site name Signed-off-by: snipe --- app/Notifications/AcceptanceAssetAcceptedToUserNotification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php b/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php index 238b48f708..22a97b709f 100644 --- a/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php +++ b/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php @@ -66,7 +66,7 @@ class AcceptanceAssetAcceptedToUserNotification extends Notification 'accepted_date' => $this->accepted_date, 'assigned_to' => $this->assigned_to, 'company_name' => $this->company_name, - 'intro_text' => trans('mail.acceptance_asset_accepted_to_user', ['site_name' => $this->settings->site_name]), + 'intro_text' => trans('mail.acceptance_asset_accepted_to_user', ['site_name' => $this->company_name ?? $this->settings->site_name]), ]) ->attach($pdf_path) ->subject(trans('mail.acceptance_asset_accepted_to_user', ['site_name' => $this->settings->site_name]));