From 56fc585828b3d84c0a556fd4e3b4edd0382848de Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 19 Apr 2024 14:26:15 +1000 Subject: [PATCH] Fixes for validation --- app/Http/Requests/Request.php | 4 ++++ app/Http/Requests/Task/StoreTaskRequest.php | 1 - app/Http/Requests/Task/UpdateTaskRequest.php | 3 --- app/Mail/Engine/PaymentEmailEngine.php | 11 ++++++---- app/Services/Client/Statement.php | 4 +++- tests/Feature/TaskApiTest.php | 21 ++++++++++++++++++++ 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index 7ff32b0275d8..3c42d83dc980 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -45,6 +45,10 @@ class Request extends FormRequest $merge_rules = []; foreach ($this->all() as $key => $value) { + + if($key == 'user') + continue; + if (method_exists($this, $key)) { $merge_rules = $this->{$key}($rules); } diff --git a/app/Http/Requests/Task/StoreTaskRequest.php b/app/Http/Requests/Task/StoreTaskRequest.php index 62039f4a1ab0..b9726331d3f7 100644 --- a/app/Http/Requests/Task/StoreTaskRequest.php +++ b/app/Http/Requests/Task/StoreTaskRequest.php @@ -92,7 +92,6 @@ class StoreTaskRequest extends Request $rules['file'] = $this->fileValidation(); } - return $this->globalRules($rules); } diff --git a/app/Http/Requests/Task/UpdateTaskRequest.php b/app/Http/Requests/Task/UpdateTaskRequest.php index ef36de91aae9..11bd12ee1d92 100644 --- a/app/Http/Requests/Task/UpdateTaskRequest.php +++ b/app/Http/Requests/Task/UpdateTaskRequest.php @@ -137,9 +137,6 @@ class UpdateTaskRequest extends Request $input['time_log'] = json_encode([]); } - if(isset($input['user'])) - unset($input['user']); - $this->replace($input); } diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index 191a1a70bb0c..ed5510dd73d6 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -17,6 +17,7 @@ use App\Utils\Helpers; use App\Models\Account; use App\Models\Payment; use Illuminate\Support\Str; +use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesDates; use App\Jobs\Entity\CreateRawPdf; use Illuminate\Support\Facades\App; @@ -28,7 +29,8 @@ use App\Services\Template\TemplateAction; class PaymentEmailEngine extends BaseEmailEngine { use MakesDates; - + use MakesHash; + public $client; /** @var \App\Models\Payment $payment */ @@ -97,11 +99,12 @@ class PaymentEmailEngine extends BaseEmailEngine ->setViewLink('') ->setViewText(''); + if ($this->client->getSetting('pdf_email_attachment') !== false && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { $template_in_use = false; - - if($this->is_refund && strlen($this->payment->client->getSetting('payment_refund_design_id')) > 2) { + + if($this->is_refund && \App\Models\Design::where('id', $this->decodePrimaryKey($this->payment->client->getSetting('payment_refund_design_id')))->where('is_template', true)->exists()) { $pdf = (new TemplateAction( [$this->payment->hashed_id], $this->payment->client->getSetting('payment_refund_design_id'), @@ -118,7 +121,7 @@ class PaymentEmailEngine extends BaseEmailEngine $this->setAttachments([['file' => base64_encode($pdf), 'name' => $file_name]]); $template_in_use = true; - } elseif(!$this->is_refund && strlen($this->payment->client->getSetting('payment_receipt_design_id')) > 2) { + } elseif(!$this->is_refund && \App\Models\Design::where('id', $this->decodePrimaryKey($this->payment->client->getSetting('payment_receipt_design_id')))->where('is_template', true)->exists()) { $pdf = (new TemplateAction( [$this->payment->hashed_id], $this->payment->client->getSetting('payment_receipt_design_id'), diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index be60783c3efa..2118386d664f 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -66,7 +66,9 @@ class Statement $option_template = &$this->options['template']; - if($this->client->getSetting('statement_design_id') != '' || $option_template && $option_template != '') { + $custom_statement_template = \App\Models\Design::where('id', $this->decodePrimaryKey($this->client->getSetting('statement_design_id')))->where('is_template',true)->first(); + + if($custom_statement_template || $option_template && $option_template != '') { $variables['values']['$start_date'] = $this->translateDate($this->options['start_date'], $this->client->date_format(), $this->client->locale()); $variables['values']['$end_date'] = $this->translateDate($this->options['end_date'], $this->client->date_format(), $this->client->locale()); diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index 22ed457ceb0f..c84201a1b7d3 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -104,6 +104,27 @@ class TaskApiTest extends TestCase } } + public function testRequestRuleParsing() + { + + $data = [ + 'client_id' => $this->client->hashed_id, + 'description' => 'Test Task', + 'time_log' => '[[1681165417,1681165432,"sumtin",true],[1681165446,0]]', + 'assigned_user' => [], + 'project' => [], + 'user' => [], + // 'status' => [], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson("/api/v1/tasks", $data); + + $response->assertStatus(200); + + } public function testUserFilters() {