Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe
2026-06-08 22:38:30 +01:00
32 changed files with 385 additions and 29 deletions
@@ -358,7 +358,7 @@ class AssetsController extends Controller
$qr_code = (object) [
'display' => $settings->qr_code == '1',
'url' => route('qr_code/hardware', $asset),
'url' => route('qr_code/common', ['object_type' => 'hardware', 'id' => $asset->id]),
];
$total_maintenance_cost = $asset->maintenances?->sum('cost');
+66
View File
@@ -0,0 +1,66 @@
<?php
namespace App\Http\Controllers;
use App\Helpers\Helper;
use App\Models\Setting;
use Com\Tecnick\Barcode\Barcode;
use Illuminate\Http\Response;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
class QrCodeController extends Controller
{
public static $map_show_route = [
'accessories' => 'accessories.show',
'assets' => 'hardware.show',
'companies' => 'companies.show',
'components' => 'components.show',
'consumables' => 'consumables.show',
'hardware' => 'hardware.show',
'licenses' => 'licenses.show',
'locations' => 'locations.show',
'models' => 'models.show',
'users' => 'users.show',
];
public function show($object_type, $id): Response|BinaryFileResponse|string|bool
{
$settings = Setting::getSettings();
if ($settings->label2_2d_type === 'none') {
return false;
}
if (! array_key_exists($object_type, self::$map_show_route)) {
return $object_type.' is not a valid type.';
}
$object = self::$map_object_type[$object_type]::withTrashed()->find($id);
if (! $object) {
return 'That item is invalid';
}
$this->authorize('view', $object);
$size = Helper::barcodeDimensions($settings->label2_2d_type);
$qr_file = public_path().'/uploads/barcodes/qr-'.str_slug($object_type).'-'.str_slug($id).'.png';
if (file_exists($qr_file)) {
return response()->file($qr_file, ['Content-type' => 'image/png']);
}
$barcode = new Barcode;
$barcode_obj = $barcode->getBarcodeObj(
$settings->label2_2d_type,
route(self::$map_show_route[$object_type], $id),
$size['height'],
$size['width'],
'black',
[-2, -2, -2, -2]
);
file_put_contents($qr_file, $barcode_obj->getPngData());
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
}
}
@@ -26,6 +26,7 @@ class AccessoriesTransformer
'id' => $accessory->id,
'name' => e($accessory->name),
'image' => ($accessory->image) ? Storage::disk('public')->url('accessories/'.e($accessory->image)) : null,
'qr_code_url' => route('qr_code/common', ['object_type' => 'accessories', 'id' => $accessory->id]),
'company' => ($accessory->company) ? [
'id' => $accessory->company->id,
'name' => e($accessory->company->name),
@@ -48,6 +48,7 @@ class AssetModelsTransformer
'tag_color' => ($assetmodel->manufacturer->tag_color) ? e($assetmodel->manufacturer->tag_color) : null,
] : null,
'image' => ($assetmodel->image != '') ? Storage::disk('public')->url('models/'.e($assetmodel->image)) : null,
'qr_code_url' => route('qr_code/common', ['object_type' => 'models', 'id' => $assetmodel->id]),
'model_number' => ($assetmodel->model_number ? e($assetmodel->model_number) : null),
'min_amt' => ($assetmodel->min_amt) ? (int) $assetmodel->min_amt : null,
@@ -98,6 +98,7 @@ class AssetsTransformer
'tag_color' => ($asset->defaultLoc->tag_color) ? e($asset->defaultLoc->tag_color) : null,
] : null,
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
'qr_code_url' => route('qr_code/common', ['object_type' => 'hardware', 'id' => $asset->id]),
'qr' => ($setting->qr_code == '1') ? Storage::disk('public')->url('barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png') : null,
'alt_barcode' => ($setting->alt_barcode_enabled == '1') ? Storage::disk('public')->url('barcodes/'.str_slug($setting->alt_barcode).'-'.str_slug($asset->asset_tag).'.png') : null,
'assigned_to' => $this->transformAssignedTo($asset),
@@ -30,6 +30,7 @@ class CompaniesTransformer
'fax' => ($company->fax != '') ? e($company->fax) : null,
'email' => ($company->email != '') ? e($company->email) : null,
'image' => ($company->image) ? Storage::disk('public')->url('companies/'.e($company->image)) : null,
'qr_code_url' => route('qr_code/common', ['object_type' => 'companies', 'id' => $company->id]),
'assets_count' => (int) $company->assets_count,
'licenses_count' => (int) $company->licenses_count,
'accessories_count' => (int) $company->accessories_count,
@@ -26,6 +26,7 @@ class ComponentsTransformer
'id' => (int) $component->id,
'name' => e($component->name),
'image' => ($component->image) ? Storage::disk('public')->url('components/'.e($component->image)) : null,
'qr_code_url' => route('qr_code/common', ['object_type' => 'components', 'id' => $component->id]),
'serial' => ($component->serial) ? e($component->serial) : null,
'location' => ($component->location) ? [
'id' => (int) $component->location->id,
@@ -25,6 +25,7 @@ class ConsumablesTransformer
'id' => (int) $consumable->id,
'name' => e($consumable->name),
'image' => ($consumable->getImageUrl()) ? ($consumable->getImageUrl()) : null,
'qr_code_url' => route('qr_code/common', ['object_type' => 'consumables', 'id' => $consumable->id]),
'category' => ($consumable->category) ? [
'id' => $consumable->category->id,
'name' => e($consumable->category->name),
@@ -24,6 +24,7 @@ class LicensesTransformer
$array = [
'id' => (int) $license->id,
'name' => e($license->name),
'qr_code_url' => route('qr_code/common', ['object_type' => 'licenses', 'id' => $license->id]),
'company' => ($license->company) ? ['id' => (int) $license->company->id, 'name' => e($license->company->name)] : null,
'manufacturer' => ($license->manufacturer) ? [
'id' => (int) $license->manufacturer->id,
@@ -39,6 +39,7 @@ class LocationsTransformer
'id' => (int) $location->id,
'name' => e($location->name),
'image' => ($location->image) ? Storage::disk('public')->url('locations/'.e($location->image)) : null,
'qr_code_url' => route('qr_code/common', ['object_type' => 'locations', 'id' => $location->id]),
'address' => ($location->address) ? e($location->address) : null,
'address2' => ($location->address2) ? e($location->address2) : null,
'city' => ($location->city) ? e($location->city) : null,
+1 -1
View File
@@ -21,7 +21,6 @@ class UsersTransformer
public function transformUser(User $user)
{
$role = null;
if ($user->isSuperUser()) {
$role = 'superadmin';
@@ -31,6 +30,7 @@ class UsersTransformer
$array = [
'id' => (int) $user->id,
'avatar' => e($user->present()->gravatar) ?? null,
'qr_code_url' => route('qr_code/common', ['object_type' => 'users', 'id' => $user->id]),
'name' => e($user->getFullNameAttribute()) ?? null,
'first_name' => e($user->first_name) ?? null,
'last_name' => e($user->last_name) ?? null,
+5
View File
@@ -216,6 +216,11 @@ class Setting extends Model
return $custom_css;
}
public function isQrEnabled(): bool
{
return $this->qr_code == '1' || $this->label2_2d_type !== 'none';
}
/**
* Converts bytes into human readable file size.
*
+21 -6
View File
@@ -14,12 +14,27 @@ class AccessoryObserver
*/
public function updated(Accessory $accessory)
{
$logAction = new Actionlog;
$logAction->item_type = Accessory::class;
$logAction->item_id = $accessory->id;
$logAction->created_at = date('Y-m-d H:i:s');
$logAction->created_by = auth()->id();
$logAction->logaction('update');
$changed = [];
foreach ($accessory->getRawOriginal() as $key => $value) {
if ($key === 'updated_at') {
continue;
}
if ($accessory->getRawOriginal()[$key] != $accessory->getAttributes()[$key]) {
$changed[$key]['old'] = $accessory->getRawOriginal()[$key];
$changed[$key]['new'] = $accessory->getAttributes()[$key];
}
}
if (count($changed) > 0) {
$logAction = new Actionlog;
$logAction->item_type = Accessory::class;
$logAction->item_id = $accessory->id;
$logAction->created_at = date('Y-m-d H:i:s');
$logAction->created_by = auth()->id();
$logAction->log_meta = json_encode($changed);
$logAction->logaction('update');
}
}
/**
+2
View File
@@ -15,6 +15,8 @@ class ComponentObserver
public function updated(Component $component)
{
$changed = [];
foreach ($component->getRawOriginal() as $key => $value) {
// Check and see if the value changed
if ($component->getRawOriginal()[$key] != $component->getAttributes()[$key]) {
+21 -6
View File
@@ -14,12 +14,27 @@ class LicenseObserver
*/
public function updated(License $license)
{
$logAction = new Actionlog;
$logAction->item_type = License::class;
$logAction->item_id = $license->id;
$logAction->created_at = date('Y-m-d H:i:s');
$logAction->created_by = auth()->id();
$logAction->logaction('update');
$changed = [];
foreach ($license->getRawOriginal() as $key => $value) {
if ($key === 'updated_at') {
continue;
}
if ($license->getRawOriginal()[$key] != $license->getAttributes()[$key]) {
$changed[$key]['old'] = $license->getRawOriginal()[$key];
$changed[$key]['new'] = $license->getAttributes()[$key];
}
}
if (count($changed) > 0) {
$logAction = new Actionlog;
$logAction->item_type = License::class;
$logAction->item_id = $license->id;
$logAction->created_at = date('Y-m-d H:i:s');
$logAction->created_by = auth()->id();
$logAction->log_meta = json_encode($changed);
$logAction->logaction('update');
}
}
/**
+1 -1
View File
@@ -66,7 +66,7 @@
<x-page-column class="col-md-3">
<x-box class="side-box expanded">
<x-info-panel :infoPanelObj="$accessory" img_path="{{ app('accessories_upload_url') }}">
<x-info-panel :infoPanelObj="$accessory" img_path="{{ app('accessories_upload_url') }}" :qr_code_url="route('qr_code/common', ['object_type' => 'accessories', 'id' => $accessory->id])">
<x-slot:buttons>
<x-button.edit :item="$accessory" :route="route('accessories.edit', $accessory->id)"/>
<x-button.clone :item="$accessory" :route="route('clone/accessories', $accessory->id)"/>
@@ -1,6 +1,7 @@
@props([
'infoPanelObj' => null,
'img_path' => null,
'qr_code_url' => null,
'snipeSettings' => \App\Models\Setting::getSettings()
])
@@ -589,6 +590,12 @@
{{ $after_list }}
@endif
@if ($qr_code_url && $snipeSettings->isQrEnabled())
<div class="col-md-12 text-center asset-qr-img" style="padding-top: 15px;">
<img src="{{ $qr_code_url }}" class="img-thumbnail" style="height: 150px; width: 150px; margin-right: 10px;" alt="QR code for {{ $infoPanelObj->name }}">
</div>
@endif
</div>
<!-- end side info-box -->
+1 -1
View File
@@ -75,7 +75,7 @@
</x-page-column>
<x-page-column class="col-md-3">
<x-box class="side-box expanded">
<x-info-panel :infoPanelObj="$company" img_path="{{ app('companies_upload_url') }}">
<x-info-panel :infoPanelObj="$company" img_path="{{ app('companies_upload_url') }}" :qr_code_url="route('qr_code/common', ['object_type' => 'companies', 'id' => $company->id])">
<x-slot:buttons>
<x-button.edit :item="$company" :route="route('companies.edit', $company->id)" />
+1 -1
View File
@@ -61,7 +61,7 @@
<x-page-column class="col-md-3">
<x-box class="side-box expanded">
<x-info-panel :infoPanelObj="$snipe_component" img_path="{{ app('components_upload_url') }}">
<x-info-panel :infoPanelObj="$snipe_component" img_path="{{ app('components_upload_url') }}" :qr_code_url="route('qr_code/common', ['object_type' => 'components', 'id' => $snipe_component->id])">
<x-slot:buttons>
<x-button.edit :item="$snipe_component" :route="route('components.edit', $snipe_component->id)"/>
+1 -1
View File
@@ -62,7 +62,7 @@
<x-page-column class="col-md-3">
<x-box class="side-box expanded">
<x-info-panel :infoPanelObj="$consumable" img_path="{{ app('consumables_upload_url') }}">
<x-info-panel :infoPanelObj="$consumable" img_path="{{ app('consumables_upload_url') }}" :qr_code_url="route('qr_code/common', ['object_type' => 'consumables', 'id' => $consumable->id])">
<x-slot:buttons>
<x-button.edit :item="$consumable" :route="route('consumables.edit', $consumable->id)"/>
+2 -2
View File
@@ -112,7 +112,7 @@ $qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->label2_1d_type!=
@if ($settings->qr_code=='1')
<div class="qr_img">
<img src="{{ config('app.url') }}/hardware/{{ $asset->id }}/qr_code" class="qr_img">
<img src="{{ route('qr_code/common', ['object_type' => 'hardware', 'id' => $asset->id]) }}" class="qr_img">
</div>
@endif
@@ -166,7 +166,7 @@ $qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->label2_1d_type!=
</div>
@if (($count % $settings->labels_per_page == 0) && $count!=count($assets))
@if ($settings->labels_per_page > 0 && ($count % $settings->labels_per_page == 0) && $count != count($assets))
<div class="page-break"></div>
<div class="next-padding">&nbsp;</div>
@endif
+3 -2
View File
@@ -318,12 +318,13 @@
@if (($snipeSettings->qr_code=='1') || $snipeSettings->label2_2d_type!='none')
@if ($snipeSettings->isQrEnabled())
<div class="col-md-12 text-center asset-qr-img" style="padding-top: 15px;">
<img src="{{ config('app.url') }}/hardware/{{ $asset->id }}/qr_code" class="img-thumbnail" style="height: 150px; width: 150px; margin-right: 10px;" alt="QR code for {{ $asset->getDisplayNameAttribute() }}">
<img src="{{ route('qr_code/common', ['object_type' => 'hardware', 'id' => $asset->id]) }}" class="img-thumbnail" style="height: 150px; width: 150px; margin-right: 10px;" alt="QR code for {{ $asset->getDisplayNameAttribute() }}">
</div>
@endif
</x-page-column>
<!-- end side stats column -->
+1 -1
View File
@@ -104,7 +104,7 @@
<x-page-column class="col-md-3">
<x-box class="side-box expanded">
<x-info-panel :infoPanelObj="$license" img_path="{{ app('licenses_upload_url') }}">
<x-info-panel :infoPanelObj="$license" img_path="{{ app('licenses_upload_url') }}" :qr_code_url="route('qr_code/common', ['object_type' => 'licenses', 'id' => $license->id])">
<x-slot:buttons>
+1 -1
View File
@@ -216,7 +216,7 @@
<x-page-column class="col-md-3">
<x-box class="side-box expanded">
<x-info-panel :infoPanelObj="$location" img_path="{{ app('locations_upload_url') }}">
<x-info-panel :infoPanelObj="$location" img_path="{{ app('locations_upload_url') }}" :qr_code_url="route('qr_code/common', ['object_type' => 'locations', 'id' => $location->id])">
<x-slot:buttons>
<x-button.edit :item="$location" :route="route('locations.edit', $location->id)" />
+1 -1
View File
@@ -54,7 +54,7 @@
</x-page-column>
<x-page-column class="col-md-3">
<x-box class="side-box expanded">
<x-info-panel :infoPanelObj="$model" img_path="{{ app('models_upload_url') }}">
<x-info-panel :infoPanelObj="$model" img_path="{{ app('models_upload_url') }}" :qr_code_url="route('qr_code/common', ['object_type' => 'models', 'id' => $model->id])">
<x-slot:buttons>
<x-button.edit :item="$model" :route="route('models.edit', $model->id)" />
<x-button.add :item="\App\Models\Asset::class" :tooltip="trans('general.new_asset')" :route="route('hardware.create', ['model_id' => $model->id])"/>
+5
View File
@@ -303,6 +303,11 @@
@endif
@if ($snipeSettings->isQrEnabled())
<div class="col-md-12 text-center user-qr-img" style="padding-top: 15px;">
<img src="{{ route('qr_code/common', ['object_type' => 'users', 'id' => $user->id]) }}" class="img-thumbnail" style="height: 150px; width: 150px; margin-right: 10px;" alt="QR code for {{ $user->display_name }}">
</div>
@endif
</x-page-column>
<!-- end side stats well column-->
+9
View File
@@ -22,6 +22,7 @@ use App\Http\Controllers\ManufacturersController;
use App\Http\Controllers\ModalController;
use App\Http\Controllers\NotesController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\QrCodeController;
use App\Http\Controllers\ReportsController;
use App\Http\Controllers\ReportTemplatesController;
use App\Http\Controllers\SettingsController;
@@ -697,6 +698,14 @@ Route::group(['middleware' => 'web'], function () {
[LoginController::class, 'logout']
)->name('logout.post');
/**
* QR Code routes
*/
Route::get('{object_type}/{id}/qr_code',
[QrCodeController::class, 'show']
)->name('qr_code/common')
->where(['object_type' => 'accessories|assets|hardware|licenses|locations|models|companies|components|consumables|users']);
/**
* Uploaded files API routes
*/
-4
View File
@@ -123,10 +123,6 @@ Route::group(
return redirect()->route('hardware.show', $assetId);
});
Route::get('{asset}/qr_code',
[AssetsController::class, 'getQrCode']
)->name('qr_code/hardware')->withTrashed();
Route::get('{asset}/barcode',
[AssetsController::class, 'getBarCode']
)->name('barcode/hardware')->withTrashed();
@@ -3,6 +3,7 @@
namespace Tests\Feature\Accessories\Api;
use App\Models\Accessory;
use App\Models\Actionlog;
use App\Models\Category;
use App\Models\Company;
use App\Models\Location;
@@ -137,4 +138,47 @@ class UpdateAccessoryTest extends TestCase implements TestsFullMultipleCompanies
$this->assertEquals($manufacturerB->id, $accessory->manufacturer_id);
$this->assertEquals($supplierB->id, $accessory->supplier_id);
}
public function test_update_logs_changed_fields_in_log_meta()
{
$accessory = Accessory::factory()->create(['qty' => 5, 'name' => 'Old Name']);
$this->actingAsForApi(User::factory()->editAccessories()->create())
->patchJson(route('api.accessories.update', $accessory), ['qty' => 10, 'name' => 'New Name']);
$log = Actionlog::where('item_type', Accessory::class)
->where('item_id', $accessory->id)
->where('action_type', 'update')
->latest()
->first();
$this->assertNotNull($log, 'No update log entry was created');
$this->assertNotNull($log->log_meta, 'log_meta was not stored');
$meta = json_decode($log->log_meta, true);
$this->assertEquals('5', $meta['qty']['old']);
$this->assertEquals('10', $meta['qty']['new']);
$this->assertEquals('Old Name', $meta['name']['old']);
$this->assertEquals('New Name', $meta['name']['new']);
}
public function test_no_op_update_does_not_create_log_entry()
{
$accessory = Accessory::factory()->create(['qty' => 5, 'name' => 'Same Name']);
$before = Actionlog::where('item_type', Accessory::class)
->where('item_id', $accessory->id)
->where('action_type', 'update')
->count();
$this->actingAsForApi(User::factory()->editAccessories()->create())
->patchJson(route('api.accessories.update', $accessory), ['qty' => 5, 'name' => 'Same Name']);
$after = Actionlog::where('item_type', Accessory::class)
->where('item_id', $accessory->id)
->where('action_type', 'update')
->count();
$this->assertEquals($before, $after, 'A spurious log entry was created for a no-op update');
}
}
@@ -3,6 +3,7 @@
namespace Tests\Feature\Accessories\Ui;
use App\Models\Accessory;
use App\Models\Actionlog;
use App\Models\Category;
use App\Models\Company;
use App\Models\Location;
@@ -124,4 +125,67 @@ class UpdateAccessoryTest extends TestCase
'notes' => 'A new note',
]);
}
public function test_update_logs_changed_fields_in_log_meta()
{
$accessory = Accessory::factory()->create([
'qty' => 5,
'name' => 'Old Name',
'model_number' => null,
'location_id' => null,
]);
$this->actingAs(User::factory()->editAccessories()->create())
->put(route('accessories.update', $accessory), [
'redirect_option' => 'index',
'name' => 'New Name',
'qty' => '10',
'category_id' => (string) $accessory->category_id,
]);
$log = Actionlog::where('item_type', Accessory::class)
->where('item_id', $accessory->id)
->where('action_type', 'update')
->latest()
->first();
$this->assertNotNull($log, 'No update log entry was created');
$this->assertNotNull($log->log_meta, 'log_meta was not stored');
$meta = json_decode($log->log_meta, true);
$this->assertEquals('5', $meta['qty']['old']);
$this->assertEquals('10', $meta['qty']['new']);
$this->assertEquals('Old Name', $meta['name']['old']);
$this->assertEquals('New Name', $meta['name']['new']);
}
public function test_no_op_update_does_not_create_log_entry()
{
$accessory = Accessory::factory()->create([
'qty' => 5,
'name' => 'Same Name',
'model_number' => null,
'location_id' => null,
]);
$before = Actionlog::where('item_type', Accessory::class)
->where('item_id', $accessory->id)
->where('action_type', 'update')
->count();
$this->actingAs(User::factory()->editAccessories()->create())
->put(route('accessories.update', $accessory), [
'redirect_option' => 'index',
'name' => 'Same Name',
'qty' => '5',
'category_id' => (string) $accessory->category_id,
]);
$after = Actionlog::where('item_type', Accessory::class)
->where('item_id', $accessory->id)
->where('action_type', 'update')
->count();
$this->assertEquals($before, $after, 'A spurious log entry was created for a no-op update');
}
}
@@ -0,0 +1,59 @@
<?php
namespace Tests\Feature\Licenses\Api;
use App\Models\Actionlog;
use App\Models\License;
use App\Models\User;
use Tests\TestCase;
class UpdateLicenseTest extends TestCase
{
public function test_update_logs_changed_fields_in_log_meta()
{
$license = License::factory()->create(['name' => 'Old Name', 'seats' => 5]);
$this->actingAsForApi(User::factory()->editLicenses()->create())
->patchJson(route('api.licenses.update', $license), [
'name' => 'New Name',
'seats' => 10,
'category_id' => $license->category_id,
]);
$log = Actionlog::where('item_type', License::class)
->where('item_id', $license->id)
->where('action_type', 'update')
->latest()
->first();
$this->assertNotNull($log, 'No update log entry was created');
$this->assertNotNull($log->log_meta, 'log_meta was not stored');
$meta = json_decode($log->log_meta, true);
$this->assertEquals('Old Name', $meta['name']['old']);
$this->assertEquals('New Name', $meta['name']['new']);
}
public function test_no_op_update_does_not_create_log_entry()
{
$license = License::factory()->create(['name' => 'Same Name']);
$before = Actionlog::where('item_type', License::class)
->where('item_id', $license->id)
->where('action_type', 'update')
->count();
$this->actingAsForApi(User::factory()->editLicenses()->create())
->patchJson(route('api.licenses.update', $license), [
'name' => 'Same Name',
'category_id' => $license->category_id,
]);
$after = Actionlog::where('item_type', License::class)
->where('item_id', $license->id)
->where('action_type', 'update')
->count();
$this->assertEquals($before, $after, 'A spurious log entry was created for a no-op update');
}
}
@@ -2,6 +2,7 @@
namespace Tests\Feature\Licenses\Ui;
use App\Models\Actionlog;
use App\Models\Category;
use App\Models\License;
use App\Models\User;
@@ -99,4 +100,63 @@ class UpdateLicenseTest extends TestCase
$this->assertEquals($license->licenseseats()->count(), $license->seats);
$this->assertEquals($license->licenseseats()->count(), 5000);
}
public function test_update_logs_changed_fields_in_log_meta()
{
$license = License::factory()->create(['name' => 'Old Name', 'seats' => 5]);
$this->actingAs(User::factory()->editLicenses()->create())
->put(route('licenses.update', $license), [
'name' => 'New Name',
'seats' => 10,
'category_id' => $license->category_id,
]);
$log = Actionlog::where('item_type', License::class)
->where('item_id', $license->id)
->where('action_type', 'update')
->latest()
->first();
$this->assertNotNull($log, 'No update log entry was created');
$this->assertNotNull($log->log_meta, 'log_meta was not stored');
$meta = json_decode($log->log_meta, true);
$this->assertEquals('Old Name', $meta['name']['old']);
$this->assertEquals('New Name', $meta['name']['new']);
}
public function test_no_op_update_does_not_create_log_entry()
{
$license = License::factory()->create([
'name' => 'Same Name',
'seats' => 5,
'license_email' => null,
'notes' => null,
'order_number' => null,
'purchase_date' => null,
'reassignable' => 0,
'serial' => null,
'supplier_id' => null,
]);
$before = Actionlog::where('item_type', License::class)
->where('item_id', $license->id)
->where('action_type', 'update')
->count();
$this->actingAs(User::factory()->editLicenses()->create())
->put(route('licenses.update', $license), [
'name' => 'Same Name',
'seats' => 5,
'category_id' => $license->category_id,
]);
$after = Actionlog::where('item_type', License::class)
->where('item_id', $license->id)
->where('action_type', 'update')
->count();
$this->assertEquals($before, $after, 'A spurious log entry was created for a no-op update');
}
}