A free open source IT asset/license management system
Merge branch 'develop' into dev-master-integration
snipe533649f24e01
diff --cc .all-contributorsrcindex 4e9f44a082,cda222a7d9..8107ba2cd0--- a/.all-contributorsrc+++ b/.all-contributorsrc@@@ -1650,6 -1650,159 +1650,168 @@@"contributions": ["code"]+ },+ {+ "login": "jwhulette",+ "name": "Wes Hulette",+ "avatar_url": "https://avatars1.githubusercontent.com/u/4930051?v=4",+ "profile": "http://macfoo.wordpress.com/",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "patrict",+ "name": "patrict",+ "avatar_url": "https://avatars0.githubusercontent.com/u/8134591?v=4",+ "profile": "https://github.com/patrict",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "VELIKII-DIVAN",+ "name": "Dmitriy Minaev",+ "avatar_url": "https://avatars3.githubusercontent.com/u/2611616?v=4",+ "profile": "https://github.com/VELIKII-DIVAN",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "liquidhorse",+ "name": "liquidhorse",+ "avatar_url": "https://avatars0.githubusercontent.com/u/5132245?v=4",+ "profile": "https://github.com/liquidhorse",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "Seldaek",+ "name": "Jordi Boggiano",+ "avatar_url": "https://avatars1.githubusercontent.com/u/183678?v=4",+ "profile": "https://seld.be/",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "inietov",+ "name": "Ivan Nieto",+ "avatar_url": "https://avatars0.githubusercontent.com/u/653557?v=4",+ "profile": "https://github.com/inietov",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "benrubson",+ "name": "Ben RUBSON",+ "avatar_url": "https://avatars2.githubusercontent.com/u/6764151?v=4",+ "profile": "https://github.com/benrubson",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "NMathar",+ "name": "NMathar",+ "avatar_url": "https://avatars2.githubusercontent.com/u/8554558?v=4",+ "profile": "https://github.com/NMathar",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "smb",+ "name": "Steffen",+ "avatar_url": "https://avatars1.githubusercontent.com/u/139566?v=4",+ "profile": "https://github.com/smb",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "Sxderp",+ "name": "Sxderp",+ "avatar_url": "https://avatars0.githubusercontent.com/u/6609453?v=4",+ "profile": "https://github.com/Sxderp",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "fanta8897",+ "name": "fanta8897",+ "avatar_url": "https://avatars1.githubusercontent.com/u/4807843?v=4",+ "profile": "https://github.com/fanta8897",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "andreybolonin",+ "name": "Andrey Bolonin",+ "avatar_url": "https://avatars2.githubusercontent.com/u/2576509?v=4",+ "profile": "https://andreybolonin.com/phpconsulting/",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "shinayoshi",+ "name": "shinayoshi",+ "avatar_url": "https://avatars3.githubusercontent.com/u/2173307?v=4",+ "profile": "http://www.shinayoshi.net/",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "reuser",+ "name": "Hubert",+ "avatar_url": "https://avatars3.githubusercontent.com/u/2130159?v=4",+ "profile": "https://github.com/reuser",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "KeenRivals",+ "name": "KeenRivals",+ "avatar_url": "https://avatars0.githubusercontent.com/u/6865789?v=4",+ "profile": "https://brashear.me",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "omyno",+ "name": "omyno",+ "avatar_url": "https://avatars3.githubusercontent.com/u/2902513?v=4",+ "profile": "https://github.com/omyno",+ "contributions": [+ "code"+ ]+ },+ {+ "login": "jackka",+ "name": "Evgeny",+ "avatar_url": "https://avatars1.githubusercontent.com/u/6271335?v=4",+ "profile": "https://github.com/jackka",+ "contributions": [+ "code"+ ]++ },++ {++ "login": "colin-campbell",++ "name": "Colin Campbell",++ "avatar_url": "https://avatars2.githubusercontent.com/u/1169963?v=4",++ "profile": "https://digitalist.se",++ "contributions": [++ "code"++ ]}]}diff --cc README.mdindex d5d21ac588,64d61de3d9..f0a5052f8c--- a/README.md+++ b/README.md@@@ -1,5 -1,5 +1,5 @@@[](https://travis-ci.org/snipe/snipe-it) [](https://crowdin.com/project/snipe-it) [](https://gitter.im/snipe/snipe-it?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://hub.docker.com/r/snipe/snipe-it/) [](https://twitter.com/snipeitapp) [](https://www.codacy.com/app/snipe/snipe-it?utm_source=github.com&utm_medium=referral&utm_content=snipe/snipe-it&utm_campaign=Badge_Grade)- [](#contributors) [](https://www.codetriage.com/snipe/snipe-it)-[](#contributors) [](https://www.codetriage.com/snipe/snipe-it)++[](#contributors) [](https://www.codetriage.com/snipe/snipe-it)## Snipe-IT - Open Source Asset Management System@@@ -95,7 -110,10 +110,10 @@@ Thanks goes to all of these wonderful p| [<img src="https://avatars2.githubusercontent.com/u/982885?v=4" width="110px;"/><br /><sub>Martin Stub</sub>](http://martinstub.dk)<br />[π](#translation-stubben "Translation") | [<img src="https://avatars2.githubusercontent.com/u/28959963?v=4" width="110px;"/><br /><sub>Meyer Flavio</sub>](https://github.com/meyerf99)<br />[π](#translation-meyerf99 "Translation") | [<img src="https://avatars3.githubusercontent.com/u/796443?v=4" width="110px;"/><br /><sub>Micael Rodrigues</sub>](https://github.com/MicaelRodrigues)<br />[π](#translation-MicaelRodrigues "Translation") | [<img src="https://avatars0.githubusercontent.com/u/10481331?v=4" width="110px;"/><br /><sub>Mikael Rasmussen</sub>](http://rubixy.com/)<br />[π](#translation-mikaelssen "Translation") | [<img src="https://avatars1.githubusercontent.com/u/1544552?v=4" width="110px;"/><br /><sub>IxFail</sub>](https://github.com/IxFail)<br />[π](#translation-IxFail "Translation") | [<img src="https://avatars3.githubusercontent.com/u/18483118?v=4" width="110px;"/><br /><sub>Mohammed Fota</sub>](http://www.mohammedfota.com)<br />[π](#translation-MohammedFota "Translation") | [<img src="https://avatars0.githubusercontent.com/u/227080?v=4" width="110px;"/><br /><sub>Moayad Alserihi</sub>](https://github.com/omego)<br />[π](#translation-omego "Translation") || [<img src="https://avatars0.githubusercontent.com/u/1680266?v=4" width="110px;"/><br /><sub>saymd</sub>](https://github.com/saymd)<br />[π](#translation-saymd "Translation") | [<img src="https://avatars0.githubusercontent.com/u/1826808?v=4" width="110px;"/><br /><sub>Patrik Larsson</sub>](https://nordsken.se)<br />[π](#translation-pooot "Translation") | [<img src="https://avatars1.githubusercontent.com/u/20584746?v=4" width="110px;"/><br /><sub>drcryo</sub>](https://github.com/drcryo)<br />[π](#translation-drcryo "Translation") | [<img src="https://avatars1.githubusercontent.com/u/19408004?v=4" width="110px;"/><br /><sub>pawel1615</sub>](https://github.com/pawel1615)<br />[π](#translation-pawel1615 "Translation") | [<img src="https://avatars2.githubusercontent.com/u/23340468?v=4" width="110px;"/><br /><sub>bodrovics</sub>](https://github.com/bodrovics)<br />[π](#translation-bodrovics "Translation") | [<img src="https://avatars0.githubusercontent.com/u/3257654?v=4" width="110px;"/><br /><sub>priatna</sub>](https://github.com/priatna)<br />[π](#translation-priatna "Translation") | [<img src="https://avatars1.githubusercontent.com/u/5358374?v=4" width="110px;"/><br /><sub>Fan Jiang</sub>](https://amayume.net)<br />[π](#translation-ProfFan "Translation") || [<img src="https://avatars1.githubusercontent.com/u/22555451?v=4" width="110px;"/><br /><sub>ragnarcx</sub>](https://github.com/ragnarcx)<br />[π](#translation-ragnarcx "Translation") | [<img src="https://avatars2.githubusercontent.com/u/18654582?v=4" width="110px;"/><br /><sub>Rein van Haaren</sub>](http://www.reinvanhaaren.nl/)<br />[π](#translation-reinvanhaaren "Translation") | [<img src="https://avatars1.githubusercontent.com/u/386672?v=4" width="110px;"/><br /><sub>Teguh Dwicaksana</sub>](http://dheche.songolimo.net)<br />[π](#translation-dheche "Translation") | [<img src="https://avatars2.githubusercontent.com/u/2572552?v=4" width="110px;"/><br /><sub>fraccie</sub>](https://github.com/FRaccie)<br />[π](#translation-FRaccie "Translation") | [<img src="https://avatars0.githubusercontent.com/u/35182720?v=4" width="110px;"/><br /><sub>vinzruzell</sub>](https://github.com/vinzruzell)<br />[π](#translation-vinzruzell "Translation") | [<img src="https://avatars1.githubusercontent.com/u/7883603?v=4" width="110px;"/><br /><sub>Kevin Austin</sub>](http://kevinaustin.com)<br />[π](#translation-vipsystem "Translation") | [<img src="https://avatars3.githubusercontent.com/u/3861828?v=4" width="110px;"/><br /><sub>Wira Sandy</sub>](http://azuraweb.xyz)<br />[π](#translation-wira-sandy "Translation") |- | [<img src="https://avatars2.githubusercontent.com/u/8663789?v=4" width="110px;"/><br /><sub>ΠΠ»ΡΡ</sub>](https://github.com/GrayHoax)<br />[π](#translation-GrayHoax "Translation") | [<img src="https://avatars3.githubusercontent.com/u/30119111?v=4" width="110px;"/><br /><sub>GodUseVPN</sub>](https://github.com/godusevpn)<br />[π](#translation-godusevpn "Translation") | [<img src="https://avatars1.githubusercontent.com/u/745576?v=4" width="110px;"/><br /><sub>ε¨ε¨</sub>](https://github.com/EngrZhou)<br />[π](#translation-EngrZhou "Translation") | [<img src="https://avatars3.githubusercontent.com/u/1631095?v=4" width="110px;"/><br /><sub>Sam</sub>](https://github.com/takuy)<br />[π»](https://github.com/snipe/snipe-it/commits?author=takuy "Code") | [<img src="https://avatars1.githubusercontent.com/u/264022?v=4" width="110px;"/><br /><sub>Azerothian</sub>](https://www.illisian.com.au)<br />[π»](https://github.com/snipe/snipe-it/commits?author=Azerothian "Code") |+ | [<img src="https://avatars2.githubusercontent.com/u/8663789?v=4" width="110px;"/><br /><sub>ΠΠ»ΡΡ</sub>](https://github.com/GrayHoax)<br />[π](#translation-GrayHoax "Translation") | [<img src="https://avatars3.githubusercontent.com/u/30119111?v=4" width="110px;"/><br /><sub>GodUseVPN</sub>](https://github.com/godusevpn)<br />[π](#translation-godusevpn "Translation") | [<img src="https://avatars1.githubusercontent.com/u/745576?v=4" width="110px;"/><br /><sub>ε¨ε¨</sub>](https://github.com/EngrZhou)<br />[π](#translation-EngrZhou "Translation") | [<img src="https://avatars3.githubusercontent.com/u/1631095?v=4" width="110px;"/><br /><sub>Sam</sub>](https://github.com/takuy)<br />[π»](https://github.com/snipe/snipe-it/commits?author=takuy "Code") | [<img src="https://avatars1.githubusercontent.com/u/264022?v=4" width="110px;"/><br /><sub>Azerothian</sub>](https://www.illisian.com.au)<br />[π»](https://github.com/snipe/snipe-it/commits?author=Azerothian "Code") | [<img src="https://avatars1.githubusercontent.com/u/4930051?v=4" width="110px;"/><br /><sub>Wes Hulette</sub>](http://macfoo.wordpress.com/)<br />[π»](https://github.com/snipe/snipe-it/commits?author=jwhulette "Code") | [<img src="https://avatars0.githubusercontent.com/u/8134591?v=4" width="110px;"/><br /><sub>patrict</sub>](https://github.com/patrict)<br />[π»](https://github.com/snipe/snipe-it/commits?author=patrict "Code") |+ | [<img src="https://avatars3.githubusercontent.com/u/2611616?v=4" width="110px;"/><br /><sub>Dmitriy Minaev</sub>](https://github.com/VELIKII-DIVAN)<br />[π»](https://github.com/snipe/snipe-it/commits?author=VELIKII-DIVAN "Code") | [<img src="https://avatars0.githubusercontent.com/u/5132245?v=4" width="110px;"/><br /><sub>liquidhorse</sub>](https://github.com/liquidhorse)<br />[π»](https://github.com/snipe/snipe-it/commits?author=liquidhorse "Code") | [<img src="https://avatars1.githubusercontent.com/u/183678?v=4" width="110px;"/><br /><sub>Jordi Boggiano</sub>](https://seld.be/)<br />[π»](https://github.com/snipe/snipe-it/commits?author=Seldaek "Code") | [<img src="https://avatars0.githubusercontent.com/u/653557?v=4" width="110px;"/><br /><sub>Ivan Nieto</sub>](https://github.com/inietov)<br />[π»](https://github.com/snipe/snipe-it/commits?author=inietov "Code") | [<img src="https://avatars2.githubusercontent.com/u/6764151?v=4" width="110px;"/><br /><sub>Ben RUBSON</sub>](https://github.com/benrubson)<br />[π»](https://github.com/snipe/snipe-it/commits?author=benrubson "Code") | [<img src="https://avatars2.githubusercontent.com/u/8554558?v=4" width="110px;"/><br /><sub>NMathar</sub>](https://github.com/NMathar)<br />[π»](https://github.com/snipe/snipe-it/commits?author=NMathar "Code") | [<img src="https://avatars1.githubusercontent.com/u/139566?v=4" width="110px;"/><br /><sub>Steffen</sub>](https://github.com/smb)<br />[π»](https://github.com/snipe/snipe-it/commits?author=smb "Code") |+ | [<img src="https://avatars0.githubusercontent.com/u/6609453?v=4" width="110px;"/><br /><sub>Sxderp</sub>](https://github.com/Sxderp)<br />[π»](https://github.com/snipe/snipe-it/commits?author=Sxderp "Code") | [<img src="https://avatars1.githubusercontent.com/u/4807843?v=4" width="110px;"/><br /><sub>fanta8897</sub>](https://github.com/fanta8897)<br />[π»](https://github.com/snipe/snipe-it/commits?author=fanta8897 "Code") | [<img src="https://avatars2.githubusercontent.com/u/2576509?v=4" width="110px;"/><br /><sub>Andrey Bolonin</sub>](https://andreybolonin.com/phpconsulting/)<br />[π»](https://github.com/snipe/snipe-it/commits?author=andreybolonin "Code") | [<img src="https://avatars3.githubusercontent.com/u/2173307?v=4" width="110px;"/><br /><sub>shinayoshi</sub>](http://www.shinayoshi.net/)<br />[π»](https://github.com/snipe/snipe-it/commits?author=shinayoshi "Code") | [<img src="https://avatars3.githubusercontent.com/u/2130159?v=4" width="110px;"/><br /><sub>Hubert</sub>](https://github.com/reuser)<br />[π»](https://github.com/snipe/snipe-it/commits?author=reuser "Code") | [<img src="https://avatars0.githubusercontent.com/u/6865789?v=4" width="110px;"/><br /><sub>KeenRivals</sub>](https://brashear.me)<br />[π»](https://github.com/snipe/snipe-it/commits?author=KeenRivals "Code") | [<img src="https://avatars3.githubusercontent.com/u/2902513?v=4" width="110px;"/><br /><sub>omyno</sub>](https://github.com/omyno)<br />[π»](https://github.com/snipe/snipe-it/commits?author=omyno "Code") |-| [<img src="https://avatars1.githubusercontent.com/u/6271335?v=4" width="110px;"/><br /><sub>Evgeny</sub>](https://github.com/jackka)<br />[π»](https://github.com/snipe/snipe-it/commits?author=jackka "Code") |++| [<img src="https://avatars1.githubusercontent.com/u/6271335?v=4" width="110px;"/><br /><sub>Evgeny</sub>](https://github.com/jackka)<br />[π»](https://github.com/snipe/snipe-it/commits?author=jackka "Code") | [<img src="https://avatars2.githubusercontent.com/u/1169963?v=4" width="110px;"/><br /><sub>Colin Campbell</sub>](https://digitalist.se)<br />[π»](https://github.com/snipe/snipe-it/commits?author=colin-campbell "Code") |<!-- ALL-CONTRIBUTORS-LIST:END -->This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!diff --cc app/Http/Controllers/Api/AssetsController.phpindex 6dfe6b9910,60341b0547..8cae0e3dbf--- a/app/Http/Controllers/Api/AssetsController.php+++ b/app/Http/Controllers/Api/AssetsController.php@@@ -125,12 -126,12 +126,12 @@@ class AssetsController extends Controll$assets->where('assets.supplier_id', '=', $request->input('supplier_id'));}- if (($request->has('assigned_to')) && ($request->has('assigned_type'))) {+ if (($request->filled('assigned_to')) && ($request->filled('assigned_type'))) {$assets->where('assets.assigned_to', '=', $request->input('assigned_to'))- ->where('assets.assigned_type', '=', $request->input('assigned_type'));+ ->where('assets.assigned_type', '=', $request->input('assigned_type'));}- if ($request->has('company_id')) {+ if ($request->filled('company_id')) {$assets->where('assets.company_id', '=', $request->input('company_id'));}@@@ -354,9 -362,9 +362,9 @@@'assets.assigned_to','assets.assigned_type','assets.status_id'- ])->with('model', 'assetstatus', 'assignedTo')->NotArchived(),'company_id', 'assets');- ])->with('model', 'assetstatus', 'assignedTo')->NotArchived(), 'company_id', 'assets');++ ])->with('model', 'assetstatus', 'assignedTo')->NotArchived());- if ($request->has('assetStatusType') && $request->input('assetStatusType') === 'RTD') {+ if ($request->filled('assetStatusType') && $request->input('assetStatusType') === 'RTD') {$assets = $assets->RTD();}diff --cc app/Http/Controllers/Api/UsersController.phpindex 5bd825d957,ddcbb289a3..35676c584c--- a/app/Http/Controllers/Api/UsersController.php+++ b/app/Http/Controllers/Api/UsersController.php@@@ -199,8 -201,9 +201,9 @@@ class UsersController extends Controlle$tmp_pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);$user->password = bcrypt($request->get('password', $tmp_pass));+if ($user->save()) {- if ($request->filled('groups')) {+ if ($request->has('groups')) {$user->groups()->sync($request->input('groups'));} else {$user->groups()->sync(array());diff --cc app/Http/Controllers/Assets/AssetsController.phpindex e143a8a184,3309044c9b..acf2596034--- a/app/Http/Controllers/Assets/AssetsController.php+++ b/app/Http/Controllers/Assets/AssetsController.php@@@ -114,112 -113,99 +113,102 @@@ class AssetsController extends Controll{$this->authorize(Asset::class);+ // Handle asset tags - there could be one, or potentially many.+ // This is only necessary on create, not update, since bulk editing is handled+ // differently+ $asset_tags = $request->input('asset_tags');- $asset = new Asset();- $asset->model()->associate(AssetModel::find($request->input('model_id')));-- $asset->name = $request->input('name');- $asset->serial = $request->input('serial');- $asset->company_id = Company::getIdForCurrentUser($request->input('company_id'));- $asset->model_id = $request->input('model_id');- $asset->order_number = $request->input('order_number');- $asset->notes = $request->input('notes');- $asset->asset_tag = $request->input('asset_tag');- $asset->user_id = Auth::id();- $asset->archived = '0';- $asset->physical = '1';- $asset->depreciate = '0';- $asset->status_id = request('status_id', 0);- $asset->warranty_months = request('warranty_months', null);- $asset->purchase_cost = Helper::ParseFloat($request->get('purchase_cost'));- $asset->purchase_date = request('purchase_date', null);- $asset->assigned_to = request('assigned_to', null);- $asset->supplier_id = request('supplier_id', 0);- $asset->requestable = request('requestable', 0);- $asset->rtd_location_id = request('rtd_location_id', null);+ $success = false;+ $serials = $request->input('serials');- if ($asset->assigned_to=='') {- $asset->location_id = $request->input('rtd_location_id', null);- }+ for ($a = 1; $a <= count($asset_tags); $a++) {++ $asset = new Asset();+ $asset->model()->associate(AssetModel::find($request->input('model_id')));+ $asset->name = $request->input('name');+ // Check for a corresponding serial+ if (($serials) && (array_key_exists($a, $serials))) {+ $asset->serial = $serials[$a];+ }+ $asset->company_id = Company::getIdForCurrentUser($request->input('company_id'));+ $asset->model_id = $request->input('model_id');+ $asset->order_number = $request->input('order_number');+ $asset->notes = $request->input('notes');+ $asset->user_id = Auth::id();+ $asset->archived = '0';+ $asset->physical = '1';+ $asset->depreciate = '0';+ $asset->status_id = request('status_id', 0);+ $asset->warranty_months = request('warranty_months', null);+ $asset->purchase_cost = Helper::ParseFloat($request->get('purchase_cost'));+ $asset->purchase_date = request('purchase_date', null);+ $asset->assigned_to = request('assigned_to', null);+ $asset->supplier_id = request('supplier_id', 0);+ $asset->requestable = request('requestable', 0);+ $asset->rtd_location_id = request('rtd_location_id', null);++ if ($asset->assigned_to=='') {+ $asset->location_id = $request->input('rtd_location_id', null);+ }+ // Create the image (if one was chosen.)- if ($request->has('image')) {++ if ($request->hasFile('image')) {+ $image = $request->input('image');- // After modification, the image is prefixed by mime info like the following:- // data:image/jpeg;base64,; This causes the image library to be unhappy, so we need to remove it.- $header = explode(';', $image, 2)[0];- // Grab the image type from the header while we're at it.- $extension = substr($header, strpos($header, '/')+1);- // Start reading the image after the first comma, postceding the base64.- $image = substr($image, strpos($image, ',')+1);-- $file_name = str_random(25).".".$extension;- $directory= public_path('uploads/assets/');- // Check if the uploads directory exists. If not, try to create it.- if (!file_exists($directory)) {- mkdir($directory, 0755, true);- }- $path = public_path('uploads/assets/'.$file_name);- try {- Image::make($image)->resize(500, 500, function ($constraint) {- $constraint->aspectRatio();- $constraint->upsize();- })->save($path);- $asset->image = $file_name;- } catch (\Exception $e) {- \Input::flash();- $messageBag = new \Illuminate\Support\MessageBag();- $messageBag->add('image', $e->getMessage());- \Session()->flash('errors', \Session::get('errors', new \Illuminate\Support\ViewErrorBag)- ->put('default', $messageBag));- return response()->json(['image' => $e->getMessage()], 422);- }- }+ $asset->asset_tag = $asset_tags[$a];+ $asset = $request->handleImages($asset);- // Update custom fields in the database.- // Validation for these fields is handled through the AssetRequest form request- $model = AssetModel::find($request->get('model_id'));+ // Update custom fields in the database.+ // Validation for these fields is handled through the AssetRequest form request+ $model = AssetModel::find($request->get('model_id'));- if ($model->fieldset) {- foreach ($model->fieldset->fields as $field) {- if ($field->field_encrypted=='1') {- if (Gate::allows('admin')) {- $asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));+ if (($model) && ($model->fieldset)) {+ foreach ($model->fieldset->fields as $field) {+ if ($field->field_encrypted=='1') {+ if (Gate::allows('admin')) {+ $asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));+ }+ } else {+ $asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());}- } else {- $asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());}}- }- // Was the asset created?- if ($asset->save()) {+ // Validate the asset before saving+ if ($asset->isValid() && $asset->save()) {++ if (request('assigned_user')) {+ $target = User::find(request('assigned_user'));+ $location = $target->location_id;+ } elseif (request('assigned_asset')) {+ $target = Asset::find(request('assigned_asset'));+ $location = $target->location_id;+ } elseif (request('assigned_location')) {+ $target = Location::find(request('assigned_location'));+ $location = $target->id;+ }++ if (isset($target)) {+ $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e($request->get('name')), $location);+ }+ $success = true;- if (request('assigned_user')) {- $target = User::find(request('assigned_user'));- $location = $target->location_id;- } elseif (request('assigned_asset')) {- $target = Asset::find(request('assigned_asset'));- $location = $target->location_id;- } elseif (request('assigned_location')) {- $target = Location::find(request('assigned_location'));- $location = $target->id;- }- if (isset($target)) {- $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e($request->get('name')), $location);}++ }++ if ($success) {// Redirect to the asset listing page- \Session::flash('success', trans('admin/hardware/message.create.success'));- return response()->json(['redirect_url' => route('hardware.index')]);+ return redirect()->route('hardware.index')+ ->with('success', trans('admin/hardware/message.create.success'));}- \Input::flash();- \Session::flash('errors', $asset->getErrors());- return response()->json(['errors' => $asset->getErrors()], 500);++ return redirect()->back()->withInput()->withErrors($asset->getErrors());+}/**diff --cc app/Importer/Importer.phpindex b5aafd4bce,ca3b7593f4..dc517efe92--- a/app/Importer/Importer.php+++ b/app/Importer/Importer.php@@@ -267,12 -271,14 +275,17 @@@ abstract class Importe$user_array = ['full_name' => $this->findCsvMatch($row, "full_name"),'email' => $this->findCsvMatch($row, "email"),- 'username' => $this->findCsvMatch($row, "username")+ 'manager_id'=> '',+ 'department_id' => '',+ 'username' => $this->findCsvMatch($row, "username"),+ 'activated' => $this->fetchHumanBoolean($this->findCsvMatch($row, 'activated')),];- \Log::debug('Importer.php Activated: '.$this->findCsvMatch($row, 'activated'));++ // Maybe we're lucky and the user already exists.+ if($user = User::where('username', $user_array['username'])->first()) {+ $this->log('User '.$user_array['username'].' already exists');+ return $user;+ }// If the full name is empty, bail out--we need this to extract first name (at the very least)if(empty($user_array['full_name'])) {@@@ -291,10 -297,9 +304,10 @@@$user_array['email'] = User::generateEmailFromFullName($user_array['full_name']);}- $user_formatted_array = User::generateFormattedNameFromFullName(Setting::getSettings()->username_format, $user_array['full_name']);+ $user_formatted_array = User::generateFormattedNameFromFullName($user_array['full_name'], Setting::getSettings()->username_format);$user_array['first_name'] = $user_formatted_array['first_name'];$user_array['last_name'] = $user_formatted_array['last_name'];+if (empty($user_array['username'])) {$user_array['username'] = $user_formatted_array['username'];if ($this->usernameFormat =='email') {@@@ -316,19 -320,16 +329,19 @@@// No Luck, let's create one.$user = new User;- $user->first_name = $user_array['first_name'];- $user->last_name = $user_array['last_name'];- $user->username = $user_array['username'];- $user->email = $user_array['email'];- $user->manager_id = (isset($user_array['manager_id']) ? $user_array['manager_id'] : null);- $user->department_id = (isset($user_array['department_id']) ? $user_array['department_id']: null);- $user->activated = $user_array['activated'];- $user->password = $this->tempPassword;+ $user->first_name = $user_array['first_name'];+ $user->last_name = $user_array['last_name'];+ $user->username = $user_array['username'];+ $user->email = $user_array['email'];+ $user->manager_id = $user_array['manager_id'] ?? null;+ $user->department_id = $user_array['department_id'] ?? null;+ $user->activated = 1;+ $user->password = $this->tempPassword;+ \Log::debug('Creating a user with the following attributes: '.print_r($user_array, true));+if ($user->save()) {+ \Log::debug('Importer.php Name: '.$user->first_name.' '.$user->last_name.' ('.$user->username.')');$this->log('User '.$user_array['username'].' created');return $user;}diff --cc app/Importer/ItemImporter.phpindex 224a612e7b,fef26e4d4b..4895545e22--- a/app/Importer/ItemImporter.php+++ b/app/Importer/ItemImporter.php@@@ -292,8 -292,27 +292,29 @@@ class ItemImporter extends Importereturn null;}+++ /**+ * Fetch an existing manager+ *+ * @author A. Gianotto+ * @since 4.6.5+ * @param $user_manager string+ * @return int id of company created/found+ */+ public function fetchManager($user_manager_first_name, $user_manager_last_name)+ {+ $manager = User::where('first_name', '=', $user_manager_first_name)+ ->where('last_name', '=', $user_manager_last_name)->first();+ if ($manager) {+ $this->log('A matching Manager ' . $user_manager_first_name . ' '. $user_manager_last_name . ' already exists');+ return $manager->id;+ }+ $this->log('No matching Manager ' . $user_manager_first_name . ' '. $user_manager_last_name . ' found. If their user account is being created through this import, you should re-process this file again. ');+ return null;+ }++/*** Fetch the existing status label or create new if it doesn't exist.*diff --cc app/Importer/UserImporter.phpindex bd5bbc1d5b,e9be1946fd..1bf4be207b--- a/app/Importer/UserImporter.php+++ b/app/Importer/UserImporter.php@@@ -47,16 -38,15 +48,19 @@@ class UserImporter extends ItemImporte$this->item['email'] = $this->findCsvMatch($row, 'email');$this->item['phone'] = $this->findCsvMatch($row, 'phone_number');$this->item['jobtitle'] = $this->findCsvMatch($row, 'jobtitle');- $this->item['activated'] = $this->fetchHumanBoolean($this->findCsvMatch($row, 'activated'));+ $this->item['activated'] = ($this->fetchHumanBoolean($this->findCsvMatch($row, 'activated')) == 1) ? '1' : 0;++ \Log::debug('UserImporter.php Activated: '.$this->findCsvMatch($row, 'activated'));+ \Log::debug('UserImporter.php Activated fetchHumanBoolean: '. $this->fetchHumanBoolean($this->findCsvMatch($row, 'activated')));+$this->item['employee_num'] = $this->findCsvMatch($row, 'employee_num');- $this->item['department_id'] = $this->createOrFetchDepartment($this->findCsvMatch($row, 'department')) ? $this->createOrFetchDepartment($this->findCsvMatch($row, 'department')) : null;- $this->item['manager_id'] = $this->fetchManager($this->findCsvMatch($row, 'manager_first_name'), $this->findCsvMatch($row, 'manager_last_name')) ? $this->fetchManager($this->findCsvMatch($row, 'manager_first_name'), $this->findCsvMatch($row, 'manager_last_name')) : null;-+ $this->item['department_id'] = $this->createOrFetchDepartment($this->findCsvMatch($row, 'department'));+ $this->item['manager_id'] = $this->fetchManager($this->findCsvMatch($row, 'manager_first_name'), $this->findCsvMatch($row, 'manager_last_name'));+ $user_department = $this->findCsvMatch($row, 'department');+ if ($this->shouldUpdateField($user_department)) {+ $this->item["department_id"] = $this->createOrFetchDepartment($user_department);+ }$user = User::where('username', $this->item['username'])->first();if ($user) {if (!$this->updating) {@@@ -67,24 -56,20 +71,25 @@@$this->log('Updating User');$user->update($this->sanitizeItemForUpdating($user));$user->save();+ // \Log::debug('UserImporter.php Updated User ' . print_r($user, true));return;}+++// This needs to be applied after the update logic, otherwise we'll overwrite user passwords// Issue #5408- $this->item['password'] = $this->tempPassword;+ $this->item['password'] = bcrypt($this->tempPassword);$this->log("No matching user, creating one");$user = new User();$user->fill($this->sanitizeItemForStoring($user));if ($user->save()) {+ // $user->logCreate('Imported using CSV Importer');$this->log("User " . $this->item["name"] . ' was created');- if($user->email) {++ if(($user->email) && ($user->activated=='1')) {$data = ['email' => $user->email,'username' => $user->username,diff --cc app/Importer/import_mappings.mdindex b65a655b21,415afb671e..0642241525--- a/app/Importer/import_mappings.md+++ b/app/Importer/import_mappings.md@@@ -4,17 -4,16 +4,16 @@@| asset tag | asset_tag | Asset || category | category | All || company | company | All |+| department_id | | User ? All || item name | item_name | All || image | image | Asset |- | email | | |+ | department_id | | User ? All || expiration date | expiration_date | License || location | location | All || notes | notes | All || licensed to email | license_email | License || licensed to name | license_name | License || maintained | maintained | License |- | manager_id | | User |-| manager_id | | User || manufacturer | manufacturer | All || model name | asset_model | Asset || model number | model_number | Asset |@@@ -33,5 -32,5 +32,6 @@@| warranty months | warranty_months | Asset || User Related Fields | assigned_to | Asset || name | | |+ | email | | || username | | |+diff --cc app/Models/Location.phpindex d0cbec3fdc,3dec481ddb..91e209075e--- a/app/Models/Location.php+++ b/app/Models/Location.php@@@ -56,8 -56,8 +56,9 @@@ class Location extends SnipeMode'country','zip','ldap_ou',+ 'manager_id','currency',+ 'manager_id','image',];protected $hidden = ['user_id'];diff --cc app/Models/Loggable.phpindex f2a96ca99b,f3914d9db5..65236785c3--- a/app/Models/Loggable.php+++ b/app/Models/Loggable.php@@@ -38,11 -31,9 +31,10 @@@ trait Loggabl*/public function logCheckout($note, $target /* What are we checking out to? */){- $settings = Setting::getSettings();$log = new Actionlog;$log = $this->determineLogItemType($log);- $log->user_id = Auth::user()->id;+ if(Auth::user())+ $log->user_id = Auth::user()->id;if (!isset($target)) {throw new Exception('All checkout logs require a target');diff --cc config/trustedproxy.phpindex fbfdcfbcc4,e94bd278cd..bde40fc7e8--- a/config/trustedproxy.php+++ b/config/trustedproxy.php@@@ -21,54 -12,34 +21,43 @@@ return* within TrustedProxy to trust any proxy* that connects directly to your server,* a requirement when you cannot know the address- * of your proxy (e.g. if using Rackspace balancers).+ * of your proxy (e.g. if using ELB or similar).*+ * The "**" character is syntactic sugar within+ * TrustedProxy to trust not just any proxy that+ * connects directly to your server, but also+ * proxies that connect to those proxies, and all+ * the way back until you reach the original source+ * IP. It will mean that $request->getClientIp()+ * always gets the originating client IP, no matter+ * how many proxies that client's request has+ * subsequently passed through.*/- 'proxies' => env('APP_TRUSTED_PROXIES') !== null ?- explode(',', env('APP_TRUSTED_PROXIES')) : '*',+ 'proxies' => null, // [<ip addresses>,], '*'/*- * Or, to trust all proxies that connect- * directly to your server, uncomment this:+ * To trust one or more specific proxies that connect+ * directly to your server, use an array of IP addresses:*/- // 'proxies' => '*',+ # 'proxies' => ['192.168.1.1'],/*- * Or, to trust ALL proxies, including those that- * are in a chain of forwarding, uncomment this:- */- // 'proxies' => '**',+ * Or, to trust all proxies that connect+ * directly to your server, use a "*"+ */+ # 'proxies' => '*',/*- * Default Header Names+ * Which headers to use to detect proxy related data (For, Host, Proto, Port)*- * Change these if the proxy does- * not send the default header names.+ * Options include:*- * Note that headers such as X-Forwarded-For- * are transformed to HTTP_X_FORWARDED_FOR format.+ * - Illuminate\Http\Request::HEADER_X_FORWARDED_ALL (use all x-forwarded-* headers to establish trust)+ * - Illuminate\Http\Request::HEADER_FORWARDED (use the FORWARDED header to establish trust)*- * The following are Symfony defaults, found in- * \Symfony\Component\HttpFoundation\Request::$trustedHeaders- *- * We may also want to add something like:- * \Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_SCHEME',+ * @link https://symfony.com/doc/current/deployment/proxies.html*/- // These are defaults already set in the config:- 'headers' => [- (defined('Illuminate\Http\Request::HEADER_FORWARDED') ? Illuminate\Http\Request::HEADER_FORWARDED : 'forwarded') => 'FORWARDED',- \Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',- \Illuminate\Http\Request::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST',- \Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO',- \Illuminate\Http\Request::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT',- ]+ 'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,++];diff --cc resources/views/users/view.blade.phpindex 0a79aa27f1,37c4580476..deca467ccf--- a/resources/views/users/view.blade.php+++ b/resources/views/users/view.blade.php@@@ -249,33 -245,31 +245,30 @@@<div class="col-md-12" style="padding-top: 5px;"><a href="{{ route('users.print', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-default hidden-print">{{ trans('admin/users/general.print_assigned') }}</a></div>- @endcan-- @can('delete', $user)- @if ($user->deleted_at=='')- <div class="col-md-12" style="padding-top: 5px;">- <form action="{{route('users.destroy',$user->id)}}" method="POST">- {{csrf_field()}}- {{ method_field("DELETE")}}- <button style="width: 100%;" class="btn btn-sm btn-warning hidden-print">{{ trans('button.delete')}}</button>- </form>- </div>- <div class="col-md-12" style="padding-top: 5px;">- <form action="{{ route('users/bulkedit') }}" method="POST">- <!-- CSRF Token -->- <input type="hidden" name="_token" value="{{ csrf_token() }}" />- <input type="hidden" name="ids[{{ $user->id }}]" value="{{ $user->id }}" />- <button style="width: 100%;" class="btn btn-sm btn-danger hidden-print">{{ trans('button.checkin_and_delete') }}</button>- </form>- </div>- @else- <div class="col-md-12" style="padding-top: 5px;">- <a href="{{ route('restore/user', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-warning hidden-print">{{ trans('button.restore') }}</a>- </div>- @endif- @endcan-- @endcan+ @can('delete', $user)+ @if ($user->deleted_at=='')+ <div class="col-md-12" style="padding-top: 5px;">+ <form action="{{route('users.destroy',$user->id)}}" method="POST">+ {{csrf_field()}}+ {{ method_field("DELETE")}}+ <button style="width: 100%;" class="btn btn-sm btn-warning hidden-print">{{ trans('button.delete')}}</button>+ </form>+ </div>+ <div class="col-md-12" style="padding-top: 5px;">+ <form action="{{ route('users/bulkedit') }}" method="POST">+ <!-- CSRF Token -->+ <input type="hidden" name="_token" value="{{ csrf_token() }}" />+ <input type="hidden" name="ids[{{ $user->id }}]" value="{{ $user->id }}" />+ <button style="width: 100%;" class="btn btn-sm btn-danger hidden-print">{{ trans('button.checkin_and_delete') }}</button>+ </form>+ </div>+ @else+ <div class="col-md-12" style="padding-top: 5px;">+ <a href="{{ route('restore/user', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-warning hidden-print">{{ trans('button.restore') }}</a>+ </div>+ @endif+ @endcan</div><!-- End button column --></div> <!--/.row-->