From 7658f7c41dafb4d0709ce1ad8f26acaf94533b33 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 20:29:53 +0100 Subject: [PATCH 01/11] First shot Signed-off-by: snipe --- app/Importer/AssetImporter.php | 6 ++-- app/Importer/Importer.php | 7 ++++ app/Importer/ItemImporter.php | 38 +++++++++++++++------ app/Livewire/Importer.php | 6 ++++ resources/views/livewire/importer.blade.php | 3 +- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 4bb887bcd8..4f5bffc560 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -71,8 +71,10 @@ class AssetImporter extends ItemImporter $asset = Asset::where(['asset_tag'=> (string) $asset_tag])->first(); if ($asset) { if (! $this->updating) { - $this->log('A matching Asset '.$asset_tag.' already exists'); - return; + $exists_error = 'A matching Asset '.$asset_tag.' already exists'; + $this->log($exists_error); + $this->addErrorToBag($asset, 'asset_tag', $exists_error); + return $exists_error; } $this->log('Updating Asset'); diff --git a/app/Importer/Importer.php b/app/Importer/Importer.php index 9738723509..c2214ef37d 100644 --- a/app/Importer/Importer.php +++ b/app/Importer/Importer.php @@ -281,6 +281,13 @@ abstract class Importer } } + protected function addErrorToBag($item, $field, $error_message) + { + if ($this->errorCallback) { + call_user_func($this->errorCallback, $item, $field, [$field => [$error_message]]); + } + } + /** * Finds the user matching given data, or creates a new one if there is no match. * This is NOT used by the User Import, only for Asset/Accessory/etc where diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index ee680413d8..a00602fb7d 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -196,55 +196,70 @@ class ItemImporter extends Importer { $condition = array(); $asset_model_name = $this->findCsvMatch($row, 'asset_model'); + $asset_model_category = $this->findCsvMatch($row, 'category'); $asset_modelNumber = $this->findCsvMatch($row, 'model_number'); + // TODO: At the moment, this means we can't update the model number if the model name stays the same. if (! $this->shouldUpdateField($asset_model_name)) { return; } + if ((empty($asset_model_name)) && (! empty($asset_modelNumber))) { $asset_model_name = $asset_modelNumber; } elseif ((empty($asset_model_name)) && (empty($asset_modelNumber))) { $asset_model_name = 'Unknown'; } - if ((!empty($asset_model_name)) && (empty($asset_modelNumber))) { - $condition[] = ['name', '=', $asset_model_name]; - } elseif ((!empty($asset_model_name)) && (!empty($asset_modelNumber))) { - $condition[] = ['name', '=', $asset_model_name]; - $condition[] = ['model_number', '=', $asset_modelNumber]; + $asset_model = AssetModel::select('id'); + + if (!empty($asset_model_name)) { + $asset_model = $asset_model->where('name', '=', $asset_model_name); + + if (!empty($asset_modelNumber)) { + $asset_model = $asset_model->where('model_number', '=', $asset_modelNumber); + } } $editingModel = $this->updating; - $asset_model = AssetModel::where($condition)->first(); + $this->log('SQL: '.$asset_model->toSql()); + $asset_model = $asset_model->first(); + + $this->log('Name: '.$asset_model_name); + $this->log('Number: '.$asset_modelNumber); + $this->log('Category: '.$asset_model_category); + $this->log('Model Info: '.print_r($asset_model, true)); if ($asset_model) { + if (! $this->updating) { $this->log('A matching model already exists, returning it.'); - return $asset_model->id; } + $this->log('Matching Model found, updating it.'); $item = $this->sanitizeItemForStoring($asset_model, $editingModel); $item['name'] = $asset_model_name; $item['notes'] = $this->findCsvMatch($row, 'model_notes'); - if(!empty($asset_modelNumber)){ + if (!empty($asset_modelNumber)){ $item['model_number'] = $asset_modelNumber; } $asset_model->update($item); $asset_model->save(); $this->log('Asset Model Updated'); - + return $asset_model->id; - } - $this->log('No Matching Model, Creating a new one'); + } + + $this->log('No Matching Model, Creating a new one'); $asset_model = new AssetModel(); $item = $this->sanitizeItemForStoring($asset_model, $editingModel); $item['name'] = $asset_model_name; $item['model_number'] = $asset_modelNumber; $item['notes'] = $this->findCsvMatch($row, 'model_notes'); + $item['category_id'] = $this->createOrFetchCategory($asset_model_category); $asset_model->fill($item); $item = null; @@ -254,6 +269,7 @@ class ItemImporter extends Importer return $asset_model->id; } + $this->log('Asset Model Errors: '.$asset_model->getErrors()); $this->logError($asset_model, 'Asset Model "'.$asset_model_name.'"'); return null; diff --git a/app/Livewire/Importer.php b/app/Livewire/Importer.php index e164af36d6..32dd7912fb 100644 --- a/app/Livewire/Importer.php +++ b/app/Livewire/Importer.php @@ -374,6 +374,12 @@ class Importer extends Component 'model name', 'model', ], + 'eol_date' => + [ + 'eol', + 'eol date', + 'asset eol date', + ], 'gravatar' => [ 'gravatar', diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index ab4646041b..92dfd128ad 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -33,6 +33,7 @@ + @@ -41,8 +42,8 @@ @foreach($error_bag as $field => $error_list) + From b57283d8d14ee2516ed7f32e82fd298ba1619819 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 22:43:56 +0100 Subject: [PATCH 02/11] Removed commented code Signed-off-by: snipe --- app/Importer/ItemImporter.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index a00602fb7d..ed778f9a8c 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -262,8 +262,11 @@ class ItemImporter extends Importer $item['category_id'] = $this->createOrFetchCategory($asset_model_category); $asset_model->fill($item); + //$asset_model = AssetModel::firstOrNew($item); $item = null; + + if ($asset_model->save()) { $this->log('Asset Model '.$asset_model_name.' with model number '.$asset_modelNumber.' was created'); From 5529669884d317d8e12609eb992afdb2d3cd9d6e Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 22:44:03 +0100 Subject: [PATCH 03/11] Added tests Signed-off-by: snipe --- .../AssetModels/Api/CreateAssetModelsTest.php | 23 ++++++++++++++++++- .../AssetModels/Ui/CreateAssetModelsTest.php | 22 ++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php b/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php index a0b1c27b73..02d6bd5d66 100644 --- a/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php @@ -53,9 +53,30 @@ class CreateAssetModelsTest extends TestCase ]) ->json(); - // dd($response); $this->assertFalse(AssetModel::where('name', 'Test AssetModel')->exists()); } + public function testUniquenessAcrossModelNameAndModelNumber() + { + AssetModel::factory()->create(['name' => 'Test Model', 'model_number'=>'1234']); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->postJson(route('api.models.store'), [ + 'name' => 'Test Model', + 'model_number' => '1234', + ]) + ->assertStatus(200) + ->assertOk() + ->assertStatusMessageIs('error') + ->assertJson([ + 'messages' => [ + 'name' => ['The name must be unique across models and model number. '], + 'model_number' => ['The model number must be unique across models and name. '], + ], + ]) + ->json(); + + } + } diff --git a/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php b/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php index ef35aa5f6c..9e9a8a52dc 100644 --- a/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php @@ -51,4 +51,26 @@ class CreateAssetModelsTest extends TestCase } + public function testUniquenessAcrossModelNameAndModelNumber() + { + + AssetModel::factory()->create(['name' => 'Test Model', 'model_number'=>'1234']); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('models.create')) + ->post(route('models.store'), [ + 'name' => 'Test Model', + 'model_number' => '1234', + 'category_id' => Category::factory()->create()->id + ]) + ->assertStatus(302) + ->assertSessionHasErrors(['name','model_number']) + ->assertStatus(302) + ->assertRedirect(route('models.create')) + ->assertInvalid(['name','model_number']); + + $this->followRedirects($response)->assertSee(trans('general.error')); + + } + } From 6ad7100aa3ed200d9ea5c6dbe1f8131d9903f634 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 22:45:17 +0100 Subject: [PATCH 04/11] Removed unused use statements Signed-off-by: snipe --- app/Providers/ValidationServiceProvider.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 041aaad98e..d5b1595022 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -6,10 +6,7 @@ use App\Models\CustomField; use App\Models\Department; use App\Models\Setting; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Crypt; -use Illuminate\Support\Facades\Log; use Illuminate\Support\ServiceProvider; -use Illuminate\Validation\Rule; use Illuminate\Support\Facades\Validator; /** @@ -99,10 +96,11 @@ class ValidationServiceProvider extends ServiceProvider Validator::extend('two_column_unique_undeleted', function ($attribute, $value, $parameters, $validator) { if (count($parameters)) { $count = DB::table($parameters[0]) - ->select('id')->where($attribute, '=', $value) - ->whereNull('deleted_at') - ->where('id', '!=', $parameters[1]) - ->where($parameters[2], $parameters[3])->count(); + ->select('id')->where($attribute, '=', $value) + ->where('id', '!=', $parameters[1]) + ->where($parameters[2], $parameters[3]) + ->whereNull('deleted_at') + ->count(); return $count < 1; } From 1a4aebf805d7c993e3917117b276755d2f24a29c Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 22:45:47 +0100 Subject: [PATCH 05/11] Added TwoColumnUniqueUndeletedTrait trait Signed-off-by: snipe --- app/Models/AssetModel.php | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php index 7a66620916..3c023507db 100755 --- a/app/Models/AssetModel.php +++ b/app/Models/AssetModel.php @@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Storage; use Watson\Validating\ValidatingTrait; use \App\Presenters\AssetModelPresenter; +use App\Http\Traits\TwoColumnUniqueUndeletedTrait; /** * Model for Asset Models. Asset Models contain higher level @@ -21,21 +22,8 @@ class AssetModel extends SnipeModel { use HasFactory; use SoftDeletes; - protected $presenter = AssetModelPresenter::class; use Loggable, Requestable, Presentable; - - protected $table = 'models'; - protected $hidden = ['user_id', 'deleted_at']; - - // Declare the rules for the model validation - protected $rules = [ - 'name' => 'string|required|min:1|max:255|unique:models,name', - 'model_number' => 'string|max:255|nullable', - 'min_amt' => 'integer|min:0|nullable', - 'category_id' => 'required|integer|exists:categories,id', - 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable', - 'eol' => 'integer:min:0|max:240|nullable', - ]; + use TwoColumnUniqueUndeletedTrait; /** * Whether the model should inject its identifier to the unique @@ -44,8 +32,26 @@ class AssetModel extends SnipeModel * * @var bool */ + protected $injectUniqueIdentifier = true; use ValidatingTrait; + protected $table = 'models'; + protected $hidden = ['user_id', 'deleted_at']; + protected $presenter = AssetModelPresenter::class; + + // Declare the rules for the model validation + + + protected $rules = [ + 'name' => 'string|required|min:1|max:255|two_column_unique_undeleted:model_number', + 'model_number' => 'string|max:255|nullable|two_column_unique_undeleted:name', + 'min_amt' => 'integer|min:0|nullable', + 'category_id' => 'required|integer|exists:categories,id', + 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable', + 'eol' => 'integer:min:0|max:240|nullable', + ]; + + /** * The attributes that are mass assignable. @@ -86,6 +92,9 @@ class AssetModel extends SnipeModel 'manufacturer' => ['name'], ]; + + + /** * Establishes the model -> assets relationship * From 9b6a36c8aaf79b2f6be2b2c22c61c49b59c919aa Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 22:45:57 +0100 Subject: [PATCH 06/11] Removed unusued parameter Signed-off-by: snipe --- app/Http/Traits/TwoColumnUniqueUndeletedTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php b/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php index 4aae02bfbd..bd60254f1a 100644 --- a/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php +++ b/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php @@ -11,7 +11,7 @@ trait TwoColumnUniqueUndeletedTrait * @param string $field * @return string */ - protected function prepareTwoColumnUniqueUndeletedRule($parameters, $field) + protected function prepareTwoColumnUniqueUndeletedRule($parameters) { $column = $parameters[0]; $value = $this->{$parameters[0]}; From 559f0d2f9083314a2fc4efdfeb17621a03103eaf Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 22:53:21 +0100 Subject: [PATCH 07/11] Added string Signed-off-by: snipe --- resources/lang/en-US/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index 4144fd2f6a..7634387906 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -561,5 +561,6 @@ return [ 'remaining_var' => ':count Remaining', 'assets_in_var' => 'Assets in :name :type', 'label' => 'Label', + 'import_asset_tag_exists' => 'An asset with the asset tag :asset_tag already exists and an update was not requested. No change was made.', ]; From 3ae4a5caf02480c90a229552faed70c2db0dc92e Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 22:53:27 +0100 Subject: [PATCH 08/11] Removed debugging Signed-off-by: snipe --- app/Importer/AssetImporter.php | 2 +- app/Importer/ItemImporter.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 4f5bffc560..781a6311fe 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -71,7 +71,7 @@ class AssetImporter extends ItemImporter $asset = Asset::where(['asset_tag'=> (string) $asset_tag])->first(); if ($asset) { if (! $this->updating) { - $exists_error = 'A matching Asset '.$asset_tag.' already exists'; + $exists_error = trans('general.import_asset_tag_exists', ['asset_tag' => $asset_tag]); $this->log($exists_error); $this->addErrorToBag($asset, 'asset_tag', $exists_error); return $exists_error; diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index ed778f9a8c..540183053d 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -221,7 +221,6 @@ class ItemImporter extends Importer } $editingModel = $this->updating; - $this->log('SQL: '.$asset_model->toSql()); $asset_model = $asset_model->first(); $this->log('Name: '.$asset_model_name); From e96b9b2f4f5d1e05ef4408ccd89591e01d2ed1f3 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Aug 2024 23:04:11 +0100 Subject: [PATCH 09/11] Added test for models with same name but no model number Signed-off-by: snipe --- .../AssetModels/Api/CreateAssetModelsTest.php | 21 +++++++++++++++++++ .../AssetModels/Ui/CreateAssetModelsTest.php | 20 ++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php b/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php index 02d6bd5d66..3879436b79 100644 --- a/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php @@ -79,4 +79,25 @@ class CreateAssetModelsTest extends TestCase } + public function testUniquenessAcrossModelNameAndModelNumberWithBlankModelNumber() + { + AssetModel::factory()->create(['name' => 'Test Model']); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->postJson(route('api.models.store'), [ + 'name' => 'Test Model', + ]) + ->assertStatus(200) + ->assertOk() + ->assertStatusMessageIs('error') + ->assertJson([ + 'messages' => [ + 'name' => ['The name must be unique across models and model number. '], + 'model_number' => ['The model number must be unique across models and name. '], + ], + ]) + ->json(); + + } + } diff --git a/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php b/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php index 9e9a8a52dc..2722e8a34d 100644 --- a/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php @@ -65,7 +65,27 @@ class CreateAssetModelsTest extends TestCase ]) ->assertStatus(302) ->assertSessionHasErrors(['name','model_number']) + ->assertRedirect(route('models.create')) + ->assertInvalid(['name','model_number']); + + $this->followRedirects($response)->assertSee(trans('general.error')); + + } + + public function testUniquenessAcrossModelNameAndModelNumberWithoutModelNumber() + { + + AssetModel::factory()->create(['name' => 'Test Model', 'model_number'=> null]); + + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('models.create')) + ->post(route('models.store'), [ + 'name' => 'Test Model', + 'model_number' => null, + 'category_id' => Category::factory()->create()->id + ]) ->assertStatus(302) + ->assertSessionHasErrors(['name','model_number']) ->assertRedirect(route('models.create')) ->assertInvalid(['name','model_number']); From 318aff1ef0f29b77b4e3cfd1f308d7e752278c27 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 17 Aug 2024 00:27:44 +0100 Subject: [PATCH 10/11] Fixed behavior for null model numbers Signed-off-by: snipe --- .../Traits/TwoColumnUniqueUndeletedTrait.php | 2 ++ app/Providers/ValidationServiceProvider.php | 17 ++++++++++++----- .../AssetModels/Api/CreateAssetModelsTest.php | 5 +++-- .../AssetModels/Ui/CreateAssetModelsTest.php | 5 +++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php b/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php index bd60254f1a..0cf0edb455 100644 --- a/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php +++ b/app/Http/Traits/TwoColumnUniqueUndeletedTrait.php @@ -16,10 +16,12 @@ trait TwoColumnUniqueUndeletedTrait $column = $parameters[0]; $value = $this->{$parameters[0]}; + // This is an existing model we're updating so ignore the current ID ($this->getKey()) if ($this->exists) { return 'two_column_unique_undeleted:'.$this->table.','.$this->getKey().','.$column.','.$value; } + // This is a new record, so we can ignore the current ID return 'two_column_unique_undeleted:'.$this->table.',0,'.$column.','.$value; } } diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index d5b1595022..1f3abca8a6 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -88,18 +88,25 @@ class ValidationServiceProvider extends ServiceProvider * * $parameters[0] - the name of the first table we're looking at * $parameters[1] - the ID (this will be 0 on new creations) - * $parameters[2] - the name of the second table we're looking at + * $parameters[2] - the name of the second field we're looking at * $parameters[3] - the value that the request is passing for the second table we're * checking for uniqueness across * */ Validator::extend('two_column_unique_undeleted', function ($attribute, $value, $parameters, $validator) { + if (count($parameters)) { + $count = DB::table($parameters[0]) - ->select('id')->where($attribute, '=', $value) - ->where('id', '!=', $parameters[1]) - ->where($parameters[2], $parameters[3]) - ->whereNull('deleted_at') + ->select('id') + ->where($attribute, '=', $value) + ->where('id', '!=', $parameters[1]); + + if ($parameters[3]!='') { + $count = $count->where($parameters[2], $parameters[3]); + } + + $count = $count->whereNull('deleted_at') ->count(); return $count < 1; diff --git a/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php b/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php index 3879436b79..2928d926f6 100644 --- a/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Api/CreateAssetModelsTest.php @@ -24,7 +24,7 @@ class CreateAssetModelsTest extends TestCase $response = $this->actingAsForApi(User::factory()->superuser()->create()) ->postJson(route('api.models.store'), [ 'name' => 'Test AssetModel', - 'category_id' => Category::factory()->create()->id + 'category_id' => Category::factory()->assetLaptopCategory()->create()->id ]) ->assertOk() ->assertStatusMessageIs('success') @@ -65,6 +65,7 @@ class CreateAssetModelsTest extends TestCase ->postJson(route('api.models.store'), [ 'name' => 'Test Model', 'model_number' => '1234', + 'category_id' => Category::factory()->assetLaptopCategory()->create()->id ]) ->assertStatus(200) ->assertOk() @@ -86,6 +87,7 @@ class CreateAssetModelsTest extends TestCase $this->actingAsForApi(User::factory()->superuser()->create()) ->postJson(route('api.models.store'), [ 'name' => 'Test Model', + 'category_id' => Category::factory()->assetLaptopCategory()->create()->id ]) ->assertStatus(200) ->assertOk() @@ -93,7 +95,6 @@ class CreateAssetModelsTest extends TestCase ->assertJson([ 'messages' => [ 'name' => ['The name must be unique across models and model number. '], - 'model_number' => ['The model number must be unique across models and name. '], ], ]) ->json(); diff --git a/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php b/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php index 2722e8a34d..b0c6f65a59 100644 --- a/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Ui/CreateAssetModelsTest.php @@ -24,6 +24,7 @@ class CreateAssetModelsTest extends TestCase $this->assertFalse(AssetModel::where('name', 'Test Model')->exists()); $this->actingAs(User::factory()->superuser()->create()) + ->from(route('models.create')) ->post(route('models.store'), [ 'name' => 'Test Model', 'category_id' => Category::factory()->create()->id @@ -85,9 +86,9 @@ class CreateAssetModelsTest extends TestCase 'category_id' => Category::factory()->create()->id ]) ->assertStatus(302) - ->assertSessionHasErrors(['name','model_number']) + ->assertSessionHasErrors(['name']) ->assertRedirect(route('models.create')) - ->assertInvalid(['name','model_number']); + ->assertInvalid(['name']); $this->followRedirects($response)->assertSee(trans('general.error')); From a25efe53aab3735b46b1b02a392f7eee1ff16dd0 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 17 Aug 2024 00:35:42 +0100 Subject: [PATCH 11/11] Removed some debugging Signed-off-by: snipe --- app/Importer/ItemImporter.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 540183053d..29197ca5dc 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -223,11 +223,6 @@ class ItemImporter extends Importer $editingModel = $this->updating; $asset_model = $asset_model->first(); - $this->log('Name: '.$asset_model_name); - $this->log('Number: '.$asset_modelNumber); - $this->log('Category: '.$asset_model_category); - $this->log('Model Info: '.print_r($asset_model, true)); - if ($asset_model) { if (! $this->updating) {
{{ trans('general.item') }}Field {{ trans('general.error') }}
{{ $key }}{{ $field }} - {{ $field }}: {{ implode(", ",$error_list) }}