Fixes for phpstan

This commit is contained in:
David Bomba 2023-03-08 17:43:52 +11:00
parent 5dacc04295
commit 3ef2591b38
6 changed files with 29 additions and 14 deletions

View File

@ -130,18 +130,15 @@ class EmailController extends BaseController
$mo->subject = strlen($subject) > 3 ? $subject : null; $mo->subject = strlen($subject) > 3 ? $subject : null;
$mo->body = strlen($body) > 3 ? $body : null; $mo->body = strlen($body) > 3 ? $body : null;
$mo->entity_id = $request->input('entity_id'); $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->entity_class = $this->resolveClass($entity);
$mo->email_template_body = $template; $mo->email_template_body = $request->input('template');
$mo->email_template_subject = str_replace("template", "subject", $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) { $entity_obj->invitations->each(function ($invitation) use ($data, $entity_obj, $template, $mo) {
if (! $invitation->contact->trashed() && $invitation->contact->email) { if (! $invitation->contact->trashed() && $invitation->contact->email) {

View File

@ -12,13 +12,16 @@
namespace App\Http\Requests\Email; namespace App\Http\Requests\Email;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Support\Str; use Illuminate\Support\Str;
class SendEmailRequest extends Request class SendEmailRequest extends Request
{ {
use MakesHash; use MakesHash;
private string $error_message = '';
/** /**
* Determine if the user is authorized to make this request. * Determine if the user is authorized to make this request.
* *
@ -78,7 +81,14 @@ class SendEmailRequest extends Request
private function checkUserAbleToSend() private function checkUserAbleToSend()
{ {
$input = $this->all(); $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*/ /*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']) { if (array_key_exists('entity', $input) && array_key_exists('entity_id', $input) && is_string($input['entity']) && $input['entity_id']) {
$company = auth()->user()->company(); $company = auth()->user()->company();
@ -96,4 +106,9 @@ class SendEmailRequest extends Request
return false; return false;
} }
protected function failedAuthorization()
{
throw new AuthorizationException($this->error_message);
}
} }

View File

@ -147,7 +147,7 @@ class EmailDefaults
* Sets the body of the email * Sets the body of the email
*/ */
private function setBody(): self private function setBody(): self
{ {nlog($this->email->email_object->email_template_body);
if ($this->email->email_object->body) { if ($this->email->email_object->body) {
// A Custom Message has been set in the email screen. // A Custom Message has been set in the email screen.
return $this; return $this;

View File

@ -38,7 +38,8 @@ class SchedulerService
*/ */
public function runTask(): void public function runTask(): void
{ {
$this->{$this->scheduler->template}(); if(method_exists($this, $this->scheduler->template))
$this->{$this->scheduler->template}();
} }
private function email_statement() private function email_statement()

View File

@ -5012,6 +5012,8 @@ $LANG = array(
'add_stripe' => 'Add Stripe', 'add_stripe' => 'Add Stripe',
'invalid_coupon' => 'Invalid Coupon', 'invalid_coupon' => 'Invalid Coupon',
'no_assigned_tasks' => 'No billable tasks for this project', '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.',
); );

View File

@ -1,5 +1,5 @@
parameters: parameters:
level: 6 level: 6
paths: paths:
- app - app
- tests - tests