diff --git a/.all-contributorsrc b/.all-contributorsrc index 68aec85323..679f2740ac 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -3190,6 +3190,15 @@ "contributions": [ "code" ] + }, + { + "login": "Scarzy", + "name": "Scarzy", + "avatar_url": "https://avatars.githubusercontent.com/u/1197791?v=4", + "profile": "https://github.com/Scarzy", + "contributions": [ + "code" + ] } ] } diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6359814b49..1bea567693 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -52,7 +52,7 @@ Thanks goes to all of these wonderful people ([emoji key](https://github.com/ken | [
bilias](https://github.com/bilias)
[💻](https://github.com/snipe/snipe-it/commits?author=bilias "Code") | [
coach1988](https://github.com/coach1988)
[💻](https://github.com/snipe/snipe-it/commits?author=coach1988 "Code") | [
MrM](https://github.com/mauro-miatello)
[💻](https://github.com/snipe/snipe-it/commits?author=mauro-miatello "Code") | [
koiakoia](https://github.com/koiakoia)
[💻](https://github.com/snipe/snipe-it/commits?author=koiakoia "Code") | [
Mustafa Online](https://github.com/mustafa-online)
[💻](https://github.com/snipe/snipe-it/commits?author=mustafa-online "Code") | [
franceslui](https://github.com/franceslui)
[💻](https://github.com/snipe/snipe-it/commits?author=franceslui "Code") | [
Q4kK](https://github.com/Q4kK)
[💻](https://github.com/snipe/snipe-it/commits?author=Q4kK "Code") | | [
squintfox](https://github.com/squintfox)
[💻](https://github.com/snipe/snipe-it/commits?author=squintfox "Code") | [
Jeff Clay](https://github.com/jeffclay)
[💻](https://github.com/snipe/snipe-it/commits?author=jeffclay "Code") | [
Phil J R](https://github.com/PP-JN-RL)
[💻](https://github.com/snipe/snipe-it/commits?author=PP-JN-RL "Code") | [
i_virus](https://www.corelight.com/)
[💻](https://github.com/snipe/snipe-it/commits?author=chandanchowdhury "Code") | [
Paul Grime](https://github.com/gitgrimbo)
[💻](https://github.com/snipe/snipe-it/commits?author=gitgrimbo "Code") | [
Lee Porte](https://leeporte.co.uk)
[💻](https://github.com/snipe/snipe-it/commits?author=LeePorte "Code") | [
BRYAN ](https://github.com/bryanlopezinc)
[💻](https://github.com/snipe/snipe-it/commits?author=bryanlopezinc "Code") [⚠️](https://github.com/snipe/snipe-it/commits?author=bryanlopezinc "Tests") | | [
U-H-T](https://github.com/U-H-T)
[💻](https://github.com/snipe/snipe-it/commits?author=U-H-T "Code") | [
Matt Tyree](https://github.com/Tyree)
[📖](https://github.com/snipe/snipe-it/commits?author=Tyree "Documentation") | [
Florent Bervas](http://spoontux.net)
[💻](https://github.com/snipe/snipe-it/commits?author=FlorentDotMe "Code") | [
Daniel Albertsen](https://ditscheri.com)
[💻](https://github.com/snipe/snipe-it/commits?author=dbakan "Code") | [
r-xyz](https://github.com/r-xyz)
[💻](https://github.com/snipe/snipe-it/commits?author=r-xyz "Code") | [
Steven Mainor](https://github.com/DrekiDegga)
[💻](https://github.com/snipe/snipe-it/commits?author=DrekiDegga "Code") | [
arne-kroeger](https://github.com/arne-kroeger)
[💻](https://github.com/snipe/snipe-it/commits?author=arne-kroeger "Code") | -| [
Glukose1](https://github.com/Glukose1)
[💻](https://github.com/snipe/snipe-it/commits?author=Glukose1 "Code") | +| [
Glukose1](https://github.com/Glukose1)
[💻](https://github.com/snipe/snipe-it/commits?author=Glukose1 "Code") | [
Scarzy](https://github.com/Scarzy)
[💻](https://github.com/snipe/snipe-it/commits?author=Scarzy "Code") | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! diff --git a/Dockerfile.alpine b/Dockerfile.alpine index c08cbbd95c..2c83a1a119 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -79,12 +79,12 @@ USER root VOLUME ["/var/lib/snipeit"] -# Entrypoints -COPY docker/entrypoint_alpine.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh +# Startup script +COPY docker/startup_alpine.sh /startup.sh +RUN chmod +x /startup.sh ENTRYPOINT ["/sbin/tini", "--"] -CMD ["/entrypoint.sh"] +CMD ["/startup.sh"] EXPOSE 80 diff --git a/Dockerfile.fpm-alpine b/Dockerfile.fpm-alpine index 77302524d4..b7fb272985 100644 --- a/Dockerfile.fpm-alpine +++ b/Dockerfile.fpm-alpine @@ -97,7 +97,7 @@ RUN set -eux; \ VOLUME [ "/var/lib/snipeit" ] COPY --chown=www-data:www-data docker/docker-secrets.env /var/www/html/.env -COPY --chmod=655 docker/docker-entrypoint.sh /usr/local/bin/docker-snipeit-entrypoint +COPY --chmod=655 docker/startup_alpine_fpm.sh /startup.sh COPY docker/column-statistics.cnf /etc/mysql/conf.d/column-statistics.cnf -ENTRYPOINT [ "/usr/local/bin/docker-snipeit-entrypoint" ] -CMD [ "/usr/local/bin/docker-php-entrypoint", "php-fpm" ] +ENTRYPOINT [ "/startup.sh" ] +CMD [ "/startup.sh", "php-fpm" ] diff --git a/app/Http/Controllers/Api/AssetModelFilesController.php b/app/Http/Controllers/Api/AssetModelFilesController.php new file mode 100644 index 0000000000..90d283f72e --- /dev/null +++ b/app/Http/Controllers/Api/AssetModelFilesController.php @@ -0,0 +1,200 @@ + + * + * @version v1.0 + * @author [T. Scarsbrook] [] + */ +class AssetModelFilesController extends Controller +{ + /** + * Accepts a POST to upload a file to the server. + * + * @param \App\Http\Requests\UploadFileRequest $request + * @param int $assetModelId + * @since [v7.0.12] + * @author [r-xyz] + */ + public function store(UploadFileRequest $request, $assetModelId = null) : JsonResponse + { + // Start by checking if the asset being acted upon exists + if (! $assetModel = AssetModel::find($assetModelId)) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.does_not_exist')), 404); + } + + // Make sure we are allowed to update this asset + $this->authorize('update', $assetModel); + + if ($request->hasFile('file')) { + // If the file storage directory doesn't exist; create it + if (! Storage::exists('private_uploads/assetmodels')) { + Storage::makeDirectory('private_uploads/assetmodels', 775); + } + + // Loop over the attached files and add them to the asset + foreach ($request->file('file') as $file) { + $file_name = $request->handleFile('private_uploads/assetmodels/','model-'.$assetModel->id, $file); + + $assetModel->logUpload($file_name, e($request->get('notes'))); + } + + // All done - report success + return response()->json(Helper::formatStandardApiResponse('success', $assetModel, trans('admin/models/message.upload.success'))); + } + + // We only reach here if no files were included in the POST, so tell the user this + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.upload.nofiles')), 500); + } + + /** + * List the files for an asset. + * + * @param int $assetModelId + * @since [v7.0.12] + * @author [r-xyz] + */ + public function list($assetModelId = null) : JsonResponse + { + // Start by checking if the asset being acted upon exists + if (! $assetModel = AssetModel::find($assetModelId)) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.does_not_exist')), 404); + } + + // the asset is valid + if (isset($assetModel->id)) { + $this->authorize('view', $assetModel); + + // Check that there are some uploads on this asset that can be listed + if ($assetModel->uploads->count() > 0) { + $files = array(); + foreach ($assetModel->uploads as $upload) { + array_push($files, $upload); + } + // Give the list of files back to the user + return response()->json(Helper::formatStandardApiResponse('success', $files, trans('admin/models/message.upload.success'))); + } + + // There are no files. + return response()->json(Helper::formatStandardApiResponse('success', array(), trans('admin/models/message.upload.success'))); + } + + // Send back an error message + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.download.error')), 500); + } + + /** + * Check for permissions and display the file. + * + * @param int $assetModelId + * @param int $fileId + * @return \Illuminate\Http\JsonResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + * @since [v7.0.12] + * @author [r-xyz] + */ + public function show($assetModelId = null, $fileId = null) : JsonResponse | StreamedResponse | Storage | StorageHelper | BinaryFileResponse + { + // Start by checking if the asset being acted upon exists + if (! $assetModel = AssetModel::find($assetModelId)) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.does_not_exist')), 404); + } + + // the asset is valid + if (isset($assetModel->id)) { + $this->authorize('view', $assetModel); + + // Check that the file being requested exists for the asset + if (! $log = Actionlog::whereNotNull('filename')->where('item_id', $assetModel->id)->find($fileId)) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.download.no_match', ['id' => $fileId])), 404); + } + + // Form the full filename with path + $file = 'private_uploads/assetmodels/'.$log->filename; + Log::debug('Checking for '.$file); + + if ($log->action_type == 'audit') { + $file = 'private_uploads/audits/'.$log->filename; + } + + // Check the file actually exists on the filesystem + if (! Storage::exists($file)) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.download.does_not_exist', ['id' => $fileId])), 404); + } + + if (request('inline') == 'true') { + + $headers = [ + 'Content-Disposition' => 'inline', + ]; + + return Storage::download($file, $log->filename, $headers); + } + + return StorageHelper::downloader($file); + } + + // Send back an error message + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.download.error', ['id' => $fileId])), 500); + } + + /** + * Delete the associated file + * + * @param int $assetModelId + * @param int $fileId + * @since [v7.0.12] + * @author [r-xyz] + */ + public function destroy($assetModelId = null, $fileId = null) : JsonResponse + { + // Start by checking if the asset being acted upon exists + if (! $assetModel = AssetModel::find($assetModelId)) { + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.does_not_exist')), 404); + } + + $rel_path = 'private_uploads/assetmodels'; + + // the asset is valid + if (isset($assetModel->id)) { + $this->authorize('update', $assetModel); + + // Check for the file + $log = Actionlog::find($fileId); + if ($log) { + // Check the file actually exists, and delete it + if (Storage::exists($rel_path.'/'.$log->filename)) { + Storage::delete($rel_path.'/'.$log->filename); + } + // Delete the record of the file + $log->delete(); + + // All deleting done - notify the user of success + return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/models/message.deletefile.success')), 200); + } + + // The file doesn't seem to really exist, so report an error + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.deletefile.error')), 500); + } + + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.deletefile.error')), 500); + } +} diff --git a/docker/entrypoint_alpine.sh b/docker/startup_alpine.sh similarity index 100% rename from docker/entrypoint_alpine.sh rename to docker/startup_alpine.sh diff --git a/docker/docker-entrypoint.sh b/docker/startup_alpine_fpm.sh similarity index 100% rename from docker/docker-entrypoint.sh rename to docker/startup_alpine_fpm.sh diff --git a/resources/assets/less/overrides.less b/resources/assets/less/overrides.less index 3358e55632..735791b4cd 100644 --- a/resources/assets/less/overrides.less +++ b/resources/assets/less/overrides.less @@ -851,6 +851,24 @@ th.css-component > .th-inner::before margin-top:50px } } +@media screen and (max-width: 992px){ + .info-stack-container { + display: flex; + flex-direction: column; + } + .col-md-3.col-xs-12.col-sm-push-9.info-stack{ + left:auto; + order:1; + } + .col-md-9.col-xs-12.col-sm-pull-3.info-stack{ + right:auto; + order:2; + } + .info-stack-container > .col-md-9.col-xs-12.col-sm-pull-3.info-stack > .row-new-striped > .row > .col-sm-2{ + width:auto; + float:none; + } +} @media screen and (max-width: 1318px) and (min-width: 1200px){ .admin.box{ height:170px; diff --git a/resources/lang/en-GB/admin/models/message.php b/resources/lang/en-GB/admin/models/message.php index ae3bc34eed..18a3fb10ce 100644 --- a/resources/lang/en-GB/admin/models/message.php +++ b/resources/lang/en-GB/admin/models/message.php @@ -43,5 +43,11 @@ return array( 'success' => 'Model deleted!|:success_count models deleted!', 'success_partial' => ':success_count model(s) were deleted, however :fail_count were unable to be deleted because they still have assets associated with them.' ), + 'download' => [ + 'error' => 'File(s) not downloaded. Please try again.', + 'success' => 'File(s) successfully downloaded.', + 'does_not_exist' => 'No file exists', + 'no_match' => 'No matching record for that asset/file', + ], ); diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index a60f0dedfd..4ebf1b8977 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -561,5 +561,6 @@ return [ 'remaining_var' => ':count Remaining', 'label' => 'Label', 'import_asset_tag_exists' => 'An asset with the asset tag :asset_tag already exists and an update was not requested. No change was made.', + 'countries_manually_entered_help' => 'Values with an asterisk (*) were manually entered and do not match existing ISO 3166 dropdown values', ]; diff --git a/resources/lang/en-US/localizations.php b/resources/lang/en-US/localizations.php index f335ddc1b3..e87af0718e 100644 --- a/resources/lang/en-US/localizations.php +++ b/resources/lang/en-US/localizations.php @@ -135,6 +135,7 @@ return [ 'EC'=>'Ecuador', 'EE'=>'Estonia', 'EG'=>'Egypt', + 'GB-ENG'=>'England', 'ER'=>'Eritrea', 'ES'=>'Spain', 'ET'=>'Ethiopia', @@ -233,6 +234,7 @@ return [ 'NG'=>'Nigeria', 'NI'=>'Nicaragua', 'NL'=>'Netherlands', + 'GB-NIR' => 'Northern Ireland', 'NO'=>'Norway', 'NP'=>'Nepal', 'NR'=>'Nauru', @@ -260,7 +262,7 @@ return [ 'RU'=>'Russian Federation', 'RW'=>'Rwanda', 'SA'=>'Saudi Arabia', - 'UK'=>'Scotland', + 'GB-SCT'=>'Scotland', 'SB'=>'Solomon Islands', 'SC'=>'Seychelles', 'SS'=>'South Sudan', @@ -312,6 +314,7 @@ return [ 'VI'=>'Virgin Islands (U.S.)', 'VN'=>'Viet Nam', 'VU'=>'Vanuatu', + 'GB-WLS' =>'Wales', 'WF'=>'Wallis And Futuna Islands', 'WS'=>'Samoa', 'YE'=>'Yemen', diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 7fefba2aa6..5d0813115e 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -32,18 +32,27 @@ Form::macro('countries', function ($name = 'country', $selected = null, $class = $idclause = (!is_null($id)) ? $id : ''; - $select = ''; $select .= ''; - // Pull the autoglossonym array from the localizations translation file - foreach (trans('localizations.countries') as $abbr => $country) { + foreach ($countries_array as $abbr => $country) { // We have to handle it this way to handle deprecication warnings since you can't strtoupper on null if ($abbr!='') { $abbr = strtoupper($abbr); } - $select .= ' '; + // Loop through the countries configured in the localization file + $select .= ' '; + + } + + // If the country value doesn't exist in the array, add it as a new option and select it so we don't drop that data + if (!in_array($selected, $countries_array)) { + $select .= ' '; } $select .= ''; diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 2da4038340..3f4a520374 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -160,9 +160,9 @@ @endif - +
-
+
@if (($asset->image) || (($asset->model) && ($asset->model->image!=''))) @@ -334,7 +334,7 @@ -
+
@@ -1078,6 +1078,7 @@
+
@@ -1120,7 +1121,7 @@ @else -
+
{{ trans('general.no_results') }}
@@ -1157,7 +1158,7 @@ {{ Helper::formatCurrencyOutput($component->purchase_cost) }} each {{ $component->serial }} - {{ trans('general.checkin') }} + {{ trans('general.checkin') }} purchase_cost *$component->pivot->assigned_qty) ?> @@ -1175,7 +1176,7 @@ @else -
+
{{ trans('general.no_results') }}
@@ -1239,7 +1240,7 @@ @else -
+
{{ trans('general.no_results') }}
@@ -1399,11 +1400,11 @@ @if (($file->filename) && (Storage::exists('private_uploads/assets/'.$file->filename))) - + - + @endif @@ -1415,7 +1416,7 @@ @can('update', \App\Models\Asset::class) - + @endcan @@ -1427,7 +1428,7 @@ @else -
+
{{ trans('general.no_results') }}
@@ -1503,12 +1504,12 @@ @if (($file->filename) && (Storage::exists('private_uploads/assetmodels/'.$file->filename))) - - + + - - + + @endif @@ -1520,8 +1521,8 @@ @can('update', \App\Models\AssetModel::class) - - + + @endcan diff --git a/resources/views/partials/forms/edit/address.blade.php b/resources/views/partials/forms/edit/address.blade.php index c68ecaa8c2..893bd01339 100644 --- a/resources/views/partials/forms/edit/address.blade.php +++ b/resources/views/partials/forms/edit/address.blade.php @@ -35,6 +35,7 @@ {{ Form::label('country', trans('general.country'), array('class' => 'col-md-3 control-label')) }}
{!! Form::countries('country', old('country', $item->country), 'select2') !!} +

{{ trans('general.countries_manually_entered_help') }}

{!! $errors->first('country', '') !!}
diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 5f0246d022..1c23b76823 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -451,6 +451,8 @@
{!! Form::countries('country', old('country', $user->country), 'col-md-12 select2') !!} + +

{{ trans('general.countries_manually_entered_help') }}

{!! $errors->first('country', '') !!}
diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index 8fbed865ee..13924dd70c 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -159,9 +159,9 @@
@endif - +
-
+
@@ -197,7 +197,9 @@ {{ trans('admin/users/general.print_assigned') }} @else - + @endif
@endcan @@ -306,7 +308,7 @@ -
+
@@ -765,6 +767,7 @@ @endif
+
diff --git a/routes/api.php b/routes/api.php index 0eb0d834cf..35e6c92060 100644 --- a/routes/api.php +++ b/routes/api.php @@ -798,6 +798,33 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi ] )->name('api.models.restore'); + Route::post('{model_id}/files', + [ + Api\AssetModelFilesController::class, + 'store' + ] + )->name('api.models.files.store'); + + Route::get('{model_id}/files', + [ + Api\AssetModelFilesController::class, + 'list' + ] + )->name('api.models.files.index'); + + Route::get('{model_id}/file/{file_id}', + [ + Api\AssetModelFilesController::class, + 'show' + ] + )->name('api.models.files.show'); + + Route::delete('{model_id}/file/{file_id}', + [ + Api\AssetModelFilesController::class, + 'destroy' + ] + )->name('api.models.files.destroy'); }); Route::resource('models', diff --git a/tests/Feature/AssetModels/Api/AssetModelFilesTest.php b/tests/Feature/AssetModels/Api/AssetModelFilesTest.php new file mode 100644 index 0000000000..c22609c0c7 --- /dev/null +++ b/tests/Feature/AssetModels/Api/AssetModelFilesTest.php @@ -0,0 +1,120 @@ +count(1)->create(); + + // Create a superuser to run this as + $user = User::factory()->superuser()->create(); + + //Upload a file + $this->actingAsForApi($user) + ->post( + route('api.models.files.store', ['model_id' => $model[0]["id"]]), [ + 'file' => [UploadedFile::fake()->create("test.jpg", 100)] + ]) + ->assertOk(); + } + + public function testAssetModelApiListsFiles() + { + // List all files on a model + + // Create an model to work with + $model = AssetModel::factory()->count(1)->create(); + + // Create a superuser to run this as + $user = User::factory()->superuser()->create(); + + // List the files + $this->actingAsForApi($user) + ->getJson( + route('api.models.files.index', ['model_id' => $model[0]["id"]])) + ->assertOk() + ->assertJsonStructure([ + 'status', + 'messages', + 'payload', + ]); + } + + public function testAssetModelApiDownloadsFile() + { + // Download a file from a model + + // Create a model to work with + $model = AssetModel::factory()->count(1)->create(); + + // Create a superuser to run this as + $user = User::factory()->superuser()->create(); + + //Upload a file + $this->actingAsForApi($user) + ->post( + route('api.models.files.store', ['model_id' => $model[0]["id"]]), [ + 'file' => [UploadedFile::fake()->create("test.jpg", 100)] + ]) + ->assertOk(); + + // List the files to get the file ID + $result = $this->actingAsForApi($user) + ->getJson( + route('api.models.files.index', ['model_id' => $model[0]["id"]])) + ->assertOk(); + + // Get the file + $this->actingAsForApi($user) + ->get( + route('api.models.files.show', [ + 'model_id' => $model[0]["id"], + 'file_id' => $result->decodeResponseJson()->json()["payload"][0]["id"], + ])) + ->assertOk(); + } + + public function testAssetModelApiDeletesFile() + { + // Delete a file from a model + + // Create a model to work with + $model = AssetModel::factory()->count(1)->create(); + + // Create a superuser to run this as + $user = User::factory()->superuser()->create(); + + //Upload a file + $this->actingAsForApi($user) + ->post( + route('api.models.files.store', ['model_id' => $model[0]["id"]]), [ + 'file' => [UploadedFile::fake()->create("test.jpg", 100)] + ]) + ->assertOk(); + + // List the files to get the file ID + $result = $this->actingAsForApi($user) + ->getJson( + route('api.models.files.index', ['model_id' => $model[0]["id"]])) + ->assertOk(); + + // Delete the file + $this->actingAsForApi($user) + ->delete( + route('api.models.files.destroy', [ + 'model_id' => $model[0]["id"], + 'file_id' => $result->decodeResponseJson()->json()["payload"][0]["id"], + ])) + ->assertOk(); + } +}