Skip to content

A free open source IT asset/license management system

Fixed category importer silently ignoring the alert_on_response column

TowyTowyc5bded7238a6
diff --git a/app/Importer/CategoryImporter.php b/app/Importer/CategoryImporter.php
index e859c41b82..10983fa3bb 100644
--- a/app/Importer/CategoryImporter.php
+++ b/app/Importer/CategoryImporter.php
@@ -45,7 +45,7 @@ class CategoryImporter extends ItemImporter
// Boolean flags. Present-empty maps to 0; present-with-value uses
// fetchHumanBoolean; absent leaves the DB value alone on update.
- foreach (['use_default_eula', 'require_acceptance', 'checkin_email'] as $flag) {
+ foreach (['use_default_eula', 'require_acceptance', 'checkin_email', 'alert_on_response'] as $flag) {
if ($this->csvRowHas($row, $flag)) {
$raw = $this->findCsvMatch($row, $flag);
$this->item[$flag] = ($this->fetchHumanBoolean($raw) == 1) ? 1 : 0;
diff --git a/tests/Feature/Importing/Api/ImportCategoriesTest.php b/tests/Feature/Importing/Api/ImportCategoriesTest.php
index 56f3dd51cc..261292950d 100644
--- a/tests/Feature/Importing/Api/ImportCategoriesTest.php
+++ b/tests/Feature/Importing/Api/ImportCategoriesTest.php
@@ -175,6 +175,57 @@ class ImportCategoriesTest extends ImportDataTestCase implements TestsPermission
$this->assertNull($category->eula_text);
}
+ #[Test]
+ public function import_sets_alert_on_response_flag(): void
+ {
+ $this->actingAsForApi(User::factory()->superuser()->create());
+
+ $importFileBuilder = new ImportFileBuilder([[
+ 'name' => 'Alerting Laptops',
+ 'category_type' => 'asset',
+ 'alert_on_response' => 1,
+ ]]);
+ $import = Import::factory()->categories()->create([
+ 'file_path' => $importFileBuilder->saveToImportsDirectory(),
+ ]);
+
+ $this->importFileResponse(['import' => $import->id])->assertOk();
+
+ $newCategory = Category::query()->where('name', 'Alerting Laptops')->sole();
+
+ $this->assertEquals(1, $newCategory->alert_on_response);
+ }
+
+ #[Test]
+ public function update_mode_updates_alert_on_response_flag(): void
+ {
+ $this->actingAsForApi(User::factory()->superuser()->create());
+
+ $category = Category::factory()->assetLaptopCategory()->create([
+ 'alert_on_response' => 1,
+ ])->refresh();
+
+ $this->assertEquals(1, $category->alert_on_response);
+
+ $importFileBuilder = new ImportFileBuilder([[
+ 'name' => $category->name,
+ 'category_type' => $category->category_type,
+ 'alert_on_response' => 0,
+ ]]);
+ $import = Import::factory()->categories()->create([
+ 'file_path' => $importFileBuilder->saveToImportsDirectory(),
+ ]);
+
+ $this->importFileResponse([
+ 'import' => $import->id,
+ 'import-update' => true,
+ ])->assertOk();
+
+ $category->refresh();
+
+ $this->assertEquals(0, $category->alert_on_response);
+ }
+
#[Test]
public function update_mode_preserves_fields_when_csv_column_is_absent(): void
{