diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php index b18360285b73..87772f3ab2c6 100644 --- a/app/Http/Controllers/EmailController.php +++ b/app/Http/Controllers/EmailController.php @@ -130,18 +130,15 @@ class EmailController extends BaseController $mo->subject = strlen($subject) > 3 ? $subject : null; $mo->body = strlen($body) > 3 ? $body : null; $mo->entity_id = $request->input('entity_id'); - $mo->template = $template; //full template name in use + $mo->template = $request->input('template'); //full template name in use $mo->entity_class = $this->resolveClass($entity); - $mo->email_template_body = $template; - $mo->email_template_subject = str_replace("template", "subject", $template); + $mo->email_template_body = $request->input('template'); + $mo->email_template_subject = str_replace("template", "subject", $request->input('template')); - if (Ninja::isHosted() && !$entity_obj->company->account->account_sms_verified) { - return response(['message' => 'Please verify your account to send emails.'], 400); - } - - if ($entity == 'purchaseOrder' || $entity == 'purchase_order' || $template == 'purchase_order' || $entity == 'App\Models\PurchaseOrder') { - return $this->sendPurchaseOrder($entity_obj, $data, $template); - } + + // if ($entity == 'purchaseOrder' || $entity == 'purchase_order' || $template == 'purchase_order' || $entity == 'App\Models\PurchaseOrder') { + // return $this->sendPurchaseOrder($entity_obj, $data, $template); + // } $entity_obj->invitations->each(function ($invitation) use ($data, $entity_obj, $template, $mo) { if (! $invitation->contact->trashed() && $invitation->contact->email) { diff --git a/app/Http/Requests/Email/SendEmailRequest.php b/app/Http/Requests/Email/SendEmailRequest.php index bc5ec63d6ef0..9ccc6be5b080 100644 --- a/app/Http/Requests/Email/SendEmailRequest.php +++ b/app/Http/Requests/Email/SendEmailRequest.php @@ -12,13 +12,16 @@ namespace App\Http\Requests\Email; use App\Http\Requests\Request; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Support\Str; class SendEmailRequest extends Request { use MakesHash; + private string $error_message = ''; /** * Determine if the user is authorized to make this request. * @@ -78,7 +81,14 @@ class SendEmailRequest extends Request private function checkUserAbleToSend() { $input = $this->all(); + + + if (Ninja::isHosted() && !auth()->user()->company()->account->account_sms_verified) { + $this->error_message = ctrans('texts.authorization_sms_failure'); + return false; + } + /*Make sure we have all the require ingredients to send a template*/ if (array_key_exists('entity', $input) && array_key_exists('entity_id', $input) && is_string($input['entity']) && $input['entity_id']) { $company = auth()->user()->company(); @@ -96,4 +106,9 @@ class SendEmailRequest extends Request return false; } + + protected function failedAuthorization() + { + throw new AuthorizationException($this->error_message); + } } diff --git a/app/Services/Email/EmailDefaults.php b/app/Services/Email/EmailDefaults.php index 0178a8b7cee9..65f77c6e61bc 100644 --- a/app/Services/Email/EmailDefaults.php +++ b/app/Services/Email/EmailDefaults.php @@ -147,7 +147,7 @@ class EmailDefaults * Sets the body of the email */ private function setBody(): self - { + {nlog($this->email->email_object->email_template_body); if ($this->email->email_object->body) { // A Custom Message has been set in the email screen. return $this; diff --git a/app/Services/Scheduler/SchedulerService.php b/app/Services/Scheduler/SchedulerService.php index 50a2cf67af44..eacd84b0e926 100644 --- a/app/Services/Scheduler/SchedulerService.php +++ b/app/Services/Scheduler/SchedulerService.php @@ -38,7 +38,8 @@ class SchedulerService */ public function runTask(): void { - $this->{$this->scheduler->template}(); + if(method_exists($this, $this->scheduler->template)) + $this->{$this->scheduler->template}(); } private function email_statement() diff --git a/lang/en/texts.php b/lang/en/texts.php index ff03778970f7..a72d217ab0cb 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5012,6 +5012,8 @@ $LANG = array( 'add_stripe' => 'Add Stripe', 'invalid_coupon' => 'Invalid Coupon', 'no_assigned_tasks' => 'No billable tasks for this project', + 'authorization_failure' => 'Insufficient permissions to perform this action', + 'authorization_sms_failure' => 'Please verify your account to send emails.', ); diff --git a/phpstan.neon b/phpstan.neon index 6f69d51b9a6b..35447fb94664 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: level: 6 paths: - - app - - tests + - app + - tests