Skip to content

Commit 9ad99c1

Browse files
authored
Merge pull request #16494 from marcusmoore/bug/sc-28675
Avoid logging consumable checkins and purge action log of bad entries
2 parents 622626b + d5bc5ca commit 9ad99c1

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

app/Http/Controllers/Users/BulkUsersController.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ public function destroy(Request $request)
298298
$this->logItemCheckinAndDelete($assets, Asset::class);
299299
$this->logAccessoriesCheckin($accessoryUserRows);
300300
$this->logItemCheckinAndDelete($licenses, License::class);
301-
$this->logConsumablesCheckin($consumableUserRows);
302301

303302
Asset::whereIn('id', $assets->pluck('id'))->update([
304303
'status_id' => e(request('status_id')),
@@ -366,20 +365,6 @@ private function logAccessoriesCheckin(Collection $accessoryUserRows): void
366365
}
367366
}
368367

369-
private function logConsumablesCheckin(Collection $consumableUserRows): void
370-
{
371-
foreach ($consumableUserRows as $consumableUserRow) {
372-
$logAction = new Actionlog();
373-
$logAction->item_id = $consumableUserRow->consumable_id;
374-
$logAction->item_type = Consumable::class;
375-
$logAction->target_id = $consumableUserRow->assigned_to;
376-
$logAction->target_type = User::class;
377-
$logAction->created_by = auth()->id();
378-
$logAction->note = 'Bulk checkin items';
379-
$logAction->logaction('checkin from');
380-
}
381-
}
382-
383368
/**
384369
* Save bulk-edited users
385370
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use App\Models\Consumable;
4+
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Support\Facades\DB;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
DB::table('action_logs')
15+
->where([
16+
'action_type' => 'checkin from',
17+
'note' => 'Bulk checkin items',
18+
'item_type' => Consumable::class,
19+
])
20+
->delete();
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*/
26+
public function down(): void
27+
{
28+
// nothing to do here...
29+
}
30+
};

tests/Feature/Users/Ui/BulkActions/BulkDeleteUsersTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,10 @@ public function test_consumables_can_be_bulk_checked_in()
146146
$this->assertTrue($userB->fresh()->consumables->isNotEmpty());
147147
$this->assertTrue($userC->fresh()->consumables->isEmpty());
148148

149-
// These assertions check against a bug where the wrong value from
150-
// consumables_users was being populated in action_logs.item_id.
151-
$this->assertActionLogCheckInEntryFor($userA, $consumableA);
152-
$this->assertActionLogCheckInEntryFor($userA, $consumableB);
153-
$this->assertActionLogCheckInEntryFor($userC, $consumableA);
149+
// Consumable checkin should not be logged.
150+
$this->assertNoActionLogCheckInEntryFor($userA, $consumableA);
151+
$this->assertNoActionLogCheckInEntryFor($userA, $consumableB);
152+
$this->assertNoActionLogCheckInEntryFor($userC, $consumableA);
154153
}
155154

156155
public function test_license_seats_can_be_bulk_checked_in()
@@ -257,4 +256,16 @@ private function assertActionLogCheckInEntryFor(User $user, Model $model): void
257256
'item_id' => $model->id,
258257
]);
259258
}
259+
260+
private function assertNoActionLogCheckInEntryFor(User $user, Model $model): void
261+
{
262+
$this->assertDatabaseMissing('action_logs', [
263+
'action_type' => 'checkin from',
264+
'target_id' => $user->id,
265+
'target_type' => User::class,
266+
'note' => 'Bulk checkin items',
267+
'item_type' => get_class($model),
268+
'item_id' => $model->id,
269+
]);
270+
}
260271
}

0 commit comments

Comments
 (0)