A free open source IT asset/license management system
Accept multi-selects for ABM
snipe9d0ba35ec76f
diff --git a/app/SyncAdapters/Support/ConfigurableAdapter.php b/app/SyncAdapters/Support/ConfigurableAdapter.phpindex 9bed957525..058aaffd02 100644--- a/app/SyncAdapters/Support/ConfigurableAdapter.php+++ b/app/SyncAdapters/Support/ConfigurableAdapter.php@@ -202,8 +202,20 @@ abstract class ConfigurableAdapter implements HostInventoryAdapter// error worth surfacing). Adapters declaring a truly// optional credential set `required => false`.$required = $field['required'] ?? true;+ $fieldName = $slug.'_'.$field['key'];+ $type = $field['type'] ?? 'text';++ // Multiselect fields post as `name[]`, so they arrive as+ // an array (or absent when nothing is selected). Validate+ // as an array with string members, not as a string.+ if ($type === 'multiselect') {+ $rules[$fieldName] = [$required ? 'required' : 'nullable', 'array'];+ $rules[$fieldName.'.*'] = ['string'];++ continue;+ }- $rules[$slug.'_'.$field['key']] = [+ $rules[$fieldName] = [$required ? 'required' : 'nullable','string',];diff --git a/tests/Feature/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapterTest.php b/tests/Feature/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapterTest.phpindex 972db94e39..d58445dd78 100644--- a/tests/Feature/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapterTest.php+++ b/tests/Feature/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapterTest.php@@ -231,6 +231,30 @@ class AppleBusinessManagerAdapterTest extends TestCase$this->assertCount(3, $records);}+ public function test_validation_rules_accept_array_value_for_multiselect_product_family_filter()+ {+ $this->configuredAdapter();+ $instance = SyncAdapterInstance::where('slug', 'apple_business_manager')->firstOrFail();+ $adapter = new AppleBusinessManagerAdapter($instance->fresh());++ // The form posts the multiselect as `name[]`, so it arrives+ // as an array. Regression: base validationRules() used to+ // declare every credential field as 'string', which rejected+ // the array with "must be a string" on submit.+ $validator = \Illuminate\Support\Facades\Validator::make([+ 'apple_business_manager_url' => 'https://api-business.apple.com/',+ 'apple_business_manager_mode' => 'business',+ 'apple_business_manager_client_id' => 'stub-client-id',+ 'apple_business_manager_key_id' => 'stub-key-id',+ 'apple_business_manager_private_key' => $this->privateKeyPem,+ 'apple_business_manager_product_family_filter' => ['Mac', 'iPhone'],+ 'apple_business_manager_default_category_id' => \App\Models\Category::factory()->assetLaptopCategory()->create()->id,+ 'apple_business_manager_default_status_id' => Statuslabel::first()->id,+ ], $adapter->validationRules());++ $this->assertFalse($validator->fails(), 'validationRules() must accept an array for multiselect fields: '.$validator->errors()->first());+ }+public function test_saveconfig_clears_family_filter_when_nothing_selected(){$this->configuredAdapter(productFamilies: ['Mac', 'iPhone']);