Skip to content

Commit b4ea75f

Browse files
authored
Merge branch 'master' into chore/migrate-textarea-helper
2 parents e45f563 + e37a990 commit b4ea75f

File tree

403 files changed

+3990
-277125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

403 files changed

+3990
-277125
lines changed

.env.dev.docker

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ MYSQL_ROOT_PASSWORD=changeme1234
1111
# REQUIRED: BASIC APP SETTINGS
1212
# --------------------------------------------
1313
APP_ENV=develop
14-
APP_DEBUG=false
14+
APP_DEBUG=true
1515
# please regenerate the APP_KEY value by calling `docker-compose run --rm snipeit bash` and then `php artisan key:generate --show` and then copy paste the value here
1616
APP_KEY=base64:3ilviXqB9u6DX1NRcyWGJ+sjySF+H18CPDGb3+IVwMQ=
1717
APP_URL=http://localhost:8000
@@ -158,7 +158,7 @@ RESET_PASSWORD_LINK_EXPIRES=900
158158
# --------------------------------------------
159159
# OPTIONAL: MISC
160160
# --------------------------------------------
161-
LOG_CHANNEL=stderr
161+
LOG_CHANNEL=single
162162
LOG_MAX_DAYS=10
163163
APP_LOCKED=false
164164
APP_CIPHER=AES-256-CBC

Dockerfile.alpine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ RUN mkdir -p /var/www/.composer && chown apache /var/www/.composer
7373

7474
# Install dependencies
7575
USER apache
76-
RUN COMPOSER_CACHE_DIR=/dev/null composer install --no-dev --working-dir=/var/www/html
76+
RUN COMPOSER_CACHE_DIR=/dev/null composer install --working-dir=/var/www/html
7777

7878
USER root
7979

app/Console/Commands/ResetDemoSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function handle()
6565
$settings->thumbnail_max_h = '30';
6666
$settings->locale = 'en-US';
6767
$settings->version_footer = 'on';
68-
$settings->support_footer = null;
68+
$settings->support_footer = 'on';
6969
$settings->saml_enabled = '0';
7070
$settings->saml_sp_x509cert = null;
7171
$settings->saml_idp_metadata = null;

app/Events/NoteAdded.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\Models\User;
6+
use Illuminate\Foundation\Events\Dispatchable;
7+
use Illuminate\Queue\SerializesModels;
8+
9+
class NoteAdded
10+
{
11+
use Dispatchable, SerializesModels;
12+
public $itemNoteAddedOn;
13+
public $note;
14+
public $noteAddedBy;
15+
16+
17+
/**
18+
* Create a new event instance.
19+
*
20+
* @return void
21+
*/
22+
public function __construct($itemNoteAddedOn, User $noteAddedBy, $note)
23+
{
24+
$this->itemNoteAddedOn = $itemNoteAddedOn;
25+
$this->note = $note;
26+
$this->noteAddedBy = $noteAddedBy;
27+
}
28+
}

app/Helpers/IconHelper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ public static function icon($type) {
184184
return 'fa-regular fa-id-card';
185185
case 'department' :
186186
return 'fa-solid fa-building-user';
187-
187+
case 'note':
188+
case 'notes':
189+
return 'fas fa-sticky-note';
188190
}
189191
}
190192
}

app/Http/Controllers/Accessories/AccessoriesFilesController.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ public function store(UploadFileRequest $request, $accessoryId = null) : Redirec
5151
}
5252

5353

54-
return redirect()->route('accessories.show', $accessory->id)->with('success', trans('general.file_upload_success'));
54+
return redirect()->route('accessories.show', $accessory->id)->withFragment('files')->with('success', trans('general.file_upload_success'));
5555

5656
}
5757

58-
return redirect()->route('accessories.show', $accessory->id)->with('error', trans('general.no_files_uploaded'));
58+
return redirect()->route('accessories.show', $accessory->id)->withFragment('files')->with('error', trans('general.no_files_uploaded'));
5959
}
6060
// Prepare the error message
61-
return redirect()->route('accessories.index')
62-
->with('error', trans('general.file_does_not_exist'));
61+
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
62+
6363
}
6464

6565
/**
@@ -72,30 +72,27 @@ public function store(UploadFileRequest $request, $accessoryId = null) : Redirec
7272
*/
7373
public function destroy($accessoryId = null, $fileId = null) : RedirectResponse
7474
{
75-
$accessory = Accessory::find($accessoryId);
76-
77-
// the asset is valid
78-
if (isset($accessory->id)) {
75+
if ($accessory = Accessory::find($accessoryId)) {
7976
$this->authorize('update', $accessory);
80-
$log = Actionlog::find($fileId);
8177

82-
// Remove the file if one exists
83-
if (Storage::exists('accessories/'.$log->filename)) {
84-
try {
85-
Storage::delete('accessories/'.$log->filename);
86-
} catch (\Exception $e) {
87-
Log::debug($e);
78+
if ($log = Actionlog::find($fileId)) {
79+
80+
if (Storage::exists('private_uploads/accessories/'.$log->filename)) {
81+
try {
82+
Storage::delete('private_uploads/accessories/' . $log->filename);
83+
$log->delete();
84+
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
85+
} catch (\Exception $e) {
86+
Log::debug($e);
87+
return redirect()->route('accessories.index')->with('error', trans('general.file_does_not_exist'));
88+
}
8889
}
89-
}
90-
91-
$log->delete();
9290

93-
return redirect()->back()
94-
->with('success', trans('admin/hardware/message.deletefile.success'));
91+
}
92+
return redirect()->route('accessories.show', ['accessory' => $accessory])->withFragment('files')->with('error', trans('general.log_record_not_found'));
9593
}
9694

97-
// Redirect to the licence management page
98-
return redirect()->route('accessories.index')->with('error', trans('general.file_does_not_exist'));
95+
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
9996
}
10097

10198
/**
@@ -125,10 +122,11 @@ public function show($accessoryId = null, $fileId = null) : View | RedirectRespo
125122
}
126123
}
127124

128-
return redirect()->route('accessories.show', ['accessory' => $accessory])->with('error', trans('general.log_record_not_found'));
125+
return redirect()->route('accessories.show', ['accessory' => $accessory])->withFragment('files')->with('error', trans('general.log_record_not_found'));
129126

130127
}
131128

132-
return redirect()->route('accessories.index')->with('error', trans('general.file_not_found'));
129+
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
130+
133131
}
134132
}

app/Http/Controllers/ActionlogController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ public function displaySig($filename) : RedirectResponse | Response | bool
4040
public function getStoredEula($filename) : Response | BinaryFileResponse | RedirectResponse
4141
{
4242
$this->authorize('view', \App\Models\Asset::class);
43-
$file = config('app.private_uploads').'/eula-pdfs/'.$filename;
43+
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+
}
4447

4548
if (Storage::exists('private_uploads/eula-pdfs/'.$filename)) {
46-
return response()->download($file);
49+
return response()->download(config('app.private_uploads').'/eula-pdfs/'.$filename);
4750
}
4851

4952
return redirect()->back()->with('error', trans('general.file_does_not_exist'));

app/Http/Controllers/Api/AssetModelFilesController.php

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Models\AssetModel;
1010
use App\Models\Actionlog;
1111
use App\Http\Requests\UploadFileRequest;
12+
use App\Http\Transformers\AssetModelsTransformer;
1213
use Illuminate\Http\JsonResponse;
1314
use Illuminate\Support\Facades\Log;
1415
use Symfony\Component\HttpFoundation\StreamedResponse;
@@ -68,37 +69,15 @@ public function store(UploadFileRequest $request, $assetModelId = null) : JsonRe
6869
/**
6970
* List the files for an asset.
7071
*
71-
* @param int $assetModelId
72+
* @param int $assetmodel
7273
* @since [v7.0.12]
7374
* @author [r-xyz]
7475
*/
75-
public function list($assetModelId = null) : JsonResponse
76+
public function list($assetmodel_id) : JsonResponse | array
7677
{
77-
// Start by checking if the asset being acted upon exists
78-
if (! $assetModel = AssetModel::find($assetModelId)) {
79-
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.does_not_exist')), 404);
80-
}
81-
82-
// the asset is valid
83-
if (isset($assetModel->id)) {
84-
$this->authorize('view', $assetModel);
85-
86-
// Check that there are some uploads on this asset that can be listed
87-
if ($assetModel->uploads->count() > 0) {
88-
$files = array();
89-
foreach ($assetModel->uploads as $upload) {
90-
array_push($files, $upload);
91-
}
92-
// Give the list of files back to the user
93-
return response()->json(Helper::formatStandardApiResponse('success', $files, trans('admin/models/message.upload.success')));
94-
}
95-
96-
// There are no files.
97-
return response()->json(Helper::formatStandardApiResponse('success', array(), trans('admin/models/message.upload.success')));
98-
}
99-
100-
// Send back an error message
101-
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.download.error')), 500);
78+
$assetmodel = AssetModel::with('uploads')->find($assetmodel_id);
79+
$this->authorize('view', $assetmodel);
80+
return (new AssetModelsTransformer)->transformAssetModelFiles($assetmodel, $assetmodel->uploads()->count());
10281
}
10382

10483
/**

app/Http/Controllers/Api/ImportController.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
use App\Models\Asset;
1010
use App\Models\Company;
1111
use App\Models\Import;
12+
use Illuminate\Http\UploadedFile;
1213
use Illuminate\Support\Facades\Artisan;
1314
use Illuminate\Database\Eloquent\JsonEncodingException;
1415
use Illuminate\Support\Facades\Request;
1516
use Illuminate\Support\Facades\Session;
1617
use Illuminate\Support\Facades\Storage;
1718
use League\Csv\Reader;
19+
use Onnov\DetectEncoding\EncodingDetector;
1820
use Symfony\Component\HttpFoundation\File\Exception\FileException;
1921
use Illuminate\Support\Facades\Log;
2022
use Illuminate\Http\JsonResponse;
@@ -45,6 +47,8 @@ public function store() : JsonResponse
4547
$path = config('app.private_uploads').'/imports';
4648
$results = [];
4749
$import = new Import;
50+
$detector = new EncodingDetector();
51+
4852
foreach ($files as $file) {
4953
if (! in_array($file->getMimeType(), [
5054
'application/vnd.ms-excel',
@@ -55,15 +59,32 @@ public function store() : JsonResponse
5559
'text/comma-separated-values',
5660
'text/tsv', ])) {
5761
$results['error'] = 'File type must be CSV. Uploaded file is '.$file->getMimeType();
58-
5962
return response()->json(Helper::formatStandardApiResponse('error', null, $results['error']), 422);
6063
}
6164

6265
//TODO: is there a lighter way to do this?
6366
if (! ini_get('auto_detect_line_endings')) {
6467
ini_set('auto_detect_line_endings', '1');
6568
}
69+
$file_contents = $file->getContent(); //TODO - this *does* load the whole file in RAM, but we need that to be able to 'iconv' it?
70+
$encoding = $detector->getEncoding($file_contents);
71+
$reader = null;
72+
if (strcasecmp($encoding, 'UTF-8') != 0) {
73+
$transliterated = iconv($encoding, 'UTF-8', $file_contents);
74+
if ($transliterated !== false) {
75+
$tmpname = tempnam(sys_get_temp_dir(), '');
76+
$tmpresults = file_put_contents($tmpname, $transliterated);
77+
if ($tmpresults !== false) {
78+
$transliterated = null; //save on memory?
79+
$newfile = new UploadedFile($tmpname, $file->getClientOriginalName(), null, null, true); //WARNING: this is enabling 'test mode' - which is gross, but otherwise the file won't be treated as 'uploaded'
80+
if ($newfile->isValid()) {
81+
$file = $newfile;
82+
}
83+
}
84+
}
85+
}
6686
$reader = Reader::createFromFileObject($file->openFile('r')); //file pointer leak?
87+
$file_contents = null; //try to save on memory, I guess?
6788
6889
try {
6990
$import->header_row = $reader->fetchOne(0);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Events\NoteAdded;
6+
use App\Helpers\Helper;
7+
use App\Http\Controllers\Controller;
8+
use App\Models\Asset;
9+
use Illuminate\Http\Request;
10+
use Illuminate\Support\Facades\Auth;
11+
use Illuminate\Validation\Rule;
12+
13+
class NotesController extends Controller
14+
{
15+
public function store(Request $request)
16+
{
17+
$validated = $request->validate([
18+
'note' => 'required|string|max:500',
19+
'type' => [
20+
'required',
21+
Rule::in(['asset']),
22+
],
23+
]);
24+
25+
// This can be made dynamic by using $request->input('type') to determine which model type to add the note to.
26+
// For now, we are only placing this on Assets
27+
$item = Asset::findOrFail($request->input("id"));
28+
$this->authorize('update', $item);
29+
30+
event(new NoteAdded($item, Auth::user(), $validated['note']));
31+
32+
return response()->json(Helper::formatStandardApiResponse('success'));
33+
}
34+
35+
public function update(Request $request)
36+
{
37+
38+
}
39+
public function destroy(Request $request)
40+
{
41+
42+
}
43+
}

0 commit comments

Comments
 (0)