From 83215cd0bc2476b68cbf81415e4467e4ee66bb1f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 13 Feb 2024 17:10:36 +1100 Subject: [PATCH] Improve template switching for hosted users --- app/Http/Middleware/TokenAuth.php | 2 +- app/Jobs/User/UserEmailChanged.php | 1 + app/Mail/Admin/ClientUnsubscribedObject.php | 1 + app/Mail/Admin/EntityCreatedObject.php | 4 +++- app/Mail/Admin/EntityFailedSendObject.php | 1 + app/Mail/Admin/EntityPaidObject.php | 1 + app/Mail/Admin/EntitySentObject.php | 4 ++++ app/Mail/Admin/EntityViewedObject.php | 1 + app/Mail/Admin/InventoryNotificationObject.php | 1 + app/Mail/Admin/PaymentFailureObject.php | 1 + app/Mail/Admin/PurchaseOrderAcceptedObject.php | 1 + app/Mail/Admin/QuoteApprovedObject.php | 1 + app/Mail/Admin/QuoteExpiredObject.php | 2 ++ app/Mail/Admin/ResetPasswordObject.php | 1 + app/Mail/Admin/VerifyUserObject.php | 1 + app/Mail/Client/ClientStatement.php | 2 +- .../ClientContactRequestCancellationObject.php | 1 + app/Mail/Subscription/OtpCode.php | 1 + app/Mail/TemplateEmail.php | 2 +- app/Mail/VendorTemplateEmail.php | 2 +- app/Providers/ComposerServiceProvider.php | 12 ------------ app/Services/Email/AdminEmailMailable.php | 1 + app/Services/Email/EmailDefaults.php | 6 +++--- app/Utils/TruthSource.php | 14 ++++++++++++++ resources/views/email/template/client.blade.php | 1 - tests/Feature/PaymentLink/PaymentLinkTest.php | 2 +- 26 files changed, 45 insertions(+), 22 deletions(-) diff --git a/app/Http/Middleware/TokenAuth.php b/app/Http/Middleware/TokenAuth.php index ab62859f2f9b..c6fc35662c94 100644 --- a/app/Http/Middleware/TokenAuth.php +++ b/app/Http/Middleware/TokenAuth.php @@ -67,7 +67,7 @@ class TokenAuth $truth->setUser($company_token->user); $truth->setCompany($company_token->company); $truth->setCompanyToken($company_token); - + $truth->setPremiumHosted($company_token->account->isPremium()); /* | This method binds the db to the jobs created using this | session diff --git a/app/Jobs/User/UserEmailChanged.php b/app/Jobs/User/UserEmailChanged.php index a9e017f945aa..d1e540d9be82 100644 --- a/app/Jobs/User/UserEmailChanged.php +++ b/app/Jobs/User/UserEmailChanged.php @@ -94,6 +94,7 @@ class UserEmailChanged implements ShouldQueue 'logo' => $this->company->present()->logo(), 'settings' => $this->settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; } } diff --git a/app/Mail/Admin/ClientUnsubscribedObject.php b/app/Mail/Admin/ClientUnsubscribedObject.php index eb0190ab161f..32193d3f62fd 100644 --- a/app/Mail/Admin/ClientUnsubscribedObject.php +++ b/app/Mail/Admin/ClientUnsubscribedObject.php @@ -44,6 +44,7 @@ class ClientUnsubscribedObject 'settings' => $this->company->settings, 'logo' => $this->company->present()->logo(), 'text_body' => "\n\n".ctrans('texts.client_unsubscribed_help', ['client' => $this->contact->present()->name()])."\n\n", + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; $mail_obj = new \stdClass(); diff --git a/app/Mail/Admin/EntityCreatedObject.php b/app/Mail/Admin/EntityCreatedObject.php index bc814c37e4ad..324e7aeeeea6 100644 --- a/app/Mail/Admin/EntityCreatedObject.php +++ b/app/Mail/Admin/EntityCreatedObject.php @@ -94,7 +94,8 @@ class EntityCreatedObject 'settings' => $this->company->settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, 'text_body' => str_replace(['$view_button','$viewButton','$viewLink','$view_url'], '$view_url', $content), - ]; + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', + ]; } else { $this->entity->load('client.country', 'client.company'); $this->client = $this->entity->client; @@ -181,6 +182,7 @@ class EntityCreatedObject 'settings' => $settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, 'text_body' => str_replace(['$view_button','$viewButton','$view_link','$view_button'], '$view_url', $content), + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; } } diff --git a/app/Mail/Admin/EntityFailedSendObject.php b/app/Mail/Admin/EntityFailedSendObject.php index a6c9a4775bf3..3d099d6b1c47 100644 --- a/app/Mail/Admin/EntityFailedSendObject.php +++ b/app/Mail/Admin/EntityFailedSendObject.php @@ -152,6 +152,7 @@ class EntityFailedSendObject "settings" => $settings, "whitelabel" => $this->company->account->isPaid() ? true : false, "text_body" => str_replace("
", "\n", $content), + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; return $data; diff --git a/app/Mail/Admin/EntityPaidObject.php b/app/Mail/Admin/EntityPaidObject.php index 441ab58c3a96..ed2d058fe4f4 100644 --- a/app/Mail/Admin/EntityPaidObject.php +++ b/app/Mail/Admin/EntityPaidObject.php @@ -105,6 +105,7 @@ class EntityPaidObject 'settings' => $settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, 'text_body' => $content, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; return $data; diff --git a/app/Mail/Admin/EntitySentObject.php b/app/Mail/Admin/EntitySentObject.php index 6433f0a3f223..52531daaf8fe 100644 --- a/app/Mail/Admin/EntitySentObject.php +++ b/app/Mail/Admin/EntitySentObject.php @@ -87,6 +87,8 @@ class EntitySentObject 'logo' => $this->company->present()->logo(), 'settings' => $this->company->settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', + ]; $mail_obj->markdown = 'email.admin.generic'; $mail_obj->tag = $this->company->company_key; @@ -197,6 +199,8 @@ class EntitySentObject 'settings' => $settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, 'text_body' => $content, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', + ]; } } diff --git a/app/Mail/Admin/EntityViewedObject.php b/app/Mail/Admin/EntityViewedObject.php index c88ee9547011..e3723d0ca18a 100644 --- a/app/Mail/Admin/EntityViewedObject.php +++ b/app/Mail/Admin/EntityViewedObject.php @@ -116,6 +116,7 @@ class EntityViewedObject 'settings' => $settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, 'text_body' => $content, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; return $data; diff --git a/app/Mail/Admin/InventoryNotificationObject.php b/app/Mail/Admin/InventoryNotificationObject.php index 8c40c25af0b3..66cdc909da7b 100644 --- a/app/Mail/Admin/InventoryNotificationObject.php +++ b/app/Mail/Admin/InventoryNotificationObject.php @@ -76,6 +76,7 @@ class InventoryNotificationObject 'settings' => $this->product->company->settings, 'whitelabel' => $this->product->company->account->isPaid() ? true : false, 'text_body' => $content, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; return $data; diff --git a/app/Mail/Admin/PaymentFailureObject.php b/app/Mail/Admin/PaymentFailureObject.php index bd714b54a777..fd3c9f414885 100644 --- a/app/Mail/Admin/PaymentFailureObject.php +++ b/app/Mail/Admin/PaymentFailureObject.php @@ -99,6 +99,7 @@ class PaymentFailureObject 'button' => $this->use_react_url ? ctrans('texts.view_client') : ctrans('texts.login'), 'additional_info' => $this->error, 'text_body' => $content, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; return $data; diff --git a/app/Mail/Admin/PurchaseOrderAcceptedObject.php b/app/Mail/Admin/PurchaseOrderAcceptedObject.php index a8a1caf0ed43..1f0df6bf959d 100644 --- a/app/Mail/Admin/PurchaseOrderAcceptedObject.php +++ b/app/Mail/Admin/PurchaseOrderAcceptedObject.php @@ -92,6 +92,7 @@ class PurchaseOrderAcceptedObject 'settings' => $settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, 'text_body' => $content, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; return $data; diff --git a/app/Mail/Admin/QuoteApprovedObject.php b/app/Mail/Admin/QuoteApprovedObject.php index 2e5e1e9a050d..5ea8733ae540 100644 --- a/app/Mail/Admin/QuoteApprovedObject.php +++ b/app/Mail/Admin/QuoteApprovedObject.php @@ -91,6 +91,7 @@ class QuoteApprovedObject 'settings' => $settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, 'text_body' => $content, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; return $data; diff --git a/app/Mail/Admin/QuoteExpiredObject.php b/app/Mail/Admin/QuoteExpiredObject.php index 7411949e319f..07b8e3af0144 100644 --- a/app/Mail/Admin/QuoteExpiredObject.php +++ b/app/Mail/Admin/QuoteExpiredObject.php @@ -91,6 +91,8 @@ class QuoteExpiredObject 'settings' => $settings, 'whitelabel' => $this->company->account->isPaid() ? true : false, 'text_body' => $content, + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', + ]; return $data; diff --git a/app/Mail/Admin/ResetPasswordObject.php b/app/Mail/Admin/ResetPasswordObject.php index 66668b56d631..c644ff429909 100644 --- a/app/Mail/Admin/ResetPasswordObject.php +++ b/app/Mail/Admin/ResetPasswordObject.php @@ -41,6 +41,7 @@ class ResetPasswordObject 'settings' => $this->company->settings, 'logo' => $this->company->present()->logo(), 'text_body' => ctrans('texts.reset_password'), + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; $mail_obj = new \stdClass(); diff --git a/app/Mail/Admin/VerifyUserObject.php b/app/Mail/Admin/VerifyUserObject.php index ea69c3fc6052..03361994b927 100644 --- a/app/Mail/Admin/VerifyUserObject.php +++ b/app/Mail/Admin/VerifyUserObject.php @@ -53,6 +53,7 @@ class VerifyUserObject 'logo' => $this->company->present()->logo(), 'signature' => $this->company->settings->email_signature, 'text_body' => ctrans('texts.confirmation_message'), + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; $mail_obj = new \stdClass(); diff --git a/app/Mail/Client/ClientStatement.php b/app/Mail/Client/ClientStatement.php index b715840083ed..d7a131fa2f0f 100644 --- a/app/Mail/Client/ClientStatement.php +++ b/app/Mail/Client/ClientStatement.php @@ -52,7 +52,7 @@ class ClientStatement extends Mailable public function content() { return new Content( - view: 'email.template.client', + view: $this->data['company']->account->isPremium() ? 'email.template.client_premium' : 'email.template.client', text: 'email.template.text', with: [ 'text_body' => $this->data['body'], diff --git a/app/Mail/RecurringInvoice/ClientContactRequestCancellationObject.php b/app/Mail/RecurringInvoice/ClientContactRequestCancellationObject.php index bd16c701f9f5..19c07ec424ce 100644 --- a/app/Mail/RecurringInvoice/ClientContactRequestCancellationObject.php +++ b/app/Mail/RecurringInvoice/ClientContactRequestCancellationObject.php @@ -48,6 +48,7 @@ class ClientContactRequestCancellationObject 'signature' => $this->company->settings->email_signature, 'settings' => $this->company->settings, 'logo' => $this->company->present()->logo(), + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]; $mail_obj = new \stdClass(); diff --git a/app/Mail/Subscription/OtpCode.php b/app/Mail/Subscription/OtpCode.php index b97f7fb1dd28..28fd20fe72e7 100644 --- a/app/Mail/Subscription/OtpCode.php +++ b/app/Mail/Subscription/OtpCode.php @@ -58,6 +58,7 @@ class OtpCode extends Mailable 'title' => ctrans('texts.otp_code_subject'), 'content' => ctrans('texts.otp_code_body', ['code' => $this->code]), 'whitelabel' => $this->company->account->isPaid(), + 'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ]); } } diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 90352e00b68e..84814520e9db 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -75,7 +75,7 @@ class TemplateEmail extends Mailable $template_name = 'email.template.'.$this->build_email->getTemplate(); if ($this->build_email->getTemplate() == 'light' || $this->build_email->getTemplate() == 'dark') { - $template_name = 'email.template.client'; + $template_name = $this->company->account->isPremium() ? 'email.template.client_premium' : 'email.template.client'; } if ($this->build_email->getTemplate() == 'custom') { diff --git a/app/Mail/VendorTemplateEmail.php b/app/Mail/VendorTemplateEmail.php index 18e491491bab..593d711e7cf4 100644 --- a/app/Mail/VendorTemplateEmail.php +++ b/app/Mail/VendorTemplateEmail.php @@ -72,7 +72,7 @@ class VendorTemplateEmail extends Mailable $template_name = 'email.template.'.$this->build_email->getTemplate(); if ($this->build_email->getTemplate() == 'light' || $this->build_email->getTemplate() == 'dark') { - $template_name = 'email.template.client'; + $template_name = $this->company->account->isPremium() ? 'email.template.client_premium' : 'email.template.client'; } if ($this->build_email->getTemplate() == 'custom') { diff --git a/app/Providers/ComposerServiceProvider.php b/app/Providers/ComposerServiceProvider.php index 4f71bdf6a2a6..7c8199142f9e 100644 --- a/app/Providers/ComposerServiceProvider.php +++ b/app/Providers/ComposerServiceProvider.php @@ -24,18 +24,6 @@ class ComposerServiceProvider extends ServiceProvider public function boot() { view()->composer('portal.*', PortalComposer::class); - - // view()->composer( - // ['email.admin.generic', 'email.client.generic'], - // function ($view) { - // $view->with( - // 'template', - // Ninja::isHosted() - // ); - // } - // ); - - } /** diff --git a/app/Services/Email/AdminEmailMailable.php b/app/Services/Email/AdminEmailMailable.php index 7745a9b48e7e..eb90be6cb915 100644 --- a/app/Services/Email/AdminEmailMailable.php +++ b/app/Services/Email/AdminEmailMailable.php @@ -68,6 +68,7 @@ class AdminEmailMailable extends Mailable 'logo' => $this->email_object->company->present()->logo(), 'settings' => $this->email_object->settings, 'whitelabel' => $this->email_object->company->account->isPaid() ? true : false, + 'template' => $this->email_object->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin', ] ); } diff --git a/app/Services/Email/EmailDefaults.php b/app/Services/Email/EmailDefaults.php index 9aadd3cd2ac5..033b2ad77478 100644 --- a/app/Services/Email/EmailDefaults.php +++ b/app/Services/Email/EmailDefaults.php @@ -107,10 +107,10 @@ class EmailDefaults match ($this->email->email_object->settings->email_style) { 'plain' => $this->template = 'email.template.plain', - 'light' => $this->template = 'email.template.client', - 'dark' => $this->template = 'email.template.client', + 'light' => $this->template = $this->email->email_object->company->account->isPremium() ? 'email.template.client_premium' : 'email.template.client', + 'dark' => $this->template = $this->email->email_object->company->account->isPremium() ? 'email.template.client_premium' :'email.template.client', 'custom' => $this->template = 'email.template.custom', - default => $this->template = 'email.template.client', + default => $this->template = $this->email->email_object->company->account->isPremium() ? 'email.template.client_premium' :'email.template.client', }; $this->email->email_object->html_template = $this->template; diff --git a/app/Utils/TruthSource.php b/app/Utils/TruthSource.php index c4f732f34be9..fe294d0b3158 100644 --- a/app/Utils/TruthSource.php +++ b/app/Utils/TruthSource.php @@ -21,6 +21,15 @@ class TruthSource public $company_token; + public $premium_hosted; + + public function setPremiumHosted($premium_hosted) + { + $this->premium_hosted = $premium_hosted; + + return $this; + } + public function setCompanyUser($company_user) { $this->company_user = $company_user; @@ -49,6 +58,11 @@ class TruthSource return $this; } + public function getPremiumHosted() + { + return $this->premium_hosted; + } + public function getCompany() { return $this->company; diff --git a/resources/views/email/template/client.blade.php b/resources/views/email/template/client.blade.php index f13a3572b40a..e73dfa3630bd 100644 --- a/resources/views/email/template/client.blade.php +++ b/resources/views/email/template/client.blade.php @@ -3,7 +3,6 @@ $email_alignment = isset($settings->email_alignment) ? $settings->email_alignment : 'center'; @endphp - diff --git a/tests/Feature/PaymentLink/PaymentLinkTest.php b/tests/Feature/PaymentLink/PaymentLinkTest.php index 9695b0d57e9f..de5755c177c8 100644 --- a/tests/Feature/PaymentLink/PaymentLinkTest.php +++ b/tests/Feature/PaymentLink/PaymentLinkTest.php @@ -9,7 +9,7 @@ * @license https://www.elastic.co/licensing/elastic-license */ -namespace Tests\Feature; +namespace Tests\Feature\PaymentLink; use Tests\TestCase; use App\Models\Invoice;