Skip to content

A free open source IT asset/license management system

Begin to display EULAs for all categories

Marcus Moore7bf7a87f8a9f
diff --git a/app/Mail/BulkAssetCheckoutMail.php b/app/Mail/BulkAssetCheckoutMail.php
index e3244aa1dd..4884fa7809 100644
--- a/app/Mail/BulkAssetCheckoutMail.php
+++ b/app/Mail/BulkAssetCheckoutMail.php
@@ -20,6 +20,8 @@ class BulkAssetCheckoutMail extends Mailable
public bool $requires_acceptance;
+ public Collection $assetsByCategory;
+
public function __construct(
public Collection $assets,
public Model $target,
@@ -31,6 +33,8 @@ class BulkAssetCheckoutMail extends Mailable
$this->requires_acceptance = $this->requiresAcceptance();
$this->loadCustomFieldsOnAssets();
+ $this->loadEulaOnAssets();
+ $this->sortAssetsByCategory();
}
public function envelope(): Envelope
@@ -49,7 +53,7 @@ class BulkAssetCheckoutMail extends Mailable
'requires_acceptance' => $this->requires_acceptance,
'requires_acceptance_wording' => $this->getRequiresAcceptanceWording(),
'acceptance_url' => $this->acceptanceUrl(),
- 'eula' => $this->getEula(),
+ 'singular_eula' => $this->getSingularEula(),
],
);
}
@@ -86,21 +90,19 @@ class BulkAssetCheckoutMail extends Mailable
return route('account.accept.item', $this->assets->first());
}
- private function getEula()
+ private function getSingularEula()
{
// if assets do not have the same category then return early...
$categories = $this->assets->pluck('model.category.id')->unique();
if ($categories->count() > 1) {
- return;
+ return null;
}
// if assets do have the same category then return the shared EULA
if ($categories->count() === 1) {
return $this->assets->first()->getEula();
}
-
- // @todo: if the categories use the default eula then return that
}
private function loadCustomFieldsOnAssets(): void
@@ -116,6 +118,20 @@ class BulkAssetCheckoutMail extends Mailable
});
}
+ private function loadEulaOnAssets(): void
+ {
+ $this->assets = $this->assets->map(function (Asset $asset) {
+ $asset->eula = $asset->getEula();
+
+ return $asset;
+ });
+ }
+
+ private function sortAssetsByCategory(): void
+ {
+ $this->assetsByCategory = $this->assets->groupBy(fn($asset) => $asset->model->category->id);
+ }
+
private function requiresAcceptance(): bool
{
return (bool) $this->assets->reduce(
diff --git a/resources/views/mail/markdown/bulk-asset-checkout-mail.blade.php b/resources/views/mail/markdown/bulk-asset-checkout-mail.blade.php
index 6023c2a9f6..47573f724d 100644
--- a/resources/views/mail/markdown/bulk-asset-checkout-mail.blade.php
+++ b/resources/views/mail/markdown/bulk-asset-checkout-mail.blade.php
@@ -32,16 +32,16 @@
**{{ trans('mail.additional_notes') }}**: {{ $note }}
@endif
-@if ($eula)
+@if ($singular_eula)
<x-mail::panel>
- {{ $eula }}
+ {{ $singular_eula }}
</x-mail::panel>
@endif
-
+@foreach($assetsByCategory as $group)
<x-mail::table>
| | |
| ------------- | ------------- |
-@foreach($assets as $asset)
+@foreach($group as $asset)
| **{{ trans('general.asset_tag') }}** | <a href="{{ route('hardware.show', $asset->id) }}">{{ $asset->display_name }}</a><br><small>{{trans('mail.serial').': '.$asset->serial}}</small> |
@if (isset($asset->model?->category))
| **{{ trans('general.category') }}** | {{ $asset->model->category->name }} |
@@ -68,6 +68,12 @@
| <hr> | <hr> |
@endforeach
</x-mail::table>
+@if (!$singular_eula)
+<x-mail::panel>
+{{ $group->first()->eula }}
+</x-mail::panel>
+@endif
+@endforeach
**{{ trans('general.administrator') }}**: {{ $admin->display_name }}