From cf07186ae8704d609c65c7f91db67af9a2963c76 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 3 Sep 2024 12:23:23 -0700 Subject: [PATCH 1/4] gives priority to default eula being checked vs catregory eula --- app/Models/Asset.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index dd2f1c8e2..aff06b668 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -950,11 +950,12 @@ class Asset extends Depreciable { if (($this->model) && ($this->model->category)) { - if ($this->model->category->eula_text) { + if (($this->model->category->eula_text) && ($this->model->category->use_default_eula === 0)) { return Helper::parseEscapedMarkedown($this->model->category->eula_text); - } elseif ($this->model->category->use_default_eula == '1') { + } elseif ($this->model->category->use_default_eula === 1) { return Helper::parseEscapedMarkedown(Setting::getSettings()->default_eula_text); } else { + return false; } } From f04a4a3cf51564269352cfd2b0ba4baeb99ac3fe Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 4 Sep 2024 12:21:49 -0700 Subject: [PATCH 2/4] adds test --- app/View/Label.php | 4 ++-- tests/Unit/NotificationTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/View/Label.php b/app/View/Label.php index 886830659..07152ccd2 100644 --- a/app/View/Label.php +++ b/app/View/Label.php @@ -158,8 +158,8 @@ class Label implements View // The end result of this will be in this format: // {labelOne} {valueOne} | {labelTwo} {valueTwo} | {labelThree} {valueThree} $previous['value'] = trim(implode(' | ', [ - implode(' ', [$previous['label'], $previous['value']]), - implode(' ', [$current['label'], $current['value']]), + implode(' ', [$previous['label'], str_replace(['{', '}'], '', $previous['value'])]), + implode(' ', [$current['label'], str_replace(['{', '}'], '', $current['value'])]), ])); // We'll set the label to an empty string since we diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 8005759a1..86177c303 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -33,4 +33,28 @@ class NotificationTest extends TestCase $asset->checkOut($user, $admin->id); Notification::assertSentTo($user, CheckoutAssetNotification::class); } + public function testDefaultEulaIsSentWhenSetInCategory() + { + Notification::fake(); + + $this->settings->setEula('My Custom EULA Text'); + + $user = User::factory()->create(); + + $category = Category::factory()->create([ + 'use_default_eula' => 1, + 'eula_text' => 'EULA Text that should not be used', + ]); + + $model = AssetModel::factory()->for($category)->create(); + $asset = Asset::factory()->for($model, 'model')->create(); + + $asset->checkOut($user, User::factory()->superuser()->create()->id); + + Notification::assertSentTo($user, CheckoutAssetNotification::class, function ($notification) { + $content = $notification->toMail()->render(); + + return str_contains($content, 'My Custom EULA Text') && !str_contains($content, 'EULA Text that should not be used'); + }); + } } From 20fa4c39f90394ae1aaf381374e242b2035bb36d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 4 Sep 2024 12:26:44 -0700 Subject: [PATCH 3/4] adds setEula to support\settings --- tests/Support/Settings.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Support/Settings.php b/tests/Support/Settings.php index 2d499838c..e171c0ab9 100644 --- a/tests/Support/Settings.php +++ b/tests/Support/Settings.php @@ -121,6 +121,10 @@ class Settings 'ldap_basedn' => 'CN=Users,DC=ad,DC=example,Dc=com' ]); } + public function setEula($text = 'Default EULA text') + { + return $this->update(['default_eula_text' => $text]); + } /** * @param array $attributes Attributes to modify in the application's settings. From 7c8955b12620208281c449bff2ecbfe29103d466 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 4 Sep 2024 12:38:35 -0700 Subject: [PATCH 4/4] revert changes to label view --- app/View/Label.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/View/Label.php b/app/View/Label.php index 07152ccd2..886830659 100644 --- a/app/View/Label.php +++ b/app/View/Label.php @@ -158,8 +158,8 @@ class Label implements View // The end result of this will be in this format: // {labelOne} {valueOne} | {labelTwo} {valueTwo} | {labelThree} {valueThree} $previous['value'] = trim(implode(' | ', [ - implode(' ', [$previous['label'], str_replace(['{', '}'], '', $previous['value'])]), - implode(' ', [$current['label'], str_replace(['{', '}'], '', $current['value'])]), + implode(' ', [$previous['label'], $previous['value']]), + implode(' ', [$current['label'], $current['value']]), ])); // We'll set the label to an empty string since we