From 968701b9718aea0b0fbfae66c4e09430cf9f7ef3 Mon Sep 17 00:00:00 2001 From: akemidx Date: Mon, 10 Apr 2023 17:28:19 -0400 Subject: [PATCH 001/134] starting to implant the str lower solution --- resources/views/hardware/view.blade.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index e33f681f6..2e69fc3bb 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -608,6 +608,11 @@ {{ trans('hardware/general.mfg_warranty_lookup') }} + @elseif ((strtolower($asset->model->manufacturer->name) == "hp") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"lenovoinc"))) + + {{ trans('hardware/general.mfg_warranty_lookup') }} + + @endif @endif From 71ff987e3c87baa7c3220d6b9cc8445efd4d75f8 Mon Sep 17 00:00:00 2001 From: akemidx Date: Tue, 11 Apr 2023 14:32:11 -0400 Subject: [PATCH 002/134] dynamic link w/ dynamic image --- resources/views/hardware/view.blade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 2e69fc3bb..3fcf6667d 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -608,9 +608,9 @@ {{ trans('hardware/general.mfg_warranty_lookup') }} - @elseif ((strtolower($asset->model->manufacturer->name) == "hp") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"lenovoinc"))) - - {{ trans('hardware/general.mfg_warranty_lookup') }} + @elseif (strtolower($asset->model->manufacturer->name)) + + {{ trans('hardware/general.mfg_warranty_lookup') }} @endif From 2453913080f439277edde3df291419c96b854386 Mon Sep 17 00:00:00 2001 From: akemidx Date: Tue, 11 Apr 2023 14:53:44 -0400 Subject: [PATCH 003/134] dynamic link w/ dynamic image --- resources/views/hardware/view.blade.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 3fcf6667d..39e28957d 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -596,24 +596,9 @@ {{ trans('admin/hardware/form.months') }} @if ($asset->serial && $asset->model->manufacturer) - @if ((strtolower($asset->model->manufacturer->name) == "apple") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"appleinc"))) - - + + {{ trans('hardware/general.mfg_warranty_lookup') }} - @elseif ((strtolower($asset->model->manufacturer->name) == "dell") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"dellinc"))) - - {{ trans('hardware/general.mfg_warranty_lookup') }} - - @elseif ((strtolower($asset->model->manufacturer->name) == "lenovo") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"lenovoinc"))) - - {{ trans('hardware/general.mfg_warranty_lookup') }} - - @elseif (strtolower($asset->model->manufacturer->name)) - - {{ trans('hardware/general.mfg_warranty_lookup') }} - - - @endif @endif From 0a993b2aa16c91fd0716e7807f6af15cc21b3edc Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 12 Apr 2023 18:52:21 -0400 Subject: [PATCH 004/134] added external link icon to warranty link --- resources/views/hardware/view.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 39e28957d..b5f61cf2c 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -597,7 +597,7 @@ @if ($asset->serial && $asset->model->manufacturer) - {{ trans('hardware/general.mfg_warranty_lookup') }} + {{ trans('hardware/general.mfg_warranty_lookup') }} @endif From 7534d27a033c23c388f179138953a7830b4b71c6 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 16 Apr 2023 07:46:18 -0700 Subject: [PATCH 005/134] Added CSV sample Signed-off-by: snipe --- sample_csvs/MOCK_LOCATIONS.csv | 101 +++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 sample_csvs/MOCK_LOCATIONS.csv diff --git a/sample_csvs/MOCK_LOCATIONS.csv b/sample_csvs/MOCK_LOCATIONS.csv new file mode 100644 index 000000000..25f4dfd0b --- /dev/null +++ b/sample_csvs/MOCK_LOCATIONS.csv @@ -0,0 +1,101 @@ +name,address,address2,city,state,country,zip,manager,manager username,currency +Calgary,1 Loomis Lane,,Bijelo Polje,AB,CA,T3S,Mychal Synder,msynder0,CAD +Barrhead,1 Londonderry Lane,,Pante Raja,AB,CA,T7N,Emili Sackler,esackler1,CAD +Manning,92006 Mifflin Terrace,,Cigadog Hilir,AB,CA,,,, +High River,42124 Doe Crossing Hill,,Gourcy,AB,CA,T1V,Alejandrina Cowhig,acowhig3,CAD +Stony Plain,6227 Hoffman Point,,Japeri,AB,CA,T7Z,Ashlie Capozzi,acapozzi4,CAD +High River,40530 Arkansas Terrace,,Hrazdan,AB,CA,T1V,Emmanuel Falcus,efalcus5,CAD +Viking,86706 Stuart Place,,Cabannungan Second,AB,CA,,,, +Two Hills,062 Chinook Point,,Hortolândia,AB,CA,,,, +Medicine Hat,01 John Wall Trail,,Cayungnan,AB,CA,,,, +Leduc,09675 Quincy Plaza,,Zürich,AB,CA,T9E,Robinet Christie,rchristie9,CAD +Stettler,11 Hoepker Parkway,,Ishimbay,AB,CA,,,, +Manning,44 Arizona Pass,52 Meadow Ridge Circle,Viana,AB,CA,,,, +Beaumont,24 Moose Avenue,,Hengshitang,AB,CA,,,, +Rocky Mountain House,5463 Debra Pass,,Sukaharja,AB,CA,,,, +Claresholm,273 Longview Crossing,,Rabaul,AB,CA,V2T,Anthony Kirwood,akirwoode,CAD +Athabasca,4349 Saint Paul Alley,,Cañazas,AB,CA,,,, +Bassano,2 Fisk Drive,,Mós,AB,CA,,,, +Millet,196 Ridgeway Street,,Aihua,AB,CA,,,, +Peace River,51201 Haas Street,7 Lien Park,Lengshui,AB,CA,,,, +Magrath,54 Namekagon Alley,,Mogwase,AB,CA,,,, +Taber,0300 Thompson Way,,Xia Zanggor,AB,CA,,,, +Stettler,44629 Miller Park,,Pedro García,AB,CA,G8J,Tamera Othen,tothenl,CAD +Vegreville,1 Homewood Pass,,Qingshi,AB,CA,,,, +Irricana,5510 Portage Plaza,,Yuquan,AB,CA,,,, +Rocky Mountain House,82696 Artisan Pass,,Krajan Bejagung,AB,CA,T4T,Ollie Cortnay,ocortnayo,CAD +Sundre,65 Mccormick Lane,,Douz,AB,CA,L9H,Ade Alleburton,aalleburtonp,CAD +Cochrane,12896 Little Fleur Park,,Seattle,AB,CA,T4C,Emma Arnao,earnaoq,CAD +Medicine Hat,27 Troy Parkway,,Aqsū,AB,CA,,,, +Millet,74 Surrey Point,,Kentongan,AB,CA,,,, +Pincher Creek,17 Hazelcrest Avenue,,Wieczfnia Kościelna,AB,CA,J0J,Tamiko Tillman,ttillmant,CAD +Calgary,09754 Sutherland Trail,,San Esteban,AB,CA,,,, +Peace River,6 Oriole Court,,Údlice,AB,CA,T8S,Eugine Jenckes,ejenckesv,CAD +Sherwood Park,54045 Washington Alley,,San Vicente Centenario,AB,CA,T8A,Malena Gapper,mgapperw,CAD +Taber,0 Randy Parkway,,Mirriah,AB,CA,,,, +Canmore,1 7th Street,,Shatou,AB,CA,,,, +Grande Cache,3 Annamark Trail,7 Stone Corner Drive,Pikalëvo,AB,CA,,,, +Killam,3470 Tennessee Trail,,Ust’-Kalmanka,AB,CA,,,, +Cochrane,2 Beilfuss Center,,Kuta,AB,CA,,,, +Millet,17601 Barby Avenue,045 Morningstar Avenue,Malikisi,AB,CA,,,, +Calgary,6637 Southridge Center,,Flor da Rosa,AB,CA,T3S,Isa Fogel,ifogel13,CAD +Smoky Lake,8 Hansons Parkway,0 Fair Oaks Junction,Nzega,AB,CA,,,, +Fort McMurray,55575 Fair Oaks Drive,,Rio Preto da Eva,AB,CA,,,, +Coaldale,1 American Ash Hill,,Jalqamūs,AB,CA,,,, +Hanna,905 Monument Court,,Arani,AB,CA,,,, +Canmore,990 Pankratz Alley,,Lulindi,AB,CA,T1W,Tally Gostage,tgostage18,CAD +Fox Creek,61 Continental Street,819 Loftsgordon Court,Cergy-Pontoise,AB,CA,,,, +Coaldale,0196 Mifflin Park,,Višnjićevo,AB,CA,,,, +Canmore,8 Hermina Park,,Bothaville,AB,CA,,,, +Fox Creek,92408 Dakota Avenue,,Nankou,AB,CA,E4B,Nickolai Nassau,nnassau1c,CAD +Camrose,0297 7th Pass,,Bitica,AB,CA,,,, +Magrath,2810 Harper Crossing,,Tanshi,AB,CA,,,, +Ponoka,68 Mallard Point,,Ipirá,AB,CA,,,, +Athabasca,13283 Monica Circle,,Baytīn,AB,CA,,,, +Hanna,73051 Hayes Plaza,,Vales,AB,CA,,,, +Sherwood Park,20603 Drewry Avenue,,Klenčí pod Čerchovem,AB,CA,T8A,Maurice Graal,mgraal1i,CAD +Airdrie,3883 Dexter Trail,,Courtaboeuf,AB,CA,T4B,Kissiah Parkman,kparkman1j,CAD +Cochrane,82 Fairview Place,,Kudowa-Zdrój,AB,CA,T4C,Gerti Brunini,gbrunini1k,CAD +Vulcan,69062 Bunker Hill Parkway,,Millet,AB,CA,V6M,Laurence Goulder,lgoulder1l,CAD +Drayton Valley,77163 Northwestern Trail,,Nivnice,AB,CA,,,, +Vulcan,0429 Sunnyside Circle,,Nagarakembang,AB,CA,,,, +Ponoka,8518 Clarendon Hill,,Iporã,AB,CA,,,, +High River,1 Cordelia Avenue,,Helsingborg,AB,CA,,,, +Irricana,91686 Sommers Place,,Xiaruyue,AB,CA,B3T,Liuka McGaugie,lmcgaugie1q,CAD +Vegreville,32 Fieldstone Road,,Athlone,AB,CA,,,, +Vegreville,422 Boyd Junction,,Dayapan,AB,CA,,,, +Beaverlodge,9 Mifflin Place,,Dibba Al-Hisn,AB,CA,G8A,Zea Fishwick,zfishwick1t,CAD +Vulcan,500 Shelley Way,,Killumney,AB,CA,V6M,Leela Cyphus,lcyphus1u,CAD +Beaumont,79 Sunnyside Drive,,Mengyin,AB,CA,,,, +Magrath,04 Dovetail Crossing,,Bandaragung,AB,CA,,,, +Lacombe,06352 Helena Street,,Taxisco,AB,CA,,,, +Blackfalds,71023 Gulseth Park,,Springfield,AB,CA,J5K,Mart Eaklee,meaklee1y,CAD +Nanton,19 Arkansas Crossing,,Guanzhuang,AB,CA,,,, +Killam,35 Swallow Hill,,Krylovskaya,AB,CA,,,, +Fort McMurray,801 Oriole Junction,4 Bobwhite Hill,Katav-Ivanovsk,AB,CA,,,, +Airdrie,975 Goodland Circle,,Sevilla,AB,CA,,,, +Pincher Creek,315 Kings Avenue,,Saint Ann’s Bay,AB,CA,J0J,Costanza Dormand,cdormand23,CAD +Edson,1917 Hollow Ridge Trail,,Tarusan,AB,CA,T7E,Amaleta Burnyate,aburnyate24,CAD +Claresholm,47 Toban Court,,Bélel,AB,CA,V2T,Scotti Crumley,scrumley25,CAD +Stettler,0860 Huxley Circle,,Zouérat,AB,CA,,,, +Bassano,4 Bellgrove Street,,Río Bueno,AB,CA,,,, +Jasper Park Lodge,03596 Bluejay Terrace,65418 Anthes Alley,Berlín,AB,CA,,,, +Fox Creek,503 Judy Crossing,,Novomykolayivka,AB,CA,,,, +Grande Prairie,51 Duke Way,,Quintão,AB,CA,,,, +Bassano,3309 Fuller Junction,,Ballyhaunis,AB,CA,,,, +Lethbridge,76024 John Wall Court,,Ninomiya,AB,CA,T1K,Beulah Veschambes,bveschambes2c,CAD +Coaldale,881 Washington Trail,,Xiaochi,AB,CA,,,, +Vegreville,829 7th Point,,Plaridel,AB,CA,,,, +Strathmore,6489 Saint Paul Hill,,Naj‘ Ḩammādī,AB,CA,T1P,Libbey Maulden,lmaulden2f,CAD +Lacombe,797 Valley Edge Park,,Al Farwānīyah,AB,CA,T4L,Joelle Seville,jseville2g,CAD +Fox Creek,95 1st Crossing,,Al Karmil,AB,CA,,,, +Fort McMurray,064 Bayside Street,,Liliongan,AB,CA,T9J,Maud Cheesley,mcheesley2i,CAD +Coaldale,006 Sloan Parkway,,Kosai-shi,AB,CA,,,, +Killam,67260 Caliangt Junction,,Beibei,AB,CA,,,, +Crossfield,29426 Jenifer Parkway,,Nové Město pod Smrkem,AB,CA,,,, +Claresholm,718 Anthes Plaza,3 Lillian Hill,Vallentuna,AB,CA,,,, +Cochrane,712 Mockingbird Trail,,Cát Bà,AB,CA,,,, +Coaldale,6416 Badeau Drive,,Suwaru,AB,CA,,,, +Ponoka,0884 Dayton Circle,,Cikayas,AB,CA,,,, +Spirit River,1658 Parkside Street,,Sidomakmur,AB,CA,V2G,Gill Shrieve,gshrieve2q,CAD +Bassano,1 Maple Wood Point,0516 Anzinger Junction,Pécs,AB,CA,M5G,Evvy Wildbore,ewildbore2r,CAD From bceb0b8a479516880bd6208c0b98343e11b1ccc2 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 16 Apr 2023 07:46:29 -0700 Subject: [PATCH 006/134] Allowed slightly longer zip codes Signed-off-by: snipe --- app/Models/Location.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Location.php b/app/Models/Location.php index 8cea9bda1..c3ddaa759 100755 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -30,7 +30,7 @@ class Location extends SnipeModel 'country' => 'min:2|max:255|nullable', 'address' => 'max:80|nullable', 'address2' => 'max:80|nullable', - 'zip' => 'min:3|max:10|nullable', + 'zip' => 'min:3|max:12|nullable', 'manager_id' => 'exists:users,id|nullable', 'parent_id' => 'non_circular:locations,id', ]; From 1509672463492609d5a031b800fa52d7aaf5c5a7 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 16 Apr 2023 07:46:36 -0700 Subject: [PATCH 007/134] Added location importer Signed-off-by: snipe --- app/Importer/LocationImporter.php | 91 +++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 app/Importer/LocationImporter.php diff --git a/app/Importer/LocationImporter.php b/app/Importer/LocationImporter.php new file mode 100644 index 000000000..ff4b9f945 --- /dev/null +++ b/app/Importer/LocationImporter.php @@ -0,0 +1,91 @@ +createLocationIfNotExists($row); + } + + /** + * Create a location if a duplicate does not exist. + * @todo Investigate how this should interact with Importer::createLocationIfNotExists + * + * @author A. Gianotto + * @since 6.1.0 + * @param array $row + */ + public function createLocationIfNotExists(array $row) + { + + // Pull the records from the CSV to determine their values + $this->item['name'] = $this->findCsvMatch($row, 'name'); + $this->item['address'] = $this->findCsvMatch($row, 'address'); + $this->item['address2'] = $this->findCsvMatch($row, 'address2'); + $this->item['city'] = $this->findCsvMatch($row, 'city'); + $this->item['state'] = $this->findCsvMatch($row, 'state'); + $this->item['country'] = $this->findCsvMatch($row, 'country'); + $this->item['zip'] = $this->findCsvMatch($row, 'zip'); + $this->item['currency'] = $this->findCsvMatch($row, 'currency'); + $this->item['ldap_ou'] = $this->findCsvMatch($row, 'ldap_ou'); + $this->item['manager'] = $this->findCsvMatch($row, 'manager'); + $this->item['manager_username'] = $this->findCsvMatch($row, 'manager_username'); + $this->item['user_id'] = \Auth::user()->id; + + if ($this->findCsvMatch($row, 'parent_location')) { + $this->item['parent_id'] = $this->createOrFetchLocation($this->findCsvMatch($row, 'parent_location')); + } + + + if ($manager = $this->createOrFetchUser($row, 'manager')) { + $this->item['manager_id'] = $manager->id; + } + + + + \Log::debug(print_r($this->item, true)); + $location = Location::where('name', '=', $this->findCsvMatch($row, 'name'))->first(); + + + // Location exists + if (($location) && ($location->count() > 0)) { + \Log::debug('A matching Location '.$this->item['name'].' already exists.'); + $this->log('Updating Location from CSV import'); + $location->update($this->sanitizeItemForStoring($location)); + // Location does not exist + } else { + $this->log('No matching location ('.$this->item['name'].'), creating one'); + $location = new Location(); + $location->fill($this->sanitizeItemForStoring($location)); + } + + if ($location->save()) { + $this->log('Location '.$location->name.' created from CSV import'); + return $location; + + } else { + \Log::debug($location->getErrors()); + return $location->errors; + } + + + } +} \ No newline at end of file From c149885ceb07fd2b37be5902d9f95048ad38c4a3 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 16 Apr 2023 07:47:04 -0700 Subject: [PATCH 008/134] =?UTF-8?q?Skip=20the=20magical=20user=20creation?= =?UTF-8?q?=20if=20it=E2=80=99s=20a=20location?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Importer/ItemImporter.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 7848ec6b8..f989457dc 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -60,8 +60,8 @@ class ItemImporter extends Importer $this->item['department_id'] = $this->createOrFetchDepartment($item_department); } - $item_manager_first_name = $this->findCsvMatch($row, 'manage_first_name'); - $item_manager_last_name = $this->findCsvMatch($row, 'manage_last_name'); + $item_manager_first_name = $this->findCsvMatch($row, 'manager_first_name'); + $item_manager_last_name = $this->findCsvMatch($row, 'manager_last_name'); if ($this->shouldUpdateField($item_manager_first_name)) { $this->item['manager_id'] = $this->fetchManager($item_manager_first_name, $item_manager_last_name); @@ -112,6 +112,10 @@ class ItemImporter extends Importer return $this->createOrFetchUser($row); } + if (get_class($this) != LocationImporter::class) { + return; + } + if (strtolower($this->item['checkout_class']) === 'location' && $this->findCsvMatch($row, 'checkout_location') != null ) { return Location::findOrFail($this->createOrFetchLocation($this->findCsvMatch($row, 'checkout_location'))); } From bcf9188dcdae7974c59204a0e151c311f3e723d8 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 16 Apr 2023 07:47:19 -0700 Subject: [PATCH 009/134] Made default password longer Signed-off-by: snipe --- app/Importer/Importer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Importer/Importer.php b/app/Importer/Importer.php index 1ee90b399..a9b812a6e 100644 --- a/app/Importer/Importer.php +++ b/app/Importer/Importer.php @@ -119,7 +119,7 @@ abstract class Importer } else { $this->csv = Reader::createFromString($file); } - $this->tempPassword = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 20); + $this->tempPassword = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 40); } // Cached Values for import lookups From a831a3459487b33246c59e9e264e3080537475aa Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 16 Apr 2023 07:47:26 -0700 Subject: [PATCH 010/134] New field mapping Signed-off-by: snipe --- app/Importer/Importer.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/app/Importer/Importer.php b/app/Importer/Importer.php index a9b812a6e..068006516 100644 --- a/app/Importer/Importer.php +++ b/app/Importer/Importer.php @@ -65,19 +65,22 @@ abstract class Importer 'email' => 'email', 'username' => 'username', 'address' => 'address', + 'address2' => 'address2', 'city' => 'city', 'state' => 'state', 'country' => 'country', + 'zip' => 'zip', 'jobtitle' => 'job title', 'employee_num' => 'employee number', 'phone_number' => 'phone number', 'first_name' => 'first name', 'last_name' => 'last name', 'department' => 'department', - 'manager_first_name' => 'manager first name', - 'manager_last_name' => 'manager last name', + 'manager_name' => 'manager full name', + 'manager_username' => 'manager username', 'min_amt' => 'minimum quantity', 'remote' => 'remote', + 'vip' => 'vip', ]; /** * Map of item fields->csv names @@ -198,11 +201,11 @@ abstract class Importer $val = $default; $key = $this->lookupCustomKey($key); - $this->log("Custom Key: ${key}"); + // $this->log("Custom Key: ${key}"); if (array_key_exists($key, $array)) { $val = Encoding::toUTF8(trim($array[$key])); } - $this->log("${key}: ${val}"); + //$this->log("${key}: ${val}"); return $val; } @@ -280,8 +283,9 @@ abstract class Importer * @return User Model w/ matching name * @internal param array $user_array User details parsed from csv */ - protected function createOrFetchUser($row) + protected function createOrFetchUser($row, $type = null) { + $user_array = [ 'full_name' => $this->findCsvMatch($row, 'full_name'), 'email' => $this->findCsvMatch($row, 'email'), @@ -292,25 +296,29 @@ abstract class Importer 'remote' => $this->fetchHumanBoolean(($this->findCsvMatch($row, 'remote'))), ]; + + if ($type == 'manager') { + \Log::debug('Type = manager'); + $user_array = [ + 'full_name' => $this->findCsvMatch($row, 'manager'), + 'username' => $this->findCsvMatch($row, 'manager_username'), + ]; + } + // 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'])) { - $this->log('Insufficient user data provided (Full name is required)- skipping user creation, just adding asset'); - + $this->log('Insufficient user data provided (Full name is required) - skipping user creation.'); + \Log::debug(print_r($user_array, true)); + \Log::debug(print_r($row, true)); return false; } - // Is the user actually an ID? - if ($user = $this->findUserByNumber($user_array['full_name'])) { - return $user; - } - $this->log('User does not appear to be an id with number: '.$user_array['full_name'].'. Continuing through our processes'); // Populate email if it does not exist. if (empty($user_array['email'])) { From 5a1d03c1dc54dd2eb239b983f8775e65efc96dcc Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 16 Apr 2023 07:47:42 -0700 Subject: [PATCH 011/134] Added alias maps Signed-off-by: snipe --- app/Http/Livewire/Importer.php | 61 ++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/app/Http/Livewire/Importer.php b/app/Http/Livewire/Importer.php index 784d3b298..e11dd060e 100644 --- a/app/Http/Livewire/Importer.php +++ b/app/Http/Livewire/Importer.php @@ -116,8 +116,8 @@ class Importer extends Component static $users = [ 'employee_num' => 'Employee Number', 'first_name' => 'First Name', - 'jobtitle' => 'Job Title', 'last_name' => 'Last Name', + 'jobtitle' => 'Job Title', 'phone_number' => 'Phone Number', 'manager_first_name' => 'Manager First Name', 'manager_last_name' => 'Manager Last Name', @@ -126,7 +126,24 @@ class Importer extends Component 'city' => 'City', 'state' => 'State', 'country' => 'Country', - 'vip' => 'VIP' + 'zip' => 'Zip', + 'vip' => 'VIP', + 'remote' => 'Remote', + ]; + + static $locations = [ + 'name' => 'Name', + 'address' => 'Address', + 'address2' => 'Address 2', + 'city' => 'City', + 'state' => 'State', + 'country' => 'Country', + 'zip' => 'Zip', + 'currency' => 'Currency', + 'ldap_ou' => 'LDAP OU', + 'manager_username' => 'Manager Username', + 'manager' => 'Manager', + 'parent_location' => 'Parent Location', ]; //array of "real fieldnames" to a list of aliases for that field @@ -150,6 +167,11 @@ class Importer extends Component 'QTY', 'Quantity' ], + 'zip' => + [ + 'Postal Code', + 'Post Code' + ], 'min_amt' => [ 'Min Amount', @@ -159,6 +181,31 @@ class Importer extends Component [ 'Next Audit', ], + 'address2' => + [ + 'Address 2', + 'Address2', + ], + 'ldap_ou' => + [ + 'LDAP OU', + 'OU', + ], + 'parent_location' => + [ + 'Parent', + 'Parent Location', + ], + 'manager' => + [ + 'Managed By', + 'Manager Name', + 'Manager Full Name', + ], + 'manager_username' => + [ + 'Manager Username', + ], ]; @@ -181,6 +228,9 @@ class Importer extends Component case 'user': $results = self::$general + self::$users; break; + case 'location': + $results = self::$general + self::$locations; + break; default: $results = self::$general; } @@ -252,7 +302,6 @@ class Importer extends Component $this->authorize('import'); $this->progress = -1; // '-1' means 'don't show the progressbar' $this->progress_bar_class = 'progress-bar-warning'; - \Log::debug("Hey, we are calling MOUNT (in the importer-file) !!!!!!!!"); //fcuk $this->importTypes = [ 'asset' => trans('general.assets'), 'accessory' => trans('general.accessories'), @@ -260,6 +309,7 @@ class Importer extends Component 'component' => trans('general.components'), 'license' => trans('general.licenses'), 'user' => trans('general.users'), + 'location' => trans('general.locations'), ]; $this->columnOptions[''] = $this->getColumns(''); //blank mode? I don't know what this is supposed to mean @@ -273,8 +323,7 @@ class Importer extends Component public function selectFile($id) { - \Log::debug("TOGGLE EVENT FIRED!"); - \Log::debug("The ID we are trying to find is AS FOLLOWS: ".$id); + $this->activeFile = Import::find($id); $this->field_map = null; foreach($this->activeFile->header_row as $element) { @@ -284,11 +333,9 @@ class Importer extends Component $this->field_map[] = null; // re-inject the 'nulls' if a file was imported with some 'Do Not Import' settings } } - //$this->field_map = $this->activeFile->field_map ? array_values($this->activeFile->field_map) : []; // this is wrong $this->file_id = $id; $this->import_errors = null; $this->statusText = null; - \Log::debug("The import type we are about to try and load up is gonna be this: ".$this->activeFile->import_type); } From 78ec21acc43123cf289a0034bfeeddb386410bc4 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 16 Apr 2023 07:47:49 -0700 Subject: [PATCH 012/134] Added location case Signed-off-by: snipe --- app/Http/Controllers/Api/ImportController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Http/Controllers/Api/ImportController.php b/app/Http/Controllers/Api/ImportController.php index 6f5fc05ff..914c16f8d 100644 --- a/app/Http/Controllers/Api/ImportController.php +++ b/app/Http/Controllers/Api/ImportController.php @@ -193,6 +193,9 @@ class ImportController extends Controller case 'user': $redirectTo = 'users.index'; break; + case 'location': + $redirectTo = 'locations.index'; + break; } if ($errors) { //Failure From aedfef78d39855102cba1b390894f45418df92c2 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 18 Apr 2023 13:26:23 -0700 Subject: [PATCH 013/134] Update app/Importer/LocationImporter.php Co-authored-by: Marcus Moore --- app/Importer/LocationImporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Importer/LocationImporter.php b/app/Importer/LocationImporter.php index ff4b9f945..0454d4b19 100644 --- a/app/Importer/LocationImporter.php +++ b/app/Importer/LocationImporter.php @@ -8,7 +8,7 @@ use App\Models\Location; * When we are importing users via an Asset/etc import, we use createOrFetchUser() in * App\Importer.php. [ALG] * - * Class UserImporter + * Class LocationImporter */ class LocationImporter extends ItemImporter { From 003cd372dd1e3c8710e8d23b0f89648e689fec6c Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 18 Apr 2023 16:23:07 -0700 Subject: [PATCH 014/134] New location same CSV Signed-off-by: snipe --- sample_csvs/MOCK_LOCATIONS.csv | 119 ++++++--------------------------- 1 file changed, 19 insertions(+), 100 deletions(-) diff --git a/sample_csvs/MOCK_LOCATIONS.csv b/sample_csvs/MOCK_LOCATIONS.csv index 25f4dfd0b..42285f216 100644 --- a/sample_csvs/MOCK_LOCATIONS.csv +++ b/sample_csvs/MOCK_LOCATIONS.csv @@ -1,101 +1,20 @@ name,address,address2,city,state,country,zip,manager,manager username,currency -Calgary,1 Loomis Lane,,Bijelo Polje,AB,CA,T3S,Mychal Synder,msynder0,CAD -Barrhead,1 Londonderry Lane,,Pante Raja,AB,CA,T7N,Emili Sackler,esackler1,CAD -Manning,92006 Mifflin Terrace,,Cigadog Hilir,AB,CA,,,, -High River,42124 Doe Crossing Hill,,Gourcy,AB,CA,T1V,Alejandrina Cowhig,acowhig3,CAD -Stony Plain,6227 Hoffman Point,,Japeri,AB,CA,T7Z,Ashlie Capozzi,acapozzi4,CAD -High River,40530 Arkansas Terrace,,Hrazdan,AB,CA,T1V,Emmanuel Falcus,efalcus5,CAD -Viking,86706 Stuart Place,,Cabannungan Second,AB,CA,,,, -Two Hills,062 Chinook Point,,Hortolândia,AB,CA,,,, -Medicine Hat,01 John Wall Trail,,Cayungnan,AB,CA,,,, -Leduc,09675 Quincy Plaza,,Zürich,AB,CA,T9E,Robinet Christie,rchristie9,CAD -Stettler,11 Hoepker Parkway,,Ishimbay,AB,CA,,,, -Manning,44 Arizona Pass,52 Meadow Ridge Circle,Viana,AB,CA,,,, -Beaumont,24 Moose Avenue,,Hengshitang,AB,CA,,,, -Rocky Mountain House,5463 Debra Pass,,Sukaharja,AB,CA,,,, -Claresholm,273 Longview Crossing,,Rabaul,AB,CA,V2T,Anthony Kirwood,akirwoode,CAD -Athabasca,4349 Saint Paul Alley,,Cañazas,AB,CA,,,, -Bassano,2 Fisk Drive,,Mós,AB,CA,,,, -Millet,196 Ridgeway Street,,Aihua,AB,CA,,,, -Peace River,51201 Haas Street,7 Lien Park,Lengshui,AB,CA,,,, -Magrath,54 Namekagon Alley,,Mogwase,AB,CA,,,, -Taber,0300 Thompson Way,,Xia Zanggor,AB,CA,,,, -Stettler,44629 Miller Park,,Pedro García,AB,CA,G8J,Tamera Othen,tothenl,CAD -Vegreville,1 Homewood Pass,,Qingshi,AB,CA,,,, -Irricana,5510 Portage Plaza,,Yuquan,AB,CA,,,, -Rocky Mountain House,82696 Artisan Pass,,Krajan Bejagung,AB,CA,T4T,Ollie Cortnay,ocortnayo,CAD -Sundre,65 Mccormick Lane,,Douz,AB,CA,L9H,Ade Alleburton,aalleburtonp,CAD -Cochrane,12896 Little Fleur Park,,Seattle,AB,CA,T4C,Emma Arnao,earnaoq,CAD -Medicine Hat,27 Troy Parkway,,Aqsū,AB,CA,,,, -Millet,74 Surrey Point,,Kentongan,AB,CA,,,, -Pincher Creek,17 Hazelcrest Avenue,,Wieczfnia Kościelna,AB,CA,J0J,Tamiko Tillman,ttillmant,CAD -Calgary,09754 Sutherland Trail,,San Esteban,AB,CA,,,, -Peace River,6 Oriole Court,,Údlice,AB,CA,T8S,Eugine Jenckes,ejenckesv,CAD -Sherwood Park,54045 Washington Alley,,San Vicente Centenario,AB,CA,T8A,Malena Gapper,mgapperw,CAD -Taber,0 Randy Parkway,,Mirriah,AB,CA,,,, -Canmore,1 7th Street,,Shatou,AB,CA,,,, -Grande Cache,3 Annamark Trail,7 Stone Corner Drive,Pikalëvo,AB,CA,,,, -Killam,3470 Tennessee Trail,,Ust’-Kalmanka,AB,CA,,,, -Cochrane,2 Beilfuss Center,,Kuta,AB,CA,,,, -Millet,17601 Barby Avenue,045 Morningstar Avenue,Malikisi,AB,CA,,,, -Calgary,6637 Southridge Center,,Flor da Rosa,AB,CA,T3S,Isa Fogel,ifogel13,CAD -Smoky Lake,8 Hansons Parkway,0 Fair Oaks Junction,Nzega,AB,CA,,,, -Fort McMurray,55575 Fair Oaks Drive,,Rio Preto da Eva,AB,CA,,,, -Coaldale,1 American Ash Hill,,Jalqamūs,AB,CA,,,, -Hanna,905 Monument Court,,Arani,AB,CA,,,, -Canmore,990 Pankratz Alley,,Lulindi,AB,CA,T1W,Tally Gostage,tgostage18,CAD -Fox Creek,61 Continental Street,819 Loftsgordon Court,Cergy-Pontoise,AB,CA,,,, -Coaldale,0196 Mifflin Park,,Višnjićevo,AB,CA,,,, -Canmore,8 Hermina Park,,Bothaville,AB,CA,,,, -Fox Creek,92408 Dakota Avenue,,Nankou,AB,CA,E4B,Nickolai Nassau,nnassau1c,CAD -Camrose,0297 7th Pass,,Bitica,AB,CA,,,, -Magrath,2810 Harper Crossing,,Tanshi,AB,CA,,,, -Ponoka,68 Mallard Point,,Ipirá,AB,CA,,,, -Athabasca,13283 Monica Circle,,Baytīn,AB,CA,,,, -Hanna,73051 Hayes Plaza,,Vales,AB,CA,,,, -Sherwood Park,20603 Drewry Avenue,,Klenčí pod Čerchovem,AB,CA,T8A,Maurice Graal,mgraal1i,CAD -Airdrie,3883 Dexter Trail,,Courtaboeuf,AB,CA,T4B,Kissiah Parkman,kparkman1j,CAD -Cochrane,82 Fairview Place,,Kudowa-Zdrój,AB,CA,T4C,Gerti Brunini,gbrunini1k,CAD -Vulcan,69062 Bunker Hill Parkway,,Millet,AB,CA,V6M,Laurence Goulder,lgoulder1l,CAD -Drayton Valley,77163 Northwestern Trail,,Nivnice,AB,CA,,,, -Vulcan,0429 Sunnyside Circle,,Nagarakembang,AB,CA,,,, -Ponoka,8518 Clarendon Hill,,Iporã,AB,CA,,,, -High River,1 Cordelia Avenue,,Helsingborg,AB,CA,,,, -Irricana,91686 Sommers Place,,Xiaruyue,AB,CA,B3T,Liuka McGaugie,lmcgaugie1q,CAD -Vegreville,32 Fieldstone Road,,Athlone,AB,CA,,,, -Vegreville,422 Boyd Junction,,Dayapan,AB,CA,,,, -Beaverlodge,9 Mifflin Place,,Dibba Al-Hisn,AB,CA,G8A,Zea Fishwick,zfishwick1t,CAD -Vulcan,500 Shelley Way,,Killumney,AB,CA,V6M,Leela Cyphus,lcyphus1u,CAD -Beaumont,79 Sunnyside Drive,,Mengyin,AB,CA,,,, -Magrath,04 Dovetail Crossing,,Bandaragung,AB,CA,,,, -Lacombe,06352 Helena Street,,Taxisco,AB,CA,,,, -Blackfalds,71023 Gulseth Park,,Springfield,AB,CA,J5K,Mart Eaklee,meaklee1y,CAD -Nanton,19 Arkansas Crossing,,Guanzhuang,AB,CA,,,, -Killam,35 Swallow Hill,,Krylovskaya,AB,CA,,,, -Fort McMurray,801 Oriole Junction,4 Bobwhite Hill,Katav-Ivanovsk,AB,CA,,,, -Airdrie,975 Goodland Circle,,Sevilla,AB,CA,,,, -Pincher Creek,315 Kings Avenue,,Saint Ann’s Bay,AB,CA,J0J,Costanza Dormand,cdormand23,CAD -Edson,1917 Hollow Ridge Trail,,Tarusan,AB,CA,T7E,Amaleta Burnyate,aburnyate24,CAD -Claresholm,47 Toban Court,,Bélel,AB,CA,V2T,Scotti Crumley,scrumley25,CAD -Stettler,0860 Huxley Circle,,Zouérat,AB,CA,,,, -Bassano,4 Bellgrove Street,,Río Bueno,AB,CA,,,, -Jasper Park Lodge,03596 Bluejay Terrace,65418 Anthes Alley,Berlín,AB,CA,,,, -Fox Creek,503 Judy Crossing,,Novomykolayivka,AB,CA,,,, -Grande Prairie,51 Duke Way,,Quintão,AB,CA,,,, -Bassano,3309 Fuller Junction,,Ballyhaunis,AB,CA,,,, -Lethbridge,76024 John Wall Court,,Ninomiya,AB,CA,T1K,Beulah Veschambes,bveschambes2c,CAD -Coaldale,881 Washington Trail,,Xiaochi,AB,CA,,,, -Vegreville,829 7th Point,,Plaridel,AB,CA,,,, -Strathmore,6489 Saint Paul Hill,,Naj‘ Ḩammādī,AB,CA,T1P,Libbey Maulden,lmaulden2f,CAD -Lacombe,797 Valley Edge Park,,Al Farwānīyah,AB,CA,T4L,Joelle Seville,jseville2g,CAD -Fox Creek,95 1st Crossing,,Al Karmil,AB,CA,,,, -Fort McMurray,064 Bayside Street,,Liliongan,AB,CA,T9J,Maud Cheesley,mcheesley2i,CAD -Coaldale,006 Sloan Parkway,,Kosai-shi,AB,CA,,,, -Killam,67260 Caliangt Junction,,Beibei,AB,CA,,,, -Crossfield,29426 Jenifer Parkway,,Nové Město pod Smrkem,AB,CA,,,, -Claresholm,718 Anthes Plaza,3 Lillian Hill,Vallentuna,AB,CA,,,, -Cochrane,712 Mockingbird Trail,,Cát Bà,AB,CA,,,, -Coaldale,6416 Badeau Drive,,Suwaru,AB,CA,,,, -Ponoka,0884 Dayton Circle,,Cikayas,AB,CA,,,, -Spirit River,1658 Parkside Street,,Sidomakmur,AB,CA,V2G,Gill Shrieve,gshrieve2q,CAD -Bassano,1 Maple Wood Point,0516 Anzinger Junction,Pécs,AB,CA,M5G,Evvy Wildbore,ewildbore2r,CAD +Peace River,8 Brentwood Court,,Birendranagar,AB,CA,T8S,Danika Mostyn,dmostyn0,CAD +Airdrie,14 Summer Ridge Court,306 Buhler Parkway,Poniatowa,AB,CA,T4B,Clementina Van Halen,cvan1,CAD +Calgary,3 Fieldstone Drive,,Iwanai,AB,CA,,Harwilll Heffernan,hheffernan2,CAD +High Prairie,1906 Weeping Birch Park,,Lopar,AB,CA,,Christian Pache,cpache3,CAD +Sundre,20 Summer Ridge Court,,Burujul,AB,CA,,,, +Athabasca,22 Browning Drive,424 Rieder Court,Itambacuri,AB,CA,,Alphonso Ashbridge,aashbridge5,CAD +Drayton Valley,56064 Onsgard Center,,Bahía Honda,AB,CA,,,, +Crossfield,0 Lighthouse Bay Place,,Bengras,AB,CA,,Vania Dufton,vdufton7,CAD +Beaverlodge,6 Katie Terrace,,Zhajin,AB,CA,,Papageno Baldi,pbaldi8,CAD +Grande Prairie,0 Ridgeview Parkway,,Yunxi,AB,CA,R3J,Selia Biggadike,sbiggadike9,CAD +Sherwood Park,263 Aberg Alley,,El Paso,AB,CA,,,, +Vegreville,9039 Shoshone Parkway,,Huazhou,AB,CA,,Georgy Eversfield,geversfieldb,CAD +Rocky Mountain House,8617 Arapahoe Parkway,,Paraipaba,AB,CA,,Mara Gilfoyle,mgilfoylec,CAD +Calmar,14 Green Ridge Circle,,Medveditskiy,AB,CA,S0G,Paulette Rylatt,prylattd,CAD +Rocky Mountain House,517 Bowman Terrace,,Viana,AB,CA,,Neal Gabitis,ngabitise,CAD +Pincher Creek,6054 Anzinger Hill,,Chlumec,AB,CA,,Bonnee Fowle,bfowlef,CAD +Airdrie,8 Lien Drive,,Reims,AB,CA,,Kerry Aherne,kaherneg,CAD +Camrose,4 Summit Parkway,,Xinqiao,AB,CA,T4V,Sherlock Stobbart,sstobbarth,CAD +Lamont,12 Ilene Park,,Huangtang,AB,CA,N2E,Karlotta Pinckstone,kpinckstonei,CAD From 345662c5c24fb8a15d38d569dafac6460b5d97c1 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 18 Apr 2023 16:34:10 -0700 Subject: [PATCH 015/134] Rearrange some of the user creation logic Signed-off-by: snipe --- app/Importer/Importer.php | 43 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/app/Importer/Importer.php b/app/Importer/Importer.php index 068006516..dfc808466 100644 --- a/app/Importer/Importer.php +++ b/app/Importer/Importer.php @@ -283,7 +283,7 @@ abstract class Importer * @return User Model w/ matching name * @internal param array $user_array User details parsed from csv */ - protected function createOrFetchUser($row, $type = null) + protected function createOrFetchUser($row, $type = 'user') { $user_array = [ @@ -298,22 +298,22 @@ abstract class Importer if ($type == 'manager') { - \Log::debug('Type = manager'); - $user_array = [ - 'full_name' => $this->findCsvMatch($row, 'manager'), - 'username' => $this->findCsvMatch($row, 'manager_username'), - ]; + $user_array['full_name'] = $this->findCsvMatch($row, 'manager'); + $user_array['username'] = $this->findCsvMatch($row, 'manager_username'); } - // 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; + // Maybe we're lucky and the username was passed and it already exists. + if (!empty($user_array['username'])) { + 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'])) { - $this->log('Insufficient user data provided (Full name is required) - skipping user creation.'); + + // If the full name and username is empty, bail out--we need this to extract first name (at the very least) + if ((empty($user_array['username'])) && (empty($user_array['full_name']))) { + $this->log('Insufficient user data provided (Full name or username is required) - skipping user creation.'); \Log::debug(print_r($user_array, true)); \Log::debug(print_r($row, true)); return false; @@ -325,6 +325,7 @@ abstract class Importer $user_array['email'] = User::generateEmailFromFullName($user_array['full_name']); } + // Get some fields for first name and last name based off of 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']; @@ -334,14 +335,12 @@ abstract class Importer if ($this->usernameFormat == 'email') { $user_array['username'] = $user_array['email']; } - } - // Does this ever actually fire?? - // Check for a matching user after trying to guess username. - if ($user = User::where('username', $user_array['username'])->first()) { - $this->log('User '.$user_array['username'].' already exists'); - - return $user; + // Check for a matching username one more time after trying to guess username. + if ($user = User::where('username', $user_array['username'])->first()) { + $this->log('User '.$user_array['username'].' already exists'); + return $user; + } } // If at this point we have not found a username or first name, bail out in shame. @@ -349,7 +348,7 @@ abstract class Importer return false; } - // No Luck, let's create one. + // No luck finding a user on username or first name, let's create one. $user = new User; $user->first_name = $user_array['first_name']; $user->last_name = $user_array['last_name']; @@ -364,9 +363,9 @@ abstract class Importer if ($user->save()) { $this->log('User '.$user_array['username'].' created'); - return $user; } + $this->logError($user, 'User "'.$user_array['username'].'" was not able to be created.'); return false; From fd5cb32dd9a0ce7e1868d01cde1c77cfd2746274 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 18 Apr 2023 16:34:47 -0700 Subject: [PATCH 016/134] =?UTF-8?q?Honor=20the=20=E2=80=9Cupdate=E2=80=9D?= =?UTF-8?q?=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Importer/LocationImporter.php | 43 +++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/app/Importer/LocationImporter.php b/app/Importer/LocationImporter.php index 0454d4b19..25140abe0 100644 --- a/app/Importer/LocationImporter.php +++ b/app/Importer/LocationImporter.php @@ -6,7 +6,7 @@ use App\Models\Location; /** * When we are importing users via an Asset/etc import, we use createOrFetchUser() in - * App\Importer.php. [ALG] + * Importer\Importer.php. [ALG] * * Class LocationImporter */ @@ -36,6 +36,22 @@ class LocationImporter extends ItemImporter public function createLocationIfNotExists(array $row) { + $editingLocation = false; + $location = Location::where('name', '=', $this->findCsvMatch($row, 'name'))->first(); + + if ($location) { + if (! $this->updating) { + $this->log('A matching Location '.$this->item['name'].' already exists'); + return; + } + + $this->log('Updating Location'); + $editingLocation = true; + } else { + $this->log('No Matching Location, Create a new one'); + $location = new Location; + } + // Pull the records from the CSV to determine their values $this->item['name'] = $this->findCsvMatch($row, 'name'); $this->item['address'] = $this->findCsvMatch($row, 'address'); @@ -54,31 +70,26 @@ class LocationImporter extends ItemImporter $this->item['parent_id'] = $this->createOrFetchLocation($this->findCsvMatch($row, 'parent_location')); } - - if ($manager = $this->createOrFetchUser($row, 'manager')) { - $this->item['manager_id'] = $manager->id; + if (!empty($this->item['manager'])) { + if ($manager = $this->createOrFetchUser($row, 'manager')) { + $this->item['manager_id'] = $manager->id; + } } - - + \Log::debug('Item array is: '); \Log::debug(print_r($this->item, true)); - $location = Location::where('name', '=', $this->findCsvMatch($row, 'name'))->first(); - // Location exists - if (($location) && ($location->count() > 0)) { - \Log::debug('A matching Location '.$this->item['name'].' already exists.'); - $this->log('Updating Location from CSV import'); - $location->update($this->sanitizeItemForStoring($location)); - // Location does not exist + if ($editingLocation) { + \Log::debug('Updating existing location'); + $location->update($this->sanitizeItemForUpdating($location)); } else { - $this->log('No matching location ('.$this->item['name'].'), creating one'); - $location = new Location(); + \Log::debug('Creating location'); $location->fill($this->sanitizeItemForStoring($location)); } if ($location->save()) { - $this->log('Location '.$location->name.' created from CSV import'); + $this->log('Location '.$location->name.' created or updated from CSV import'); return $location; } else { From bdd104527289e445ecf6e4a41b58355a785e648d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 19 Apr 2023 09:11:44 -0700 Subject: [PATCH 017/134] adds a checkout range for custom asset reports --- app/Http/Controllers/ReportsController.php | 3 +++ resources/views/reports/custom.blade.php | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 9764df923..5303126ca 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -641,6 +641,9 @@ class ReportsController extends Controller if (($request->filled('created_start')) && ($request->filled('created_end'))) { $assets->whereBetween('assets.created_at', [$request->input('created_start'), $request->input('created_end')]); } + if (($request->filled('checkout_date_start')) && ($request->filled('checkout_date_end'))) { + $assets->whereBetween('assets.last_checkout', [$request->input('checkout_date_start'), $request->input('checkout_date_end')]); + } if (($request->filled('expected_checkin_start')) && ($request->filled('expected_checkin_end'))) { $assets->whereBetween('assets.expected_checkin', [$request->input('expected_checkin_start'), $request->input('expected_checkin_end')]); diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php index d05978154..7dab008be 100644 --- a/resources/views/reports/custom.blade.php +++ b/resources/views/reports/custom.blade.php @@ -283,6 +283,16 @@ + +
+ +
+ + to + +
+
+
From 8a5612d1c9558c8910efce5b28576d3115cd00f5 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 19 Apr 2023 09:13:43 -0700 Subject: [PATCH 018/134] fixes comment --- resources/views/reports/custom.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php index 7dab008be..561755fe1 100644 --- a/resources/views/reports/custom.blade.php +++ b/resources/views/reports/custom.blade.php @@ -283,7 +283,7 @@
- +
From 0e1f50c226b14e3bb1a3bcda28c8cfacf6d0237f Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 19 Apr 2023 10:11:26 -0700 Subject: [PATCH 019/134] adds checkout-range to jquery --- resources/views/reports/custom.blade.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php index 561755fe1..c48f8df20 100644 --- a/resources/views/reports/custom.blade.php +++ b/resources/views/reports/custom.blade.php @@ -284,7 +284,7 @@
-
+
@@ -378,6 +378,12 @@ endDate: '0d', format: 'yyyy-mm-dd' }); + $('.checkout-range .input-daterange').datepicker({ + clearBtn: true, + todayHighlight: true, + endDate: '0d', + format: 'yyyy-mm-dd' + }); $('.expected_checkin-range .input-daterange').datepicker({ clearBtn: true, From 608c5d037f481871990bcc1c02e2bdf961dabec3 Mon Sep 17 00:00:00 2001 From: Joel Pittet Date: Wed, 19 Apr 2023 15:25:48 -0700 Subject: [PATCH 020/134] Use environment variable and default to PHP's sendmail_path Use sendmail_path in PHP instead of hardcoded path and options --- config/mail.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/mail.php b/config/mail.php index d47d182ed..f650cf538 100755 --- a/config/mail.php +++ b/config/mail.php @@ -140,8 +140,8 @@ return [ | */ - 'sendmail' => '/usr/sbin/sendmail -bs', - + 'sendmail' => env('SENDMAIL_PATH', ini_get('sendmail_path')), + 'markdown' => [ 'theme' => 'default', 'paths' => [ From bd212b31088c9269f8f20b39451bd58f243179c2 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 19 Apr 2023 16:35:06 -0700 Subject: [PATCH 021/134] adds component costs to asset view --- app/Models/Asset.php | 8 +++++++- resources/lang/en/admin/hardware/table.php | 1 + resources/views/hardware/view.blade.php | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index a5211e800..8c92f8c78 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -909,7 +909,13 @@ class Asset extends Depreciable return false; } - + public function getComponentCost(){ + $cost = 0; + foreach($this->components as $component) { + $cost += $component->pivot->assigned_qty*$component->purchase_cost; + } + return $cost; + } /** * ----------------------------------------------- diff --git a/resources/lang/en/admin/hardware/table.php b/resources/lang/en/admin/hardware/table.php index 6166ba804..10629fd22 100644 --- a/resources/lang/en/admin/hardware/table.php +++ b/resources/lang/en/admin/hardware/table.php @@ -8,6 +8,7 @@ return [ 'change' => 'In/Out', 'checkout_date' => 'Checkout Date', 'checkoutto' => 'Checked Out', + 'components_cost' => 'Total Components Cost', 'current_value' => 'Current Value', 'diff' => 'Diff', 'dl_csv' => 'Download CSV', diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index ccd3f8653..ce3a040c8 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -530,6 +530,25 @@
@endif + @if(($asset->components->count() > 0) && ($asset->purchase_cost)) +
+
+ + {{ trans('admin/hardware/table.components_cost') }} + +
+
+ @if (($asset->id) && ($asset->location)) + {{ $asset->location->currency }} + @elseif (($asset->id) && ($asset->location)) + {{ $asset->location->currency }} + @else + {{ $snipeSettings->default_currency }} + @endif + {{Helper::formatCurrencyOutput($asset->getComponentCost())}} +
+
+ @endif @if (($asset->model) && ($asset->depreciation) && ($asset->purchase_date))
From 16a5a883e532fb4eea229a2dc95c015483f78763 Mon Sep 17 00:00:00 2001 From: akemidx Date: Thu, 20 Apr 2023 16:34:25 -0400 Subject: [PATCH 022/134] new request, preparing support_url for validation --- .../Controllers/ManufacturersController.php | 5 ++- app/Http/Requests/SaveManufacturerRequest.php | 41 +++++++++++++++++++ app/Presenters/AssetPresenter.php | 14 +++++++ resources/views/hardware/view.blade.php | 2 +- 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 app/Http/Requests/SaveManufacturerRequest.php diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index 1f7d2f2c0..6e024ab8a 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Http\Requests\ImageUploadRequest; +use App\Http\Requests\SaveManufacturerRequest; use App\Models\Manufacturer; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -114,7 +115,7 @@ class ManufacturersController extends Controller * @since [v1.0] * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function update(ImageUploadRequest $request, $manufacturerId = null) + public function update(SaveManufacturerRequest $request, $manufacturerId = null) { $this->authorize('update', Manufacturer::class); // Check if the manufacturer exists @@ -123,7 +124,7 @@ class ManufacturersController extends Controller return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.does_not_exist')); } - // Save the data + // Save the data $manufacturer->name = $request->input('name'); $manufacturer->url = $request->input('url'); $manufacturer->support_url = $request->input('support_url'); diff --git a/app/Http/Requests/SaveManufacturerRequest.php b/app/Http/Requests/SaveManufacturerRequest.php new file mode 100644 index 000000000..dc96042e0 --- /dev/null +++ b/app/Http/Requests/SaveManufacturerRequest.php @@ -0,0 +1,41 @@ +getRules(); + } + + /** + * Prepare the data for validation. + * + * @return void + */ + protected function prepareForValidation() + { + $this->merge([ + 'support_url' => $this->input('support_url'), + ]); + dd($this->all()); + } +} diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index 4be0f5601..06364fe31 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -534,6 +534,20 @@ class AssetPresenter extends Presenter return false; } + /** + * Used to take user created warranty URL and dynamically fill in the needed values per asset + * @return string + */ + public function supportUrl() + { + $tempurl = $this->model->model->manufacturer->support_url; + + $tempurl = (str_replace('{LOCALE}',\App\Models\Setting::getSettings()->locale,$tempurl)); + $tempurl = (str_replace('{SERIAL}',$this->model->serial,$tempurl)); + + return $tempurl; + } + /** * Url to view this item. * @return string diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index b5f61cf2c..c4510adee 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -596,7 +596,7 @@ {{ trans('admin/hardware/form.months') }} @if ($asset->serial && $asset->model->manufacturer) - + {{ trans('hardware/general.mfg_warranty_lookup') }} @endif From 9cd278318543ca6f25556b5179fcf000cc91ed93 Mon Sep 17 00:00:00 2001 From: akemidx Date: Mon, 24 Apr 2023 20:07:21 -0400 Subject: [PATCH 023/134] Regex added for link instead --- app/Http/Controllers/ManufacturersController.php | 2 +- app/Models/Manufacturer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index 6e024ab8a..2eaabc707 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -115,7 +115,7 @@ class ManufacturersController extends Controller * @since [v1.0] * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function update(SaveManufacturerRequest $request, $manufacturerId = null) + public function update(ImageUploadRequest $request, $manufacturerId = null) { $this->authorize('update', Manufacturer::class); // Check if the manufacturer exists diff --git a/app/Models/Manufacturer.php b/app/Models/Manufacturer.php index 5f01c3c27..4d61e1042 100755 --- a/app/Models/Manufacturer.php +++ b/app/Models/Manufacturer.php @@ -23,8 +23,8 @@ class Manufacturer extends SnipeModel protected $rules = [ 'name' => 'required|min:2|max:255|unique:manufacturers,name,NULL,id,deleted_at,NULL', 'url' => 'url|nullable', - 'support_url' => 'url|nullable', 'support_email' => 'email|nullable', + 'support_url' => ['regex:/.+:\/\/.+/','nullable'], ]; protected $hidden = ['user_id']; From 07336bbc6a9f0b7000cc513970118539d526636e Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 25 Apr 2023 15:51:36 -0700 Subject: [PATCH 024/134] Added `auto_add_to_fieldsets` field Signed-off-by: snipe --- app/Models/CustomField.php | 3 ++ ..._25_085912_add_autoadd_to_customfields.php | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 database/migrations/2023_04_25_085912_add_autoadd_to_customfields.php diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index fcab5b25f..b39650e74 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -52,6 +52,7 @@ class CustomField extends Model 'name' => 'required|unique:custom_fields', 'element' => 'required|in:text,listbox,textarea,checkbox,radio', 'field_encrypted' => 'nullable|boolean', + 'auto_add_to_fieldsets' => 'boolean', ]; /** @@ -69,6 +70,8 @@ class CustomField extends Model 'show_in_email', 'is_unique', 'display_in_user_view', + 'auto_add_to_fieldsets', + ]; /** diff --git a/database/migrations/2023_04_25_085912_add_autoadd_to_customfields.php b/database/migrations/2023_04_25_085912_add_autoadd_to_customfields.php new file mode 100644 index 000000000..918bec9c5 --- /dev/null +++ b/database/migrations/2023_04_25_085912_add_autoadd_to_customfields.php @@ -0,0 +1,34 @@ +boolean('auto_add_to_fieldsets')->nullable()->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('custom_fields', function (Blueprint $table) { + if (Schema::hasColumn('custom_fields', 'auto_add_to_fieldsets')) { + $table->dropColumn('auto_add_to_fieldsets'); + } + }); + } +} From 4954b50280164f683481e3258e46977fc1abd64a Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 25 Apr 2023 15:57:46 -0700 Subject: [PATCH 025/134] Added new strings Signed-off-by: snipe --- resources/lang/en/admin/custom_fields/general.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/lang/en/admin/custom_fields/general.php b/resources/lang/en/admin/custom_fields/general.php index 9dae380aa..1923aa7f4 100644 --- a/resources/lang/en/admin/custom_fields/general.php +++ b/resources/lang/en/admin/custom_fields/general.php @@ -49,4 +49,6 @@ return [ 'unique' => 'Unique', 'display_in_user_view' => 'Allow the checked out user to view these values in their View Assigned Assets page', 'display_in_user_view_table' => 'Visible to User', + 'auto_add_to_fieldsets' => 'Automatically add this to every new fieldset', + 'add_to_preexisting_fieldsets' => 'Add to any existing fieldsets', ]; From 4e3ccb74bc1d5d9afdc49b60befa966eec96a488 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 25 Apr 2023 15:59:19 -0700 Subject: [PATCH 026/134] Fixed slightly weird padding Signed-off-by: snipe --- resources/views/custom_fields/index.blade.php | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/resources/views/custom_fields/index.blade.php b/resources/views/custom_fields/index.blade.php index 0ad851118..ba95199ea 100644 --- a/resources/views/custom_fields/index.blade.php +++ b/resources/views/custom_fields/index.blade.php @@ -178,26 +178,29 @@ + {{ Form::open(array('route' => array('fields.destroy', $field->id), 'method' => 'delete', 'style' => 'display:inline-block')) }} @can('update', $field) - - - {{ trans('button.edit') }} - + + + {{ trans('button.edit') }} + @endcan + @can('delete', $field) - {{ Form::open(array('route' => array('fields.destroy', $field->id), 'method' => 'delete', 'style' => 'display:inline-block')) }} - @if($field->fieldset->count()>0) - - @else - - @endif - {{ Form::close() }} + + @if($field->fieldset->count()>0) + + @else + + @endif + @endcan + {{ Form::close() }} From 4a063d23b96b11709ea081dfd3105fb3415ee4f3 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 25 Apr 2023 19:36:52 -0700 Subject: [PATCH 027/134] =?UTF-8?q?We=20don=E2=80=99t=20actually=20use=20t?= =?UTF-8?q?his=20test=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- tests/Unit/CustomFieldTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Unit/CustomFieldTest.php b/tests/Unit/CustomFieldTest.php index dbf96c55f..d5704d8aa 100644 --- a/tests/Unit/CustomFieldTest.php +++ b/tests/Unit/CustomFieldTest.php @@ -13,12 +13,6 @@ class CustomFieldTest extends TestCase public function testFormat() { $customfield = CustomField::factory()->make(['format' => 'IP']); - $values = [ - 'name' => $customfield->name, - 'format' => $customfield->format, - 'element' => $customfield->element, - ]; - $this->assertEquals($customfield->getAttributes()['format'], CustomField::PREDEFINED_FORMATS['IP']); //this seems undocumented... $this->assertEquals($customfield->format, 'IP'); } From 6cd3cfe1eaddf2bfd531f6bcdc6be82ecf222200 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 25 Apr 2023 20:57:03 -0700 Subject: [PATCH 028/134] Added new field to factory Signed-off-by: snipe --- database/factories/CustomFieldFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/database/factories/CustomFieldFactory.php b/database/factories/CustomFieldFactory.php index bfa41b4d8..adcca9cae 100644 --- a/database/factories/CustomFieldFactory.php +++ b/database/factories/CustomFieldFactory.php @@ -25,6 +25,7 @@ class CustomFieldFactory extends Factory 'name' => $this->faker->catchPhrase(), 'format' => '', 'element' => 'text', + 'auto_add_to_fieldsets' => '0', ]; } From 67212f9d57561892b948f97d81bea28ad55ee4f1 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 25 Apr 2023 20:59:29 -0700 Subject: [PATCH 029/134] Changed layout, added fieldsets Signed-off-by: snipe --- .../views/custom_fields/fields/edit.blade.php | 131 +++++++++++++----- 1 file changed, 95 insertions(+), 36 deletions(-) diff --git a/resources/views/custom_fields/fields/edit.blade.php b/resources/views/custom_fields/fields/edit.blade.php index 8e025e4b6..0b6a1c45c 100644 --- a/resources/views/custom_fields/fields/edit.blade.php +++ b/resources/views/custom_fields/fields/edit.blade.php @@ -1,8 +1,9 @@ -@php - use App\Models\CustomField; -@endphp +@extends('layouts/default', [ + 'helpText' => trans('admin/custom_fields/general.about_fieldsets_text'), + 'helpPosition' => 'right', + 'topSubmit' => true, +]) -@extends('layouts/default') {{-- Page title --}} @section('title') @@ -21,24 +22,28 @@ {{-- Page content --}} @section('content') -
-
- @if ($field->id) - {{ Form::open(['route' => ['fields.update', $field->id], 'class'=>'form-horizontal']) }} - {{ method_field('PUT') }} - @else - {{ Form::open(['route' => 'fields.store', 'class'=>'form-horizontal']) }} - @endif + @if ($field->id) + {{ Form::open(['route' => ['fields.update', $field->id], 'class'=>'form-horizontal']) }} + {{ method_field('PUT') }} + @else + {{ Form::open(['route' => 'fields.store', 'class'=>'form-horizontal']) }} + @endif + @csrf +
+
+ +
+
-