From b2f7262cd2dda6ffd046eaedceb2091947210a80 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 14 Mar 2022 19:38:36 -0700 Subject: [PATCH] adds table structure for asset history --- .../Account/AcceptanceController.php | 22 ++++------ app/Http/Controllers/ActionlogController.php | 2 +- .../Transformers/ActionlogsTransformer.php | 2 +- app/Listeners/LogListener.php | 3 +- app/Models/Actionlog.php | 2 +- ...001334_add_eula_to_checkout_acceptance.php | 31 ++++++++++++++ resources/views/hardware/view.blade.php | 42 ++++++++++++++++++- .../views/partials/bootstrap-table.blade.php | 1 - 8 files changed, 85 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index b3d4d26a2b..2b9f2881be 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -102,12 +102,12 @@ class AcceptanceController extends Controller } $sig_filename = ''; - if ($request->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 = 'private_uploads/eula-pdfs/accepted-eula-'.date('Y-m-d-h-i-s').'.pdf'; $path = Storage::put('private_uploads/signatures/'.$sig_filename, (string) $decoded_image); } @@ -139,19 +139,13 @@ class AcceptanceController extends Controller \Log::error(storage_path().'/eula-pdfs/'.$sig_filename); $pdf = Pdf::loadView('account.accept.accept-eula', $data); - $stored_eula= Storage::put('private_uploads/eula-pdfs/accepted-eula-'.date('Y-m-d-h-i-s').'.pdf', $pdf->output()); - \Log::info($stored_eula); - //not sure what im doing here,but I think its something of this. - Actionlog::Create([ - 'item_id' => $acceptance->id, - 'stored_eula' => $stored_eula, - 'action_type' => 'accepted', - ]); - \log::info(Actionlog::Create([ - 'item_id' => $acceptance->id, - 'stored_eula' => $stored_eula, - 'action_type' => 'accepted', - ])); + Storage::put($acceptance->stored_eula_file, $pdf->output()); + $a=new Actionlog(); + $a->stored_eula = $item->getEula(); + $a->stored_eula_file = $acceptance->stored_eula_file; + $a->save(); + \log::info($a); + return redirect()->to('account/accept')->with('success', $return_msg); } diff --git a/app/Http/Controllers/ActionlogController.php b/app/Http/Controllers/ActionlogController.php index f4e86e0d52..8d45aebe19 100644 --- a/app/Http/Controllers/ActionlogController.php +++ b/app/Http/Controllers/ActionlogController.php @@ -19,7 +19,7 @@ class ActionlogController extends Controller public function getStoredEula($filename){ $this->authorize('view', \App\Models\Asset::class); - $file = config('app.private_uploads').'/eula-pdfs/'.$filename; + $file = config('app'.$filename); return Response::download($file); diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 4e774ac581..78fff1b20e 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -112,7 +112,7 @@ 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, + 'stored_eula_file' => $actionlog->stored_eula_file, ]; return $array; diff --git a/app/Listeners/LogListener.php b/app/Listeners/LogListener.php index f337df60f5..3988d116c2 100644 --- a/app/Listeners/LogListener.php +++ b/app/Listeners/LogListener.php @@ -34,11 +34,12 @@ class LogListener public function onCheckoutAccepted(CheckoutAccepted $event) { - $logaction = new Actionlog(); + $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->action_type = 'accepted'; // TODO: log the actual license seat that was checked out diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index edbc9d9eef..de313a1b26 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']; + protected $fillable = ['created_at', 'item_type', 'user_id', 'item_id', 'action_type', 'note', 'target_id', 'target_type', 'stored_eula', 'stored_eula_file']; use Searchable; diff --git a/database/migrations/2022_03_09_001334_add_eula_to_checkout_acceptance.php b/database/migrations/2022_03_09_001334_add_eula_to_checkout_acceptance.php index 39b21a4c91..07101d1694 100644 --- a/database/migrations/2022_03_09_001334_add_eula_to_checkout_acceptance.php +++ b/database/migrations/2022_03_09_001334_add_eula_to_checkout_acceptance.php @@ -5,3 +5,34 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class AddEulaToCheckoutAcceptance extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('checkout_acceptances', function (Blueprint $table) { + $table->text('stored_eula')->nullable()->default(null); + $table->string('stored_eula_file')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('checkout_acceptances', function (Blueprint $table) { + if (Schema::hasColumn('checkout_acceptances', 'stored_eula')) { + $table->dropColumn('stored_eula'); + } + if (Schema::hasColumn('checkout_acceptances', 'stored_eula_file')) { + $table->dropColumn('stored_eula_file'); + } + }); + } +} \ No newline at end of file diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 7c5e28b7a2..76e1f9e13f 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -1093,11 +1093,51 @@ {{ trans('general.item') }} {{ trans('general.target') }} {{ trans('general.notes') }} - {{ trans('general.accept_eula') }} + {{ trans('general.accept_eula') }} {{ trans('general.download') }} {{ trans('admin/hardware/table.changed')}} + @foreach($action_logs as $log) + + + + @if($log->created_at) + {{ Helper::getFormattedDateObject($file->created_at, 'datetime', false) }} + @endif + + + {{$log->user_id}} + + + {{$log->action_type}} + + + {{$log->item_type}} + + + {{$log->item_type}} + + + @if($log->note) + {{$log->note}} + @endif + + + @if($log->stored_eula_file) + {{$log->stored_eula_file}} + @endif + + + @if($log->file) + {{$log->file}} + @endif + + + {{$log->log_meta}} + + + @endforeach diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 3c1512b2d2..88b9584542 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -6,7 +6,6 @@ @push('js') -