From 3957d670d0b38505ab233ee42f66382392f5a389 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 22 Aug 2024 10:04:46 -0700 Subject: [PATCH 1/9] fixes send acceptance reminder query --- app/Console/Commands/SendAcceptanceReminder.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/SendAcceptanceReminder.php b/app/Console/Commands/SendAcceptanceReminder.php index dd9e59f611..a11ea8e270 100644 --- a/app/Console/Commands/SendAcceptanceReminder.php +++ b/app/Console/Commands/SendAcceptanceReminder.php @@ -47,9 +47,10 @@ class SendAcceptanceReminder extends Command { $pending = CheckoutAcceptance::pending()->where('checkoutable_type', 'App\Models\Asset') ->whereHas('checkoutable', function($query) { - $query->where('archived', 0); + $query->where('accepted_at', null) + ->where('declined_at', null); }) - ->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.adminuser']) + ->with(['assignedTo', 'checkoutable.assignedTo', 'checkoutable.model', 'checkoutable.admin']) ->get(); $count = 0; From b59bf3e7dc803b24159744c8bf2819a95a7df8ab Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 21 Aug 2024 16:49:29 -0700 Subject: [PATCH 2/9] Add failing test --- .../AssetModels/Ui/UpdateAssetModelsTest.php | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php index 423eaad574..9a58eb5c5b 100644 --- a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php @@ -4,6 +4,8 @@ namespace Tests\Feature\AssetModels\Ui; use App\Models\AssetModel; use App\Models\Category; +use App\Models\CustomField; +use App\Models\CustomFieldset; use App\Models\User; use Tests\TestCase; @@ -19,7 +21,7 @@ class UpdateAssetModelsTest extends TestCase ->assertStatus(403) ->assertForbidden(); } - + public function testUserCanEditAssetModels() { $category = Category::factory()->forAssets()->create(); @@ -62,4 +64,41 @@ class UpdateAssetModelsTest extends TestCase } + public function test_default_values_remain_unchanged_after_validation_error_occurs() + { + $this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL'); + + $assetModel = AssetModel::factory()->create(); + + $customFieldset = CustomFieldset::factory()->create(); + + [$customFieldOne, $customFieldTwo] = CustomField::factory()->count(2)->create(); + + $customFieldset->fields()->attach($customFieldOne, ['order' => 1, 'required' => false]); + $customFieldset->fields()->attach($customFieldTwo, ['order' => 2, 'required' => false]); + + $assetModel->fieldset()->associate($customFieldset); + + $assetModel->defaultValues()->attach($customFieldOne, ['default_value' => 'first default value']); + $assetModel->defaultValues()->attach($customFieldTwo, ['default_value' => 'second default value']); + + $this->actingAs(User::factory()->superuser()->create()) + ->put(route('models.update', ['model' => $assetModel]), [ + // should trigger validation error without name, etc, and NOT remove or change default values + 'add_default_values' => '1', + 'fieldset_id' => $customFieldset->id, + 'default_values' => [ + $customFieldOne->id => 'changed value', + $customFieldTwo->id => 'changed value', + ], + ]); + + $this->assertEquals( + 2, + $assetModel->fresh()->defaultValues->filter(function (CustomField $field) { + return in_array($field->pivot->default_value, ['first default value', 'second default value']); + })->count(), + 'Default field values were changed unexpectedly.' + ); + } } From bcace9d019b08048a954a9b89df9e09f8cbfa67e Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 21 Aug 2024 16:54:16 -0700 Subject: [PATCH 3/9] Point test to correct endpoint --- tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php index 9a58eb5c5b..3ca91e9821 100644 --- a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php @@ -14,11 +14,10 @@ class UpdateAssetModelsTest extends TestCase public function testPermissionRequiredToStoreAssetModel() { $this->actingAs(User::factory()->create()) - ->post(route('models.store'), [ - 'name' => 'Test Model', - 'category_id' => Category::factory()->create()->id + ->put(route('models.update', ['model' => AssetModel::factory()->create()]), [ + 'name' => 'Changed Name', + 'category_id' => Category::factory()->create()->id, ]) - ->assertStatus(403) ->assertForbidden(); } From 663b2fd844aa6461b5336f10f66d7ea49cf3ecdf Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 21 Aug 2024 16:59:38 -0700 Subject: [PATCH 4/9] Add test case --- .../AssetModels/Ui/UpdateAssetModelsTest.php | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php index 3ca91e9821..83ffce7c91 100644 --- a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php @@ -68,9 +68,7 @@ class UpdateAssetModelsTest extends TestCase $this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL'); $assetModel = AssetModel::factory()->create(); - $customFieldset = CustomFieldset::factory()->create(); - [$customFieldOne, $customFieldTwo] = CustomField::factory()->count(2)->create(); $customFieldset->fields()->attach($customFieldOne, ['order' => 1, 'required' => false]); @@ -87,8 +85,8 @@ class UpdateAssetModelsTest extends TestCase 'add_default_values' => '1', 'fieldset_id' => $customFieldset->id, 'default_values' => [ - $customFieldOne->id => 'changed value', - $customFieldTwo->id => 'changed value', + $customFieldOne->id => 'first changed value', + $customFieldTwo->id => 'second changed value', ], ]); @@ -100,4 +98,40 @@ class UpdateAssetModelsTest extends TestCase 'Default field values were changed unexpectedly.' ); } + + public function test_default_values_can_be_updated() + { + $this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL'); + + $assetModel = AssetModel::factory()->create(); + $customFieldset = CustomFieldset::factory()->create(); + [$customFieldOne, $customFieldTwo] = CustomField::factory()->count(2)->create(); + + $customFieldset->fields()->attach($customFieldOne, ['order' => 1, 'required' => false]); + $customFieldset->fields()->attach($customFieldTwo, ['order' => 2, 'required' => false]); + + $assetModel->fieldset()->associate($customFieldset); + + $assetModel->defaultValues()->attach($customFieldOne, ['default_value' => 'first default value']); + $assetModel->defaultValues()->attach($customFieldTwo, ['default_value' => 'second default value']); + + $this->actingAs(User::factory()->superuser()->create()) + ->put(route('models.update', ['model' => $assetModel]), [ + // should trigger validation error without name, etc, and NOT remove or change default values + 'name' => 'Test Model Edited', + 'category_id' => $assetModel->category_id, + 'add_default_values' => '1', + 'fieldset_id' => $customFieldset->id, + 'default_values' => [ + $customFieldOne->id => 'first changed value', + $customFieldTwo->id => 'second changed value', + ], + ]); + + $potentiallyChangedDefaultValues = $assetModel->defaultValues->pluck('pivot.default_value'); + + $this->assertCount(2, $potentiallyChangedDefaultValues); + $this->assertContains('first changed value', $potentiallyChangedDefaultValues); + $this->assertContains('second changed value', $potentiallyChangedDefaultValues); + } } From d67975cb62f1f5ddb5bc3fa7c5297cb71e3388ea Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 21 Aug 2024 16:59:44 -0700 Subject: [PATCH 5/9] Implement fix --- app/Http/Controllers/AssetModelsController.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index b6bb34738d..60b1a39803 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -151,17 +151,17 @@ class AssetModelsController extends Controller $model->notes = $request->input('notes'); $model->requestable = $request->input('requestable', '0'); - $this->removeCustomFieldsDefaultValues($model); - $model->fieldset_id = $request->input('fieldset_id'); - if ($this->shouldAddDefaultValues($request->input())) { - if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){ - return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error')); - } - } - if ($model->save()) { + $this->removeCustomFieldsDefaultValues($model); + + if ($this->shouldAddDefaultValues($request->input())) { + if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))) { + return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error')); + } + } + if ($model->wasChanged('eol')) { if ($model->eol > 0) { $newEol = $model->eol; From af0a95be12fbe3b12ec710e95935fa1dcb54bc74 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 21 Aug 2024 17:00:32 -0700 Subject: [PATCH 6/9] Simplify assertions --- .../Feature/AssetModels/Ui/UpdateAssetModelsTest.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php index 83ffce7c91..95eb592b6d 100644 --- a/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php +++ b/tests/Feature/AssetModels/Ui/UpdateAssetModelsTest.php @@ -90,13 +90,10 @@ class UpdateAssetModelsTest extends TestCase ], ]); - $this->assertEquals( - 2, - $assetModel->fresh()->defaultValues->filter(function (CustomField $field) { - return in_array($field->pivot->default_value, ['first default value', 'second default value']); - })->count(), - 'Default field values were changed unexpectedly.' - ); + $potentiallyChangedDefaultValues = $assetModel->defaultValues->pluck('pivot.default_value'); + $this->assertCount(2, $potentiallyChangedDefaultValues); + $this->assertContains('first default value', $potentiallyChangedDefaultValues); + $this->assertContains('second default value', $potentiallyChangedDefaultValues); } public function test_default_values_can_be_updated() @@ -129,7 +126,6 @@ class UpdateAssetModelsTest extends TestCase ]); $potentiallyChangedDefaultValues = $assetModel->defaultValues->pluck('pivot.default_value'); - $this->assertCount(2, $potentiallyChangedDefaultValues); $this->assertContains('first changed value', $potentiallyChangedDefaultValues); $this->assertContains('second changed value', $potentiallyChangedDefaultValues); From 1d7853cbfe7ec5def3b8124133379355e133525d Mon Sep 17 00:00:00 2001 From: setpill <37372069+setpill@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:45:53 +0200 Subject: [PATCH 7/9] fixed #15374: load TrustProxies middleware in Kernel.php --- app/Http/Kernel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index d89f829d48..8c9289a799 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -14,6 +14,7 @@ class Kernel extends HttpKernel * @var array */ protected $middleware = [ + \App\Http\Middleware\TrustProxies::class, \App\Http\Middleware\NoSessionStore::class, \Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance::class, \Illuminate\Session\Middleware\StartSession::class, From ec0346e4a89635871f1a0f432ed2aa9fea6200c7 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 23 Aug 2024 07:19:08 +0100 Subject: [PATCH 8/9] Add @setpill as a contributor --- .all-contributorsrc | 9 +++++++++ CONTRIBUTORS.md | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 679f2740ac..bc4231a02a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -3199,6 +3199,15 @@ "contributions": [ "code" ] + }, + { + "login": "setpill", + "name": "setpill", + "avatar_url": "https://avatars.githubusercontent.com/u/37372069?v=4", + "profile": "https://github.com/setpill", + "contributions": [ + "code" + ] } ] } diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 1bea567693..e7d0eac039 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -52,7 +52,7 @@ Thanks goes to all of these wonderful people ([emoji key](https://github.com/ken | [
bilias](https://github.com/bilias)
[💻](https://github.com/snipe/snipe-it/commits?author=bilias "Code") | [
coach1988](https://github.com/coach1988)
[💻](https://github.com/snipe/snipe-it/commits?author=coach1988 "Code") | [
MrM](https://github.com/mauro-miatello)
[💻](https://github.com/snipe/snipe-it/commits?author=mauro-miatello "Code") | [
koiakoia](https://github.com/koiakoia)
[💻](https://github.com/snipe/snipe-it/commits?author=koiakoia "Code") | [
Mustafa Online](https://github.com/mustafa-online)
[💻](https://github.com/snipe/snipe-it/commits?author=mustafa-online "Code") | [
franceslui](https://github.com/franceslui)
[💻](https://github.com/snipe/snipe-it/commits?author=franceslui "Code") | [
Q4kK](https://github.com/Q4kK)
[💻](https://github.com/snipe/snipe-it/commits?author=Q4kK "Code") | | [
squintfox](https://github.com/squintfox)
[💻](https://github.com/snipe/snipe-it/commits?author=squintfox "Code") | [
Jeff Clay](https://github.com/jeffclay)
[💻](https://github.com/snipe/snipe-it/commits?author=jeffclay "Code") | [
Phil J R](https://github.com/PP-JN-RL)
[💻](https://github.com/snipe/snipe-it/commits?author=PP-JN-RL "Code") | [
i_virus](https://www.corelight.com/)
[💻](https://github.com/snipe/snipe-it/commits?author=chandanchowdhury "Code") | [
Paul Grime](https://github.com/gitgrimbo)
[💻](https://github.com/snipe/snipe-it/commits?author=gitgrimbo "Code") | [
Lee Porte](https://leeporte.co.uk)
[💻](https://github.com/snipe/snipe-it/commits?author=LeePorte "Code") | [
BRYAN ](https://github.com/bryanlopezinc)
[💻](https://github.com/snipe/snipe-it/commits?author=bryanlopezinc "Code") [⚠️](https://github.com/snipe/snipe-it/commits?author=bryanlopezinc "Tests") | | [
U-H-T](https://github.com/U-H-T)
[💻](https://github.com/snipe/snipe-it/commits?author=U-H-T "Code") | [
Matt Tyree](https://github.com/Tyree)
[📖](https://github.com/snipe/snipe-it/commits?author=Tyree "Documentation") | [
Florent Bervas](http://spoontux.net)
[💻](https://github.com/snipe/snipe-it/commits?author=FlorentDotMe "Code") | [
Daniel Albertsen](https://ditscheri.com)
[💻](https://github.com/snipe/snipe-it/commits?author=dbakan "Code") | [
r-xyz](https://github.com/r-xyz)
[💻](https://github.com/snipe/snipe-it/commits?author=r-xyz "Code") | [
Steven Mainor](https://github.com/DrekiDegga)
[💻](https://github.com/snipe/snipe-it/commits?author=DrekiDegga "Code") | [
arne-kroeger](https://github.com/arne-kroeger)
[💻](https://github.com/snipe/snipe-it/commits?author=arne-kroeger "Code") | -| [
Glukose1](https://github.com/Glukose1)
[💻](https://github.com/snipe/snipe-it/commits?author=Glukose1 "Code") | [
Scarzy](https://github.com/Scarzy)
[💻](https://github.com/snipe/snipe-it/commits?author=Scarzy "Code") | +| [
Glukose1](https://github.com/Glukose1)
[💻](https://github.com/snipe/snipe-it/commits?author=Glukose1 "Code") | [
Scarzy](https://github.com/Scarzy)
[💻](https://github.com/snipe/snipe-it/commits?author=Scarzy "Code") | [
setpill](https://github.com/setpill)
[💻](https://github.com/snipe/snipe-it/commits?author=setpill "Code") | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! From f85ebd7ffd30b334593724cc04dec607afe75ea0 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 23 Aug 2024 07:27:39 +0100 Subject: [PATCH 9/9] Added pull-right to angle bracket Signed-off-by: snipe --- resources/views/layouts/default.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index b303362ade..9b244102bd 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -647,7 +647,7 @@ dir="{{ Helper::determineLanguageDirection() }}"> {{ trans('general.settings') }} - +