Fix Quote transformer. (#3165)

* Use native Laravel prepareForValidation method instead of custom sanitize

* fix quote transformer
This commit is contained in:
David Bomba 2019-12-20 22:23:09 +11:00 committed by GitHub
parent 519c1114c1
commit b0da84baa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 109 additions and 182 deletions

View File

@ -35,7 +35,6 @@ class CreateAccountRequest extends Request
*/
public function rules()
{
$this->sanitize();
return [
//'email' => 'required|string|email|max:100',
@ -49,15 +48,15 @@ class CreateAccountRequest extends Request
];
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
$input['user_agent'] = request()->server('HTTP_USER_AGENT');
$this->replace($input);
return $this->all();
}
}

View File

@ -27,15 +27,14 @@ class EditClientRequest extends Request
return auth()->user()->can('edit', $this->client);
}
public function sanitize()
{
$input = $this->all();
// public function prepareForValidation()
// {
// $input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
// //$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
// $this->replace($input);
return $this->all();
}
// }
}

View File

@ -38,7 +38,6 @@ class StoreClientRequest extends Request
public function rules()
{
$this->sanitize();
/* Ensure we have a client name, and that all emails are unique*/
//$rules['name'] = 'required|min:1';
@ -63,7 +62,7 @@ class StoreClientRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -74,9 +73,6 @@ class StoreClientRequest extends Request
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
$this->replace($input);
return $this->all();
}
public function messages()

View File

@ -34,7 +34,6 @@ class UpdateClientRequest extends Request
public function rules()
{
/* Ensure we have a client name, and that all emails are unique*/
$this->sanitize();
$rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000';
$rules['industry_id'] = 'integer|nullable';
@ -70,7 +69,7 @@ class UpdateClientRequest extends Request
];
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -80,7 +79,6 @@ class UpdateClientRequest extends Request
$this->replace($input);
return $this->all();
}
}

View File

@ -35,15 +35,13 @@ class EditCompanyRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
$this->replace($input);
}
}

View File

@ -31,9 +31,7 @@ class StoreCompanyRequest extends Request
public function rules()
{
//$this->sanitize();
$rules = [];
$input = $this->all();
//$rules['name'] = 'required';
$rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000'; // max 10000kb

View File

@ -35,15 +35,14 @@ class DestroyCompanyGatewayRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
$this->replace($input);
return $this->all();
}
}

View File

@ -35,15 +35,13 @@ class EditCompanyGatewayRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
$this->replace($input);
}
}

View File

@ -35,15 +35,13 @@ class ShowCompanyGatewayRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
$this->replace($input);
}
}

View File

@ -34,8 +34,6 @@ class StoreCompanyGatewayRequest extends Request
public function rules()
{
$this->sanitize();
$rules = [
'gateway_key' => 'required',
'fees_and_limits' => new ValidCompanyGatewayFeesAndLimitsRule(),
@ -44,7 +42,7 @@ class StoreCompanyGatewayRequest extends Request
return $rules;
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -56,7 +54,6 @@ class StoreCompanyGatewayRequest extends Request
$this->replace($input);
return $this->all();
}
}

View File

@ -34,8 +34,6 @@ class UpdateCompanyGatewayRequest extends Request
public function rules()
{
$this->sanitize();
$rules = [
'fees_and_limits' => new ValidCompanyGatewayFeesAndLimitsRule(),
];
@ -43,7 +41,7 @@ class UpdateCompanyGatewayRequest extends Request
return $rules;
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -53,8 +51,6 @@ class UpdateCompanyGatewayRequest extends Request
$input['fees_and_limits'] = $this->cleanFeesAndLimits($input['fees_and_limits']);
$this->replace($input);
return $this->all();
}
}

View File

@ -27,15 +27,5 @@ class EditGroupSettingRequest extends Request
return auth()->user()->can('edit', $this->group_setting);
}
public function sanitize()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
}
}

View File

@ -34,7 +34,6 @@ class StoreGroupSettingRequest extends Request
public function rules()
{
$this->sanitize();
$rules['name'] = 'required';
$rules['settings'] = new ValidClientGroupSettingsRule();
@ -42,7 +41,7 @@ class StoreGroupSettingRequest extends Request
return $rules;
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();

View File

@ -31,7 +31,6 @@ class UpdateGroupSettingRequest extends Request
public function rules()
{
$this->sanitize();
$rules['settings'] = new ValidClientGroupSettingsRule();
@ -39,14 +38,12 @@ class UpdateGroupSettingRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
$this->replace($input);
return $this->all();
}

View File

@ -34,16 +34,4 @@ class EditInvoiceRequest extends Request
return $rules;
}
public function sanitize()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
}
}

View File

@ -35,8 +35,6 @@ class StoreInvoiceRequest extends Request
public function rules()
{
$this->sanitize();
return [
'client_id' => 'required',
// 'invoice_type_id' => 'integer',
@ -44,7 +42,7 @@ class StoreInvoiceRequest extends Request
];
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -52,8 +50,6 @@ class StoreInvoiceRequest extends Request
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
//$input['line_items'] = json_encode($input['line_items']);
$this->replace($input);
return $this->all();
}
}

View File

@ -38,8 +38,6 @@ class UpdateInvoiceRequest extends Request
public function rules()
{
$this->sanitize();
return [
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
//'client_id' => 'required|integer',
@ -47,7 +45,7 @@ class UpdateInvoiceRequest extends Request
];
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -57,7 +55,5 @@ class UpdateInvoiceRequest extends Request
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
$this->replace($input);
return $this->all();
}
}

View File

@ -35,15 +35,13 @@ class EditPaymentRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
$this->replace($input);
}
}

View File

@ -29,7 +29,6 @@ class StoreProductRequest extends Request
public function rules()
{
$this->sanitize();
return [
'product_key' => 'required|unique:products,product_key,null,null,company_id,'.auth()->user()->companyId(),
@ -39,7 +38,7 @@ class StoreProductRequest extends Request
];
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -48,7 +47,6 @@ class StoreProductRequest extends Request
$this->replace($input);
return $this->all();
}
}

View File

@ -32,9 +32,6 @@ class UpdateProductRequest extends Request
public function rules()
{
//when updating you need to ignore the column ID
$this->sanitize();
return [
//'product_key' => 'unique:products,product_key,'.$this->product->id.',id,company_id,'.auth()->user()->companyId(),
'cost' => 'numeric',
@ -44,7 +41,7 @@ class UpdateProductRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -53,7 +50,6 @@ class UpdateProductRequest extends Request
$this->replace($input);
return $this->all();
}
}

View File

@ -35,15 +35,14 @@ class EditQuoteRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
$this->replace($input);
return $this->all();
}
}

View File

@ -38,14 +38,12 @@ class UpdateQuoteRequest extends Request
public function rules()
{
$this->sanitize();
return [
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
];
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -56,8 +54,6 @@ class UpdateQuoteRequest extends Request
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
$this->replace($input);
return $this->all();
}
}

View File

@ -35,15 +35,13 @@ class EditRecurringInvoiceRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
$this->replace($input);
}
}

View File

@ -36,7 +36,7 @@ class StoreRecurringInvoiceRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
//do post processing of RecurringInvoice request here, ie. RecurringInvoice_items
}

View File

@ -35,15 +35,13 @@ class EditRecurringQuoteRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
$this->replace($input);
}
}

View File

@ -37,16 +37,5 @@ class StoreRecurringQuoteRequest extends Request
}
public function sanitize()
{
//do post processing of RecurringQuote request here, ie. RecurringQuote_items
}
public function messages()
{
}
}

View File

@ -35,15 +35,5 @@ class EditUserRequest extends Request
}
public function sanitize()
{
$input = $this->all();
//$input['id'] = $this->encodePrimaryKey($input['id']);
//$this->replace($input);
return $this->all();
}
}

View File

@ -37,8 +37,6 @@ class StoreUserRequest extends Request
public function rules()
{
$this->sanitize();
$rules = [];
$rules['first_name'] = 'required|string|max:100';
@ -53,7 +51,7 @@ class StoreUserRequest extends Request
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -78,8 +76,6 @@ class StoreUserRequest extends Request
$this->replace($input);
return $this->all();
}

View File

@ -31,7 +31,6 @@ class UpdateUserRequest extends Request
public function rules()
{
$this->sanitize();
$input = $this->all();
$rules = [];
@ -42,7 +41,7 @@ class UpdateUserRequest extends Request
return $rules;
}
public function sanitize()
protected function prepareForValidation()
{
$input = $this->all();
@ -50,8 +49,6 @@ class UpdateUserRequest extends Request
unset($input['company_user']);
$this->replace($input);
return $this->all();
}

View File

@ -128,8 +128,6 @@ class InvoiceTransformer extends EntityTransformer
'custom_surcharge_taxes' => (bool) $invoice->custom_surcharge_taxes,
'line_items' => $invoice->line_items ?: (array)[],
'backup' => $invoice->backup ?: '',
'settings' => $invoice->settings ?: '',
];
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Transformers;
use App\Models\Quote;
use App\Models\QuoteInvitation;
use App\Utils\Traits\MakesHash;
class QuoteInvitationTransformer extends EntityTransformer
{
use MakesHash;
public function transform(QuoteInvitation $invitation)
{
return [
'id' => $this->encodePrimaryKey($invitation->id),
'client_contact_id' => $this->encodePrimaryKey($invitation->client_contact_id),
'key' => $invitation->key,
'link' => $invitation->getLink() ?: '',
'sent_date' => $invitation->sent_date ?: '',
'viewed_date' => $invitation->viewed_date ?: '',
'opened_date' => $invitation->opened_date ?: '',
];
}
}

View File

@ -12,38 +12,30 @@
namespace App\Transformers;
use App\Models\Quote;
use App\Models\QuoteInvitation;
use App\Transformers\QuoteInvitationTransformer;
use App\Utils\Traits\MakesHash;
class QuoteTransformer extends EntityTransformer
{
use MakesHash;
protected $defaultIncludes = [
// 'quote_items',
];
protected $defaultIncludes = [];
protected $availableIncludes = [
// 'invitations',
'invitations',
// 'payments',
// 'client',
// 'documents',
];
public function includeInvitations(Quote $quote)
{
$transformer = new QuoteInvitationTransformer($this->serializer);
return $this->includeCollection($quote->invitations, $transformer, QuoteInvitation::class);
}
/*
public function includequoteItems(quote $quote)
{
$transformer = new quoteItemTransformer($this->serializer);
return $this->includeCollection($quote->quote_items, $transformer, ENTITY_quote_ITEM);
}
public function includeInvitations(quote $quote)
{
$transformer = new InvitationTransformer($this->account, $this->serializer);
return $this->includeCollection($quote->invitations, $transformer, ENTITY_INVITATION);
}
public function includePayments(quote $quote)
{
$transformer = new PaymentTransformer($this->account, $this->serializer, $quote);
@ -82,44 +74,49 @@ class QuoteTransformer extends EntityTransformer
'id' => $this->encodePrimaryKey($quote->id),
'user_id' => $this->encodePrimaryKey($quote->user_id),
'assigned_user_id' => $this->encodePrimaryKey($quote->assigned_user_id),
'amount' => (float) $quote->amount ?: '',
'balance' => (float) $quote->balance ?: '',
'client_id' => (string) $quote->client_id,
'amount' => (float) $quote->amount,
'balance' => (float) $quote->balance,
'client_id' => (string) $this->encodePrimaryKey($quote->client_id),
'status_id' => (string) ($quote->status_id ?: 1),
'design_id' => (string) ($quote->design_id ?: 1),
'updated_at' => $quote->updated_at,
'archived_at' => $quote->deleted_at,
'quote_number' => $quote->quote_number ?: '',
'discount' => (float) $quote->discount ?: '',
'number' => $quote->number ?: '',
'discount' => (float) $quote->discount,
'po_number' => $quote->po_number ?: '',
'quote_date' => $quote->quote_date ?: '',
'date' => $quote->date ?: '',
'next_send_date' => $quote->date ?: '',
'valid_until' => $quote->valid_until ?: '',
'due_date' => $quote->due_date ?: '',
'terms' => $quote->terms ?: '',
'public_notes' => $quote->public_notes ?: '',
'private_notes' => $quote->private_notes ?: '',
'is_deleted' => (bool) $quote->is_deleted,
'quote_type_id' => (string) $quote->quote_type_id,
'uses_inclusive_taxes' => (bool) $quote->uses_inclusive_taxes,
'invoice_type_id' => (string) $quote->invoice_type_id ?: '',
'tax_name1' => $quote->tax_name1 ? $quote->tax_name1 : '',
'tax_rate1' => (float) $quote->tax_rate1 ?: '',
'tax_rate1' => (float) $quote->tax_rate1,
'tax_name2' => $quote->tax_name2 ? $quote->tax_name2 : '',
'tax_rate2' => (float) $quote->tax_rate2 ?: '',
'tax_rate2' => (float) $quote->tax_rate2,
'tax_name3' => $quote->tax_name3 ? $quote->tax_name3 : '',
'tax_rate3' => (float) $quote->tax_rate3 ?: '',
'tax_rate3' => (float) $quote->tax_rate3,
'total_taxes' => (float) $quote->total_taxes,
'is_amount_discount' => (bool) ($quote->is_amount_discount ?: false),
'quote_footer' => $quote->quote_footer ?: '',
'footer' => $quote->footer ?: '',
'partial' => (float) ($quote->partial ?: 0.0),
'partial_due_date' => $quote->partial_due_date ?: '',
'custom_value1' => (float) $quote->custom_value1 ?: '',
'custom_value2' => (float) $quote->custom_value2 ?: '',
'custom_taxes1' => (bool) $quote->custom_taxes1 ?: '',
'custom_taxes2' => (bool) $quote->custom_taxes2 ?: '',
'custom_value1' => (string) $quote->custom_value1 ?: '',
'custom_value2' => (string) $quote->custom_value2 ?: '',
'custom_value3' => (string) $quote->custom_value3 ?: '',
'custom_value4' => (string) $quote->custom_value4 ?: '',
'has_tasks' => (bool) $quote->has_tasks,
'has_expenses' => (bool) $quote->has_expenses,
'custom_text_value1' => $quote->custom_text_value1 ?: '',
'custom_text_value2' => $quote->custom_text_value2 ?: '',
'custom_surcharge1' => (float)$quote->custom_surcharge1,
'custom_surcharge2' => (float)$quote->custom_surcharge2,
'custom_surcharge3' => (float)$quote->custom_surcharge3,
'custom_surcharge4' => (float)$quote->custom_surcharge4,
'custom_surcharge_taxes' => (bool) $quote->custom_surcharge_taxes,
'line_items' => $quote->line_items ?: (array)[],
'backup' => $quote->backup ?: '',
'settings' => $quote->settings ?: '',
];
}
}

View File

@ -84,7 +84,6 @@ class ConstantsSeeder extends Seeder
$timezones[] = ['name'=>'Africa/Cairo', 'location' => '(GMT+02:00) Cairo', 'utc_offset' => 7200];
$timezones[] = ['name'=>'Africa/Harare', 'location' => '(GMT+02:00) Harare', 'utc_offset' => 7200];
$timezones[] = ['name'=>'Europe/Helsinki', 'location' => '(GMT+02:00) Helsinki', 'utc_offset' => 7200];
$timezones[] = ['name'=>'Europe/Istanbul', 'location' => '(GMT+02:00) Istanbul', 'utc_offset' => 7200];
$timezones[] = ['name'=>'Asia/Jerusalem', 'location' => '(GMT+02:00) Jerusalem', 'utc_offset' => 7200];
$timezones[] = ['name'=>'Europe/Kiev', 'location' => '(GMT+02:00) Kyiv', 'utc_offset' => 7200];
$timezones[] = ['name'=>'Europe/Minsk', 'location' => '(GMT+02:00) Minsk', 'utc_offset' => 7200];
@ -92,6 +91,7 @@ class ConstantsSeeder extends Seeder
$timezones[] = ['name'=>'Europe/Sofia', 'location' => '(GMT+02:00) Sofia', 'utc_offset' => 7200];
$timezones[] = ['name'=>'Europe/Tallinn', 'location' => '(GMT+02:00) Tallinn', 'utc_offset' => 7200];
$timezones[] = ['name'=>'Europe/Vilnius', 'location' => '(GMT+02:00) Vilnius', 'utc_offset' => 7200];
$timezones[] = ['name'=>'Europe/Istanbul', 'location' => '(GMT+03:00) Istanbul', 'utc_offset' => 10800];
$timezones[] = ['name'=>'Asia/Baghdad', 'location' => '(GMT+03:00) Baghdad', 'utc_offset' => 10800];
$timezones[] = ['name'=>'Asia/Kuwait', 'location' => '(GMT+03:00) Kuwait', 'utc_offset' => 10800];
$timezones[] = ['name'=>'Africa/Nairobi', 'location' => '(GMT+03:00) Nairobi', 'utc_offset' => 10800];

View File

@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true">
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>