Skip to content

A free open source IT asset/license management system

Quick tweak to advanced search aliases

snipea84533b4f4b7
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index e04db03175..3d68d2136a 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -228,6 +228,8 @@ class Asset extends Depreciable
protected $searchableRelationAliases = [
'status_label' => 'status',
'assigned_to' => 'assignedTo',
+ 'model_number' => 'model',
+ 'rtd_location' => 'defaultLoc',
];
protected static function booted(): void
diff --git a/database/migrations/2026_05_05_125206_add_unique_index_to_nonces.php b/database/migrations/2026_05_05_125206_add_unique_index_to_nonces.php
index 0880d53871..25f5a5d1d8 100644
--- a/database/migrations/2026_05_05_125206_add_unique_index_to_nonces.php
+++ b/database/migrations/2026_05_05_125206_add_unique_index_to_nonces.php
@@ -2,6 +2,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
@@ -11,6 +12,8 @@ return new class extends Migration
*/
public function up(): void
{
+
+ Artisan::call("saml:clear_expired_nonces");
Schema::table('saml_nonces', function (Blueprint $table) {
$table->dropIndex(['nonce']);
$table->unique('nonce');
diff --git a/tests/Feature/Search/SearchableTraitTest.php b/tests/Feature/Search/SearchableTraitTest.php
index d5bca4973b..8c0183268d 100644
--- a/tests/Feature/Search/SearchableTraitTest.php
+++ b/tests/Feature/Search/SearchableTraitTest.php
@@ -1145,4 +1145,56 @@ class SearchableTraitTest extends TestCase
// Users with no location should also be included for negated filters.
$this->assertContains((int) $nullLocationUser->id, $returnedIds);
}
+
+ /**
+ * Regression: structured AND filter should honor model_number and location together.
+ */
+ public function test_asset_structured_filter_and_operator_with_model_number_and_location()
+ {
+ $locationA = Location::factory()->create(['name' => 'HQ-East']);
+ $locationB = Location::factory()->create(['name' => 'HQ-West']);
+ $manufacturer = Manufacturer::factory()->create(['name' => 'FilterCo']);
+
+ $modelMatch = AssetModel::factory()->create([
+ 'manufacturer_id' => $manufacturer->id,
+ 'model_number' => 'MODEL-111',
+ ]);
+
+ $modelOther = AssetModel::factory()->create([
+ 'manufacturer_id' => $manufacturer->id,
+ 'model_number' => 'MODEL-222',
+ ]);
+
+ // ✅ Matches both model_number and location.
+ Asset::factory()->create([
+ 'asset_tag' => 'AND-MATCH-1',
+ 'model_id' => $modelMatch->id,
+ 'location_id' => $locationA->id,
+ ]);
+
+ // ❌ Matches location only.
+ Asset::factory()->create([
+ 'asset_tag' => 'AND-LOC-ONLY',
+ 'model_id' => $modelOther->id,
+ 'location_id' => $locationA->id,
+ ]);
+
+ // ❌ Matches model_number only.
+ Asset::factory()->create([
+ 'asset_tag' => 'AND-MODEL-ONLY',
+ 'model_id' => $modelMatch->id,
+ 'location_id' => $locationB->id,
+ ]);
+
+ $this->actingAsForApi(User::factory()->viewAssets()->create())
+ ->getJson(route('api.assets.index', [
+ 'filter' => json_encode([
+ 'model_number' => 'MODEL-111',
+ 'location' => 'HQ-East',
+ ]),
+ 'filter_operator' => 'and',
+ ]))
+ ->assertOk()
+ ->assertJson(fn (AssertableJson $json) => $json->has('rows', 1)->etc());
+ }
}