mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fixes for document public/private setting
This commit is contained in:
parent
eb33ee7d78
commit
67336af5c6
@ -50,7 +50,7 @@ class DocumentsTable extends Component
|
||||
{
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
$this->client = Client::withTrashed()->with('company')->find($this->client_id);
|
||||
$this->client = Client::query()->withTrashed()->with('company')->find($this->client_id);
|
||||
|
||||
$this->company = $this->client->company;
|
||||
|
||||
@ -118,12 +118,17 @@ class DocumentsTable extends Component
|
||||
|
||||
protected function documents()
|
||||
{
|
||||
return $this->client->documents();
|
||||
return Document::query()
|
||||
->where('is_public', true)
|
||||
->whereHasMorph('documentable', [Client::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
}
|
||||
|
||||
protected function credits()
|
||||
{
|
||||
return Document::query()
|
||||
->where('is_public', true)
|
||||
->whereHasMorph('documentable', [Credit::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
@ -132,6 +137,7 @@ class DocumentsTable extends Component
|
||||
protected function expenses()
|
||||
{
|
||||
return Document::query()
|
||||
->where('is_public', true)
|
||||
->whereHasMorph('documentable', [Expense::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
@ -140,6 +146,7 @@ class DocumentsTable extends Component
|
||||
protected function invoices()
|
||||
{
|
||||
return Document::query()
|
||||
->where('is_public', true)
|
||||
->whereHasMorph('documentable', [Invoice::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
@ -148,6 +155,7 @@ class DocumentsTable extends Component
|
||||
protected function payments()
|
||||
{
|
||||
return Document::query()
|
||||
->where('is_public', true)
|
||||
->whereHasMorph('documentable', [Payment::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
@ -156,6 +164,7 @@ class DocumentsTable extends Component
|
||||
protected function projects()
|
||||
{
|
||||
return Document::query()
|
||||
->where('is_public', true)
|
||||
->whereHasMorph('documentable', [Project::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
@ -164,6 +173,7 @@ class DocumentsTable extends Component
|
||||
protected function quotes()
|
||||
{
|
||||
return Document::query()
|
||||
->where('is_public', true)
|
||||
->whereHasMorph('documentable', [Quote::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
@ -172,6 +182,7 @@ class DocumentsTable extends Component
|
||||
protected function recurringInvoices()
|
||||
{
|
||||
return Document::query()
|
||||
->where('is_public', true)
|
||||
->whereHasMorph('documentable', [RecurringInvoice::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
@ -180,6 +191,7 @@ class DocumentsTable extends Component
|
||||
protected function tasks()
|
||||
{
|
||||
return Document::query()
|
||||
->where('is_public', true)
|
||||
->whereHasMorph('documentable', [Task::class], function ($query) {
|
||||
$query->where('client_id', $this->client->id);
|
||||
});
|
||||
|
@ -33,11 +33,17 @@ class StoreClientRequest extends Request
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('create', Client::class);
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('create', Client::class);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
if ($this->file('documents') && is_array($this->file('documents'))) {
|
||||
$rules['documents.*'] = $this->file_validation;
|
||||
} elseif ($this->file('documents')) {
|
||||
@ -51,7 +57,7 @@ class StoreClientRequest extends Request
|
||||
}
|
||||
|
||||
if (isset($this->number)) {
|
||||
$rules['number'] = Rule::unique('clients')->where('company_id', auth()->user()->company()->id);
|
||||
$rules['number'] = Rule::unique('clients')->where('company_id', $user->company()->id);
|
||||
}
|
||||
|
||||
$rules['country_id'] = 'integer|nullable';
|
||||
@ -81,12 +87,12 @@ class StoreClientRequest extends Request
|
||||
//'regex:/[@$!%*#?&.]/', // must contain a special character
|
||||
];
|
||||
|
||||
if (auth()->user()->company()->account->isFreeHostedClient()) {
|
||||
$rules['id'] = new CanStoreClientsRule(auth()->user()->company()->id);
|
||||
if ($user->company()->account->isFreeHostedClient()) {
|
||||
$rules['id'] = new CanStoreClientsRule($user->company()->id);
|
||||
}
|
||||
|
||||
$rules['number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', auth()->user()->company()->id)];
|
||||
$rules['id_number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', auth()->user()->company()->id)];
|
||||
$rules['number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)];
|
||||
$rules['id_number'] = ['bail', 'nullable', Rule::unique('clients')->where('company_id', $user->company()->id)];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
@ -94,7 +100,9 @@ class StoreClientRequest extends Request
|
||||
public function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
/* Default settings */
|
||||
$settings = (array)ClientSettings::defaults();
|
||||
|
||||
@ -130,10 +138,10 @@ class StoreClientRequest extends Request
|
||||
if ($group_settings && property_exists($group_settings->settings, 'currency_id') && isset($group_settings->settings->currency_id)) {
|
||||
$input['settings']['currency_id'] = (string) $group_settings->settings->currency_id;
|
||||
} else {
|
||||
$input['settings']['currency_id'] = (string) auth()->user()->company()->settings->currency_id;
|
||||
$input['settings']['currency_id'] = (string) $user->company()->settings->currency_id;
|
||||
}
|
||||
} elseif (! array_key_exists('currency_id', $input['settings'])) {
|
||||
$input['settings']['currency_id'] = (string) auth()->user()->company()->settings->currency_id;
|
||||
$input['settings']['currency_id'] = (string) $user->company()->settings->currency_id;
|
||||
}
|
||||
|
||||
if (isset($input['currency_code'])) {
|
||||
|
@ -40,6 +40,8 @@ class UpdateClientRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
/* Ensure we have a client name, and that all emails are unique*/
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
if ($this->file('documents') && is_array($this->file('documents'))) {
|
||||
$rules['documents.*'] = $this->file_validation;
|
||||
@ -58,15 +60,13 @@ class UpdateClientRequest extends Request
|
||||
$rules['size_id'] = 'integer|nullable';
|
||||
$rules['country_id'] = 'integer|nullable';
|
||||
$rules['shipping_country_id'] = 'integer|nullable';
|
||||
//$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id;
|
||||
//$rules['id_number'] = 'unique:clients,id_number,'.$this->id.',id,company_id,'.$this->company_id;
|
||||
|
||||
if ($this->id_number) {
|
||||
$rules['id_number'] = Rule::unique('clients')->where('company_id', auth()->user()->company()->id)->ignore($this->client->id);
|
||||
$rules['id_number'] = Rule::unique('clients')->where('company_id', $user->company()->id)->ignore($this->client->id);
|
||||
}
|
||||
|
||||
if ($this->number) {
|
||||
$rules['number'] = Rule::unique('clients')->where('company_id', auth()->user()->company()->id)->ignore($this->client->id);
|
||||
$rules['number'] = Rule::unique('clients')->where('company_id', $user->company()->id)->ignore($this->client->id);
|
||||
}
|
||||
|
||||
$rules['settings'] = new ValidClientGroupSettingsRule();
|
||||
@ -102,9 +102,12 @@ class UpdateClientRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
/* If the user removes the currency we must always set the default */
|
||||
if (array_key_exists('settings', $input) && ! array_key_exists('currency_id', $input['settings'])) {
|
||||
$input['settings']['currency_id'] = (string) auth()->user()->company()->settings->currency_id;
|
||||
$input['settings']['currency_id'] = (string) $user->company()->settings->currency_id;
|
||||
}
|
||||
|
||||
if (isset($input['language_code'])) {
|
||||
|
@ -109,12 +109,12 @@ trait MockAccountData
|
||||
public $recurring_quote;
|
||||
|
||||
/**
|
||||
* @var
|
||||
* @var \App\Models\Credit
|
||||
*/
|
||||
public $credit;
|
||||
|
||||
/**
|
||||
* @var
|
||||
* @var \App\Models\Invoice
|
||||
*/
|
||||
public $invoice;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user