A free open source IT asset/license management system
Added checkbox for location overwrite to keeo behavior the same as single audit
snipe4f5fbf3ba708
diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.phpindex 3618ee9d89..b807ab1cee 100644--- a/app/Http/Controllers/Assets/BulkAssetsController.php+++ b/app/Http/Controllers/Assets/BulkAssetsController.php@@ -1022,7 +1022,15 @@ class BulkAssetsController extends Controller}$asset->last_audit_date = date('Y-m-d H:i:s');- if ($submittedLocation) {+ // Only overwrite the asset's physical location when the+ // "update_location" opt-in is checked. Without it, the+ // audit log still records the submitted location below+ // (as "where the audit happened") but the asset itself+ // stays where it was. Matches the single-audit form's+ // matching checkbox and the API's update_location=1+ // gate, so an integration and a UI user get identical+ // behavior from the same intent.+ if ($submittedLocation && $request->input('update_location') == '1') {$asset->location_id = $submittedLocation->id;}diff --git a/resources/views/hardware/bulk-audit.blade.php b/resources/views/hardware/bulk-audit.blade.phpindex 83e67e459e..bd5dbce2f9 100644--- a/resources/views/hardware/bulk-audit.blade.php+++ b/resources/views/hardware/bulk-audit.blade.php@@ -38,6 +38,17 @@:selected="old('location_id')"/>+ {{-- When unchecked (default), the+ location above is only recorded on each audit log+ entry (as "where the audit happened"). When checked,+ the assets' physical location_id is also overwritten+ to that location. --}}+ <x-form.checkbox-row+ name="update_location"+ :label="trans('admin/hardware/form.asset_location')"+ :help_html="trans('help.audit_help')"+ />+{{-- Next audit date. Prefilled with today + audit_intervalfrom settings so users can accept the calculateddefault or override for this batch. --}}diff --git a/tests/Feature/Assets/Ui/BulkAuditSelectedAssetsTest.php b/tests/Feature/Assets/Ui/BulkAuditSelectedAssetsTest.phpindex 3b54ea9796..f2f010d3d3 100644--- a/tests/Feature/Assets/Ui/BulkAuditSelectedAssetsTest.php+++ b/tests/Feature/Assets/Ui/BulkAuditSelectedAssetsTest.php@@ -112,7 +112,7 @@ class BulkAuditSelectedAssetsTest extends TestCase}}- public function test_bulk_audit_updates_location_when_provided(): void+ public function test_bulk_audit_updates_asset_location_when_update_location_opt_in_is_checked(): void{$location = Location::factory()->create();$assets = Asset::factory()->count(2)->create();@@ -121,12 +121,48 @@ class BulkAuditSelectedAssetsTest extends TestCase->post(route('hardware.bulk-audit.store'), ['selected_assets' => $assets->pluck('id')->toArray(),'location_id' => $location->id,+ 'update_location' => '1',+ ])+ ->assertRedirect(route('hardware.index'));++ foreach ($assets as $asset) {+ $this->assertSame($location->id, $asset->fresh()->location_id);+ }+ }++ public function test_bulk_audit_does_not_move_assets_when_update_location_is_unchecked(): void+ {+ // Provided location_id + no update_location flag should+ // record the audit's location on each log entry (as "where+ // the audit happened") without touching the asset's actual+ // location_id. Matches the API's update_location=1 gate.+ $originalLocation = Location::factory()->create();+ $auditLocation = Location::factory()->create();+ $assets = Asset::factory()->count(2)->create(['location_id' => $originalLocation->id]);++ $this->actingAs(User::factory()->auditAssets()->create())+ ->post(route('hardware.bulk-audit.store'), [+ 'selected_assets' => $assets->pluck('id')->toArray(),+ 'location_id' => $auditLocation->id,+ // update_location intentionally omitted (unchecked)])->assertRedirect(route('hardware.index'));foreach ($assets as $asset) {$fresh = $asset->fresh();- $this->assertSame($location->id, $fresh->location_id);+ $this->assertSame(+ $originalLocation->id,+ $fresh->location_id,+ "Asset {$asset->id} location must not change when update_location is unchecked.",+ );++ // But the audit log DOES record the submitted location.+ $log = Actionlog::where('action_type', 'audit')+ ->where('item_type', Asset::class)+ ->where('item_id', $asset->id)+ ->first();+ $this->assertNotNull($log);+ $this->assertSame($auditLocation->id, (int) $log->location_id);}}