mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Validation for project clients
This commit is contained in:
parent
3d40df6264
commit
c7d7e71e78
@ -47,12 +47,14 @@ class StoreInvoiceRequest extends Request
|
||||
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
|
||||
}
|
||||
|
||||
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
|
||||
$rules['client_id'] = 'bail|required|exists:clients,id,company_id,'.auth()->user()->company()->id;
|
||||
|
||||
$rules['invitations.*.client_contact_id'] = 'distinct';
|
||||
|
||||
$rules['number'] = new UniqueInvoiceNumberRule($this->all());
|
||||
|
||||
$rules['project_id'] = 'bail|sometimes|' . new ValidProjectForClient($this->all());
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
@ -68,6 +70,10 @@ class StoreInvoiceRequest extends Request
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('project_id', $input) && is_string($input['project_id'])) {
|
||||
$input['project_id'] = $this->decodePrimaryKey($input['project_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) {
|
||||
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
|
||||
}
|
||||
|
55
app/Http/ValidationRules/Project/ValidProjectForClient.php
Normal file
55
app/Http/ValidationRules/Project/ValidProjectForClient.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\ValidationRules\Project;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
/**
|
||||
* Class ValidProjectForClient.
|
||||
*/
|
||||
class ValidProjectForClient implements Rule
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public $input;
|
||||
|
||||
public function __construct($input)
|
||||
{
|
||||
$this->input = $input;
|
||||
}
|
||||
/**
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
if(is_string($this->input['project_id']))
|
||||
$this->input['project_id'] = $this->decodePrimaryKey($this->input['project_id']);
|
||||
|
||||
$project = Project::findOrFail($this->input['project_id']);
|
||||
|
||||
return $project->client_id == $this->input['client_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return "Project client does not match entity client";
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user