Merge pull request #15445 from Godmartinz/eula_confusion
Some checks are pending
Crowdin Action / upload-sources-to-crowdin (push) Waiting to run
Docker images (Alpine) / docker (push) Waiting to run
Docker images / docker (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Waiting to run
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Waiting to run

Fixed priority for category eula vs default eula
This commit is contained in:
snipe 2024-09-10 11:04:58 +01:00 committed by GitHub
commit f6bf2d03c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 2 deletions

View file

@ -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;
}
}

View file

@ -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.

View file

@ -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');
});
}
}