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