diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index b8a34ed8c..227ec6e20 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1,7 +1,6 @@ filled('signature_output')) { - $sig_filename = 'siglog-'.Str::uuid().'-'.date('Y-m-d-his').'.png'; - $data_uri = e($request->input('signature_output')); - $encoded_image = explode(',', $data_uri); - $decoded_image = base64_decode($encoded_image[1]); - $acceptance->stored_eula_file = 'accepted-eula-'.date('Y-m-d-h-i-s').'.pdf'; - $path = Storage::put('private_uploads/signatures/'.$sig_filename, (string) $decoded_image); - } - - if ($request->input('asset_acceptance') == 'accepted') { - $acceptance->accept($sig_filename); - - event(new CheckoutAccepted($acceptance)); - - $return_msg = trans('admin/users/message.accepted'); - - - } else { - $acceptance->decline($sig_filename); - - event(new CheckoutDeclined($acceptance)); - - $return_msg = trans('admin/users/message.declined'); + /** + * Check for the eula-pdfs directory + */ + if (! Storage::exists('private_uploads/eula-pdfs')) { + Storage::makeDirectory('private_uploads/eula-pdfs', 775); } $item = $acceptance->checkoutable_type::find($acceptance->checkoutable_id); + $display_model = ''; + $pdf_view_route = ''; + $pdf_filename = 'accepted-eula-'.date('Y-m-d-h-i-s').'.pdf'; + $sig_filename=''; - if ($acceptance->checkoutable_type== 'App\Models\Asset') { - $assigned_to = User::find($item->assigned_to); - $asset_model = AssetModel::find($item->model_id); + + if ($request->input('asset_acceptance') == 'accepted') { + + // The item was accepted, check for a signature + if ($request->filled('signature_output')) { + $sig_filename = 'siglog-'.Str::uuid().'-'.date('Y-m-d-his').'.png'; + $data_uri = $request->input('signature_output'); + $encoded_image = explode(',', $data_uri); + $decoded_image = base64_decode($encoded_image[1]); + Storage::put('private_uploads/signatures/'.$sig_filename, (string) $decoded_image); + } + + + // this is horrible + if ($acceptance->checkoutable_type == 'App\Models\Asset') { + $pdf_view_route ='account.accept.accept-asset-eula'; + $asset_model = AssetModel::find($item->model_id); + $display_model = $asset_model->name; + $assigned_to = User::find($item->assigned_to)->present()->fullName; + + } elseif ($acceptance->checkoutable_type== 'App\Models\Accessory') { + $pdf_view_route ='account.accept.accept-accessory-eula'; + $accessory = Accessory::find($item->id); + $display_model = $accessory->name; + $assigned_to = User::find($item->assignedTo); + + } + + /** + * Gather the data for the PDF. We fire this whether there is a signature required or not, + * since we want the moment-in-time proof of what the EULA was when they accepted it. + */ $branding_settings = SettingsController::getPDFBranding(); $data = [ 'item_tag' => $item->asset_tag, - 'item_model' => $asset_model->name, + 'item_model' => $display_model, 'item_serial' => $item->serial, 'eula' => $item->getEula(), 'check_out_date' => Carbon::parse($acceptance->created_at)->format($branding_settings->date_display_format), 'accepted_date' => Carbon::parse($acceptance->accepted_at)->format($branding_settings->date_display_format), - 'assigned_to' => $assigned_to->first_name . ' ' . $assigned_to->last_name, + 'assigned_to' => $assigned_to, 'company_name' => $branding_settings->site_name, - 'signature' => storage_path() . '/private_uploads/signatures/' . $sig_filename, + 'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null, 'logo' => public_path() . '/uploads/' . $branding_settings->logo, 'date_settings' => $branding_settings->date_display_format, ]; - $pdf = Pdf::loadView('account.accept.accept-asset-eula', $data); - Storage::put('private_uploads/eula-pdfs/' . $acceptance->stored_eula_file, $pdf->output()); - $a = new Actionlog(); - $a->stored_eula = $item->getEula(); - $a->stored_eula_file = $acceptance->stored_eula_file; - $a->save(); + if ($pdf_view_route!='') { + \Log::debug($pdf_filename.' is the filename, and the route was specified.'); + $pdf = Pdf::loadView($pdf_view_route, $data); + Storage::put('private_uploads/eula-pdfs/' .$pdf_filename, $pdf->output()); + } - return redirect()->to('account/accept')->with('success', $return_msg); + $acceptance->accept($sig_filename, $item->getEula(), $pdf_filename); + event(new CheckoutAccepted($acceptance)); + + $return_msg = trans('admin/users/message.accepted'); + + } else { + $acceptance->decline($sig_filename); + event(new CheckoutDeclined($acceptance)); + $return_msg = trans('admin/users/message.declined'); } -// - $accessory_user= DB::table('checkout_acceptances')->find($acceptance->assigned_to_id); - $assigned_to = User::find($accessory_user->assigned_to_id); - $accessory_model = Accessory::find($item->id); - $branding_settings = SettingsController::getPDFBranding(); - $data = [ - 'item_tag' => $item->model_number, - 'item_model' => $accessory_model->name, - 'eula' => $item->getEula(), - 'check_out_date' => Carbon::parse($acceptance->created_at)->format($branding_settings->date_display_format), - 'accepted_date' => Carbon::parse($acceptance->accepted_at)->format($branding_settings->date_display_format), -// 'assigned_by' => self - 'assigned_to' => $assigned_to->first_name . ' ' . $assigned_to->last_name, - 'company_name' => $branding_settings->site_name, - 'signature' => storage_path() . '/private_uploads/signatures/' . $sig_filename, - 'logo' => public_path() . '/uploads/' . $branding_settings->logo, - 'date_settings' => $branding_settings->date_display_format, - ]; - $pdf = Pdf::loadView('account.accept.accept-accessory-eula', $data); - Storage::put('private_uploads/eula-pdfs/' . $acceptance->stored_eula_file, $pdf->output()); - $a = new Actionlog(); - $a->stored_eula = $item->getEula(); - $a->stored_eula_file = $acceptance->stored_eula_file; - $a->save(); return redirect()->to('account/accept')->with('success', $return_msg); + } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/ReportsController.php b/app/Http/Controllers/Api/ReportsController.php index 815138654..1406dba79 100644 --- a/app/Http/Controllers/Api/ReportsController.php +++ b/app/Http/Controllers/Api/ReportsController.php @@ -52,7 +52,6 @@ class ReportsController extends Controller 'accept_signature', 'action_type', 'note', - 'stored_eula_file', ]; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php index 8acc0a7b6..657b02171 100644 --- a/app/Http/Controllers/Assets/AssetCheckinController.php +++ b/app/Http/Controllers/Assets/AssetCheckinController.php @@ -98,9 +98,6 @@ class AssetCheckinController extends Controller } $asset->location_id = $asset->rtd_location_id; - \Log::debug('After Location ID: '.$asset->location_id); - \Log::debug('After RTD Location ID: '.$asset->rtd_location_id); - if ($request->filled('location_id')) { \Log::debug('NEW Location ID: '.$request->get('location_id')); diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index fb2e291fd..12f89de2b 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -59,9 +59,14 @@ class ActionlogsTransformer $array = [ 'id' => (int) $actionlog->id, 'icon' => $icon, - 'file' => ($actionlog->filename!='') ? + 'file' => ($actionlog->filename!='') + ? [ - 'url' => route('show/assetfile', ['assetId' => $actionlog->item->id, 'fileId' => $actionlog->id]), + 'url' => ($actionlog->present()->actionType()=='accepted') + ? + route('log.storedeula.download', ['filename' => $actionlog->filename]) + : + route('show/assetfile', ['assetId' => $actionlog->id, 'fileId' => $actionlog->id]), 'filename' => $actionlog->filename, 'inlineable' => (bool) Helper::show_file_inline($actionlog->filename), ] : null, @@ -96,7 +101,6 @@ class ActionlogsTransformer 'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null, 'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null, 'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'), - 'stored_eula_file' => ($actionlog->stored_eula_file) ? route('log.storedeula.download', ['filename' => $actionlog->stored_eula_file]) : null, ]; //\Log::info("Clean Meta is: ".print_r($clean_meta,true)); diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 7fe523198..e3bc0839e 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -130,7 +130,7 @@ class AssetImporter extends ItemImporter //-- user_id is a property of the abstract class Importer, which this class inherits from and it's setted by //-- the class that needs to use it (command importer or GUI importer inside the project). if (isset($target)) { - $asset->fresh()->checkOut($target, $this->user_id); + $asset->fresh()->checkOut($target, $this->user_id, date('Y-m-d H:i:s')); } return; diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 93d16ff5b..22006d1cc 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -24,10 +24,14 @@ use Illuminate\Support\Facades\Notification; class CheckoutableListener { /** - * Notify the user about the checked out checkoutable + * Notify the user about the checked out checkoutable and add a record to the + * checkout_requests table. */ public function onCheckedOut($event) { + + \Log::debug('onCheckedOut in the Checkoutable listener fired'); + /** * When the item wasn't checked out to a user, we can't send notifications */ @@ -58,14 +62,12 @@ class CheckoutableListener */ public function onCheckedIn($event) { - \Log::debug('checkin fired'); + \Log::debug('onCheckedIn in the Checkoutable listener fired'); /** * When the item wasn't checked out to a user, we can't send notifications */ if (! $event->checkedOutTo instanceof User) { - \Log::debug('checked out to not a user'); - return; } @@ -81,16 +83,14 @@ class CheckoutableListener $acceptance->delete(); } } - \Log::debug('checked out to a user'); + + // Use default locale if (! $event->checkedOutTo->locale) { - \Log::debug('Use default settings locale'); Notification::locale(Setting::getSettings()->locale)->send( $this->getNotifiables($event), $this->getCheckinNotification($event) ); } else { - \Log::debug('Use user locale? I do not think this works as expected yet'); - // \Log::debug(print_r($this->getNotifiables($event), true)); Notification::send( $this->getNotifiables($event), $this->getCheckinNotification($event) @@ -151,10 +151,6 @@ class CheckoutableListener private function getCheckinNotification($event) { - // $model = get_class($event->checkoutable); - - - $notificationClass = null; switch (get_class($event->checkoutable)) { diff --git a/app/Listeners/LogListener.php b/app/Listeners/LogListener.php index 3988d116c..8fb6bfc00 100644 --- a/app/Listeners/LogListener.php +++ b/app/Listeners/LogListener.php @@ -22,24 +22,44 @@ use App\Models\LicenseSeat; class LogListener { + /** + * These onBlah methods are used by the subscribe() method further down in this file. + * This one creates an action_logs entry for the checkin + * @param CheckoutableCheckedIn $event + * @return void + * + */ public function onCheckoutableCheckedIn(CheckoutableCheckedIn $event) { $event->checkoutable->logCheckin($event->checkedOutTo, $event->note, $event->action_date); } + /** + * These onBlah methods are used by the subscribe() method further down in this file. + * This one creates an action_logs entry for the checkout + * + * @param CheckoutableCheckedOut $event + * @return void + * + */ public function onCheckoutableCheckedOut(CheckoutableCheckedOut $event) { $event->checkoutable->logCheckout($event->note, $event->checkedOutTo, $event->checkoutable->last_checkout); } + /** + * These onBlah methods are used by the subscribe() method further down in this file. + * This creates the entry in the action_logs table for the accept/decline action + */ public function onCheckoutAccepted(CheckoutAccepted $event) { + \Log::error('event passed to the onCheckoutAccepted listener:'); $logaction = new Actionlog(); $logaction->item()->associate($event->acceptance->checkoutable); $logaction->target()->associate($event->acceptance->assignedTo); $logaction->accept_signature = $event->acceptance->signature_filename; - $logaction->stored_eula_file = $event->acceptance->stored_eula_file; + $logaction->filename = $event->acceptance->stored_eula_file; $logaction->action_type = 'accepted'; // TODO: log the actual license seat that was checked out @@ -47,6 +67,7 @@ class LogListener $logaction->item()->associate($event->acceptance->checkoutable->license); } + \Log::debug('New onCheckoutAccepted Listener fired. logaction: '.print_r($logaction, true)); $logaction->save(); } diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index 8d430c79d..2d406b3aa 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -25,7 +25,7 @@ class Actionlog extends SnipeModel protected $table = 'action_logs'; public $timestamps = true; - protected $fillable = ['created_at', 'item_type', 'user_id', 'item_id', 'action_type', 'note', 'target_id', 'target_type', 'stored_eula', 'stored_eula_file']; + protected $fillable = ['created_at', 'item_type', 'user_id', 'item_id', 'action_type', 'note', 'target_id', 'target_type', 'stored_eula']; use Searchable; diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php index cc6ca37fd..1f2af711f 100644 --- a/app/Models/CheckoutAcceptance.php +++ b/app/Models/CheckoutAcceptance.php @@ -57,20 +57,24 @@ class CheckoutAcceptance extends Model } /** - * Accept the checkout acceptance + * Add a record to the checkout_acceptance table ONLY. + * Do not add stuff here that doesn't have a corresponding column in the + * checkout_acceptances table or you'll get an error. * * @param string $signature_filename */ - public function accept($signature_filename) + public function accept($signature_filename, $eula = null, $filename = null) { $this->accepted_at = now(); $this->signature_filename = $signature_filename; + $this->stored_eula = $eula; + $this->stored_eula_file = $filename; $this->save(); /** * Update state for the checked out item */ - $this->checkoutable->acceptedCheckout($this->assignedTo, $signature_filename); + $this->checkoutable->acceptedCheckout($this->assignedTo, $signature_filename, $filename); } /** diff --git a/app/Models/Setting.php b/app/Models/Setting.php index e58001f5b..0c3587977 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -218,6 +218,7 @@ class Setting extends Model */ public static function fileSizeConvert($bytes): string { + $result = 0; $bytes = floatval($bytes); $arBytes = [ 0 => [ diff --git a/app/Models/Traits/Acceptable.php b/app/Models/Traits/Acceptable.php index b0ddd665a..967d878fa 100644 --- a/app/Models/Traits/Acceptable.php +++ b/app/Models/Traits/Acceptable.php @@ -17,8 +17,9 @@ trait Acceptable * @param User $acceptedBy * @param string $signature */ - public function acceptedCheckout(User $acceptedBy, $signature) + public function acceptedCheckout(User $acceptedBy, $signature, $filename = null) { + \Log::debug('acceptedCheckout in Acceptable trait fired, tho it doesn\'t do anything?'); } /** diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index fc2537704..9868ad1b4 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -54,7 +54,6 @@ class CheckinAssetNotification extends Notification * has the corresponding checkbox checked. */ if ($this->item->checkin_email() && $this->target instanceof User && $this->target->email != '') { - \Log::debug('use email'); $notifyBy[] = 'mail'; } diff --git a/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.php index be9928282..8ab77c663 100644 --- a/app/Providers/SettingsServiceProvider.php +++ b/app/Providers/SettingsServiceProvider.php @@ -36,6 +36,11 @@ class SettingsServiceProvider extends ServiceProvider // Model paths and URLs + + \App::singleton('eula_pdf_path', function () { + return 'eula_pdf_path/'; + }); + \App::singleton('assets_upload_path', function () { return 'assets/'; }); diff --git a/database/migrations/2022_05_16_235350_remove_stored_eula_field.php b/database/migrations/2022_05_16_235350_remove_stored_eula_field.php new file mode 100644 index 000000000..48c8a1882 --- /dev/null +++ b/database/migrations/2022_05_16_235350_remove_stored_eula_field.php @@ -0,0 +1,48 @@ +get(); + + foreach ($actionlog_eulas as $eula_file) { + $eula_file->filename = $eula_file->stored_eula_file; + $eula_file->save(); + } + + $actionlog_bad_action_type = Actionlog::where('item_id', '=', 0)->whereNull('target_type')->whereNull('action_type')->whereNull('target_type')->get(); + + foreach ($actionlog_bad_action_type as $bad_action_type) { + $bad_action_type->delete(); + } + + Schema::table('action_logs', function (Blueprint $table) { + $table->dropColumn('stored_eula_file'); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('action_logs', function (Blueprint $table) { + $table->string('stored_eula_file')->nullable()->default(null); + }); + } +} diff --git a/resources/views/account/accept/accept-accessory-eula.blade.php b/resources/views/account/accept/accept-accessory-eula.blade.php index d2eb09017..98b80ba09 100644 --- a/resources/views/account/accept/accept-accessory-eula.blade.php +++ b/resources/views/account/accept/accept-accessory-eula.blade.php @@ -4,10 +4,16 @@ +
-@if ($signature) +@if ($logo){{$company_name}}
@@ -15,22 +21,27 @@ @endifDate: {{ date($date_settings) }}
Asset Tag: {{ $item_tag }}
-Asset Model: {{ $item_model }}
+
+ {{ trans('general.date') }}: {{ date($date_settings) }}
+ {{ trans('general.asset_model') }}: {{ $item_model }}
+
Assigned on: {{$check_out_date}}
-Accepted on: {{$accepted_date}}
-Assigned to: {{$assigned_to}}
-@if ($signature) -
+ Assigned on: {{$check_out_date}}
+ Assigned to: {{$assigned_to}}
+ Accepted on: {{$accepted_date}}
+