1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00

Add validation for is_public across entities

This commit is contained in:
David Bomba 2023-08-20 14:36:22 +10:00
parent 07d71b43fe
commit dc63ead58c
24 changed files with 249 additions and 47 deletions

View File

@ -41,6 +41,20 @@ class UploadBankIntegrationRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -41,6 +41,20 @@ class UploadBankTransactionRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -41,6 +41,20 @@ class UploadClientRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -41,6 +41,20 @@ class UploadCreditRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -23,6 +23,9 @@ class CreateDocumentRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('create', Document::class); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', Document::class);
} }
} }

View File

@ -22,6 +22,9 @@ class DestroyDocumentRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('edit', $this->document); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->document);
} }
} }

View File

@ -22,7 +22,10 @@ class EditDocumentRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('edit', $this->document); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->document);
} }
/** /**

View File

@ -22,7 +22,10 @@ class ShowDocumentRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('view', $this->document); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('view', $this->document);
} }
/** /**

View File

@ -46,15 +46,4 @@ class StoreDocumentRequest extends Request
$this->replace($input); $this->replace($input);
} }
/**
* Convert to boolean
*
* @param $bool
* @return bool
*/
private function toBoolean($bool): bool
{
return filter_var($bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
} }

View File

@ -41,6 +41,20 @@ class UploadExpenseRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -52,5 +52,13 @@ class UploadInvoiceRequest extends Request
public function prepareForValidation() public function prepareForValidation()
{ {
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
} }
} }

View File

@ -2,7 +2,7 @@
/** /**
* Payment Ninja (https://paymentninja.com). * Payment Ninja (https://paymentninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Payment Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Payment Ninja LLC (https://paymentninja.com)
* *
@ -41,6 +41,20 @@ class UploadPaymentRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -2,7 +2,7 @@
/** /**
* Product Ninja (https://paymentninja.com). * Product Ninja (https://paymentninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Product Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Product Ninja LLC (https://paymentninja.com)
* *
@ -40,6 +40,20 @@ class UploadProductRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -2,7 +2,7 @@
/** /**
* Project Ninja (https://paymentninja.com). * Project Ninja (https://paymentninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Project Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Project Ninja LLC (https://paymentninja.com)
* *
@ -41,6 +41,20 @@ class UploadProjectRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* Quote Ninja (https://paymentninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Quote Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */
@ -41,6 +41,20 @@ class UploadPurchaseOrderRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* Quote Ninja (https://paymentninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Quote Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */
@ -41,6 +41,20 @@ class UploadQuoteRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* Quote Ninja (https://paymentninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Quote Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */
@ -22,7 +22,10 @@ class UploadRecurringInvoiceRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('edit', $this->recurring_invoice); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->recurring_invoice);
} }
public function rules() public function rules()
@ -41,6 +44,20 @@ class UploadRecurringInvoiceRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public'])) {
$input['is_public'] = $this->toBoolean($input['is_public']);
}
$this->replace($input);
}
} }

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* Quote Ninja (https://paymentninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Quote Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */

View File

@ -199,6 +199,17 @@ class Request extends FormRequest
{ {
} }
/**
* Convert to boolean
*
* @param $bool
* @return bool
*/
public function toBoolean($bool): bool
{
return filter_var($bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
public function checkTimeLog(array $log): bool public function checkTimeLog(array $log): bool
{ {
if (count($log) == 0) { if (count($log) == 0) {

View File

@ -2,7 +2,7 @@
/** /**
* Invoice Ninja (https://paymentninja.com). * Invoice Ninja (https://paymentninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://paymentninja.com)
* *

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* Quote Ninja (https://paymentninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Quote Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */
@ -22,17 +22,30 @@ class UploadTaskRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('edit', $this->task); /** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->task);
} }
public function rules() public function rules()
{ {
$rules = []; $rules = [
'documents' => 'bail|sometimes|file|mimes:csv,png,ai,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:2000000',
if ($this->input('documents')) { 'is_public' => 'sometimes|boolean',
$rules['documents'] = 'file|mimes:csv,png,ai,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:2000000'; ];
}
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public']))
$input['is_public'] = $this->toBoolean($input['is_public']);
$this->replace($input);
}
} }

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* Quote Ninja (https://paymentninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Quote Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
* *
* @license https://www.elastic.co/licensing/elastic-license * @license https://www.elastic.co/licensing/elastic-license
*/ */
@ -41,6 +41,18 @@ class UploadVendorRequest extends Request
$rules['file'] = $this->file_validation; $rules['file'] = $this->file_validation;
} }
$rules['is_public'] = 'sometimes|boolean';
return $rules; return $rules;
} }
public function prepareForValidation()
{
$input = $this->all();
if(isset($input['is_public']))
$input['is_public'] = $this->toBoolean($input['is_public']);
$this->replace($input);
}
} }

View File

@ -2,7 +2,7 @@
/** /**
* Payment Ninja (https://paymentninja.com). * Payment Ninja (https://paymentninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. Payment Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. Payment Ninja LLC (https://paymentninja.com)
* *

View File

@ -2,7 +2,7 @@
/** /**
* payment Ninja (https://paymentninja.com). * payment Ninja (https://paymentninja.com).
* *
* @link https://github.com/paymentninja/paymentninja source repository * @link https://github.com/invoiceninja/invoiceninja source repository
* *
* @copyright Copyright (c) 2022. payment Ninja LLC (https://paymentninja.com) * @copyright Copyright (c) 2022. payment Ninja LLC (https://paymentninja.com)
* *