Skip to content

Commit 9db65c6

Browse files
authored
Merge pull request grokability#17881 from grokability/grokability#17873-eula-tab-on-users
Fixed grokability#17873 - Added EULA tab to user view
2 parents a18957d + 1346e33 commit 9db65c6

File tree

4 files changed

+68
-15
lines changed

4 files changed

+68
-15
lines changed

app/Http/Controllers/Account/AcceptanceController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ public function store(Request $request, $id) : RedirectResponse
120120

121121

122122
$item = $acceptance->checkoutable_type::find($acceptance->checkoutable_id);
123-
$display_model = '';
124-
$pdf_view_route = '';
125-
$pdf_filename = 'accepted-eula-'.date('Y-m-d-h-i-s').'.pdf';
123+
$checkout_type_shortname = strtolower(str_replace('App\Models\\', '', $acceptance->checkoutable_type));
124+
$pdf_filename = 'accepted-'.$acceptance->checkoutable_id.'-'.$checkout_type_shortname.'-eula-'.date('Y-m-d-h-i-s').'.pdf';
126125
$sig_filename='';
127126

128127
if ($request->input('asset_acceptance') == 'accepted') {
@@ -164,7 +163,7 @@ public function store(Request $request, $id) : RedirectResponse
164163

165164
$data = [
166165
'item_tag' => $item->asset_tag,
167-
'item_model' => $display_model,
166+
'item_model' => $item->model ? $item->model->name : $item->display_name,
168167
'item_serial' => $item->serial,
169168
'item_status' => $item->assetstatus?->name,
170169
'eula' => $item->getEula(),
@@ -203,7 +202,7 @@ public function store(Request $request, $id) : RedirectResponse
203202
$pdf->AddPage();
204203
$pdf->writeHTML('<img src="'.$path_logo.'" height="30">', true, 0, true, 0, '');
205204

206-
if ($data['item_serial']) {
205+
if ($data['item_tag']) {
207206
$pdf->writeHTML("<strong>" . trans('general.asset_tag') . '</strong>: ' . $data['item_tag'], true, 0, true, 0, '');
208207
}
209208
$pdf->writeHTML("<strong>".trans('general.asset_model').'</strong>: '.$data['item_model'], true, 0, true, 0, '');

app/Http/Controllers/ActionlogController.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
namespace App\Http\Controllers;
44

55
use App\Helpers\Helper;
6+
use App\Models\Actionlog;
67
use Illuminate\Http\RedirectResponse;
78
use Illuminate\Support\Facades\Log;
89
use Illuminate\Support\Facades\Storage;
9-
use \Illuminate\Http\Response;
1010
use Symfony\Component\HttpFoundation\BinaryFileResponse;
11+
use \Illuminate\Http\Response;
12+
1113
class ActionlogController extends Controller
1214
{
1315
public function displaySig($filename) : RedirectResponse | Response | bool
@@ -39,17 +41,29 @@ public function displaySig($filename) : RedirectResponse | Response | bool
3941

4042
public function getStoredEula($filename) : Response | BinaryFileResponse | RedirectResponse
4143
{
42-
$this->authorize('view', \App\Models\Asset::class);
4344

44-
if (config('filesystems.default') == 's3_private') {
45-
return redirect()->away(Storage::disk('s3_private')->temporaryUrl('private_uploads/eula-pdfs/'.$filename, now()->addMinutes(5)));
46-
}
45+
if ($actionlog = Actionlog::where('filename', $filename)->with('user')->with('target')->firstOrFail()) {
46+
47+
$this->authorize('view', $actionlog->target);
48+
$this->authorize('view', $actionlog->user);
4749

48-
if (Storage::exists('private_uploads/eula-pdfs/'.$filename)) {
49-
return response()->download(config('app.private_uploads').'/eula-pdfs/'.$filename);
50-
}
5150

52-
return redirect()->back()->with('error', trans('general.file_does_not_exist'));
51+
if (config('filesystems.default') == 's3_private') {
52+
return redirect()->away(Storage::disk('s3_private')->temporaryUrl('private_uploads/eula-pdfs/' . $filename, now()->addMinutes(5)));
53+
}
54+
55+
if (Storage::exists('private_uploads/eula-pdfs/' . $filename)) {
56+
57+
if (request()->input('inline') == 'true') {
58+
return response()->file(config('app.private_uploads') . '/eula-pdfs/' . $filename);
59+
}
60+
61+
return response()->download(config('app.private_uploads') . '/eula-pdfs/' . $filename);
62+
}
63+
64+
return redirect()->back()->with('error', trans('general.file_does_not_exist'));
65+
}
5366

67+
return redirect()->back()->with('error', trans('general.record_not_found'));
5468
}
5569
}

app/Http/Transformers/ActionlogsTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function transformActionlog (Actionlog $actionlog, $settings = null)
147147
[
148148
'url' => $actionlog->uploads_file_url(),
149149
'filename' => $actionlog->filename,
150-
'inlineable' => StorageHelper::allowSafeInline($actionlog->uploads_file_url()),
150+
'inlineable' => StorageHelper::allowSafeInline($actionlog->uploads_file_path()),
151151
'exists_on_disk' => Storage::exists($actionlog->uploads_file_path()) ? true : false,
152152
] : null,
153153

resources/views/users/view.blade.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@
9494
</a>
9595
</li>
9696

97+
<li>
98+
<a href="#eulas" data-toggle="tab">
99+
<span class="hidden-lg hidden-md" aria-hidden="true">
100+
<x-icon type="files" class="fa-2x" />
101+
</span>
102+
<span class="hidden-xs hidden-sm">{{ trans('general.eula') }}
103+
{!! ($user->eulas->count() > 0 ) ? '<span class="badge badge-secondary">'.number_format($user->eulas->count()).'</span>' : '' !!}
104+
</span>
105+
</a>
106+
</li>
107+
97108
<li>
98109
<a href="#history" data-toggle="tab">
99110
<span class="hidden-lg hidden-md">
@@ -1001,6 +1012,35 @@ class="table table-striped snipe-table table-hover"
10011012
</div> <!--/ROW-->
10021013
</div><!--/FILES-->
10031014

1015+
<div class="tab-pane" id="eulas">
1016+
<table
1017+
data-toolbar="#userEULAToolbar"
1018+
data-cookie-id-table="userEULATable"
1019+
data-id-table="userEULATable"
1020+
id="userEULATable"
1021+
data-side-pagination="client"
1022+
data-show-footer="true"
1023+
data-show-refresh="false"
1024+
data-sort-order="asc"
1025+
data-sort-name="name"
1026+
class="table table-striped snipe-table table-hover"
1027+
data-url="{{ route('api.user.eulas', $user) }}"
1028+
data-export-options='{
1029+
"fileName": "export-eula-{{ str_slug($user->username) }}-{{ date('Y-m-d') }}",
1030+
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","delete","purchasecost", "icon"]
1031+
}'>
1032+
<thead>
1033+
<tr>
1034+
<th data-visible="true" data-field="icon" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter">{{ trans('admin/hardware/table.icon') }}</th>
1035+
<th data-visible="true" data-field="item.name">{{ trans('general.item') }}</th>
1036+
<th data-visible="true" data-field="created_at" data-sortable="true" data-formatter="dateDisplayFormatter">{{ trans('general.accepted_date') }}</th>
1037+
<th data-field="note">{{ trans('general.notes') }}</th>
1038+
<th data-field="url" data-formatter="fileDownloadButtonsFormatter">{{ trans('general.download') }}</th>
1039+
</tr>
1040+
</thead>
1041+
</table>
1042+
</div><!-- /eulas-tab -->
1043+
10041044
<div class="tab-pane" id="history">
10051045
<div class="table-responsive">
10061046

0 commit comments

Comments
 (0)