From 6e89affc936453ec93c9b7088f66cd9ab3c7cc43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Sat, 9 May 2020 00:21:35 +0200 Subject: [PATCH] Scope LiveWire components to company (#3679) --- app/Http/Livewire/CreditsTable.php | 1 + app/Http/Livewire/InvoicesTable.php | 5 +++-- app/Http/Livewire/PaymentMethodsTable.php | 1 + app/Http/Livewire/PaymentsTable.php | 1 + app/Http/Livewire/QuotesTable.php | 3 ++- app/Http/Livewire/RecurringInvoicesTable.php | 3 +-- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Http/Livewire/CreditsTable.php b/app/Http/Livewire/CreditsTable.php index 443b46b1ef..6f51d16e53 100644 --- a/app/Http/Livewire/CreditsTable.php +++ b/app/Http/Livewire/CreditsTable.php @@ -17,6 +17,7 @@ class CreditsTable extends Component public function render() { $query = Credit::query() + ->where('company_id', auth('contact')->user()->company->id) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/app/Http/Livewire/InvoicesTable.php b/app/Http/Livewire/InvoicesTable.php index e400047986..ffab5cb399 100644 --- a/app/Http/Livewire/InvoicesTable.php +++ b/app/Http/Livewire/InvoicesTable.php @@ -30,8 +30,9 @@ class InvoicesTable extends Component public function render() { - $query = Invoice::query(); - $query = $query->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); + $query = Invoice::query() + ->where('company_id', auth('contact')->user()->company->id) + ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); if (in_array('paid', $this->status)) { $query = $query->orWhere('status_id', Invoice::STATUS_PAID); diff --git a/app/Http/Livewire/PaymentMethodsTable.php b/app/Http/Livewire/PaymentMethodsTable.php index 8b0c798ac2..a8fca8c73a 100644 --- a/app/Http/Livewire/PaymentMethodsTable.php +++ b/app/Http/Livewire/PaymentMethodsTable.php @@ -24,6 +24,7 @@ class PaymentMethodsTable extends Component { $query = ClientGatewayToken::query() ->with('gateway_type') + ->where('company_id', auth('contact')->user()->company->id) ->where('client_id', $this->client->id) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/app/Http/Livewire/PaymentsTable.php b/app/Http/Livewire/PaymentsTable.php index 78cba62e7a..0b2b3b81e7 100644 --- a/app/Http/Livewire/PaymentsTable.php +++ b/app/Http/Livewire/PaymentsTable.php @@ -24,6 +24,7 @@ class PaymentsTable extends Component { $query = Payment::query() ->with('type', 'client') + ->where('company_id', auth('contact')->user()->company->id) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->paginate($this->per_page); diff --git a/app/Http/Livewire/QuotesTable.php b/app/Http/Livewire/QuotesTable.php index bb350ddf71..a32a659826 100644 --- a/app/Http/Livewire/QuotesTable.php +++ b/app/Http/Livewire/QuotesTable.php @@ -27,7 +27,8 @@ class QuotesTable extends Component public function render() { $query = Quote::query() - ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); + ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') + ->where('company_id', auth('contact')->user()->company->id); if (in_array('draft', $this->status)) { $query = $query->orWhere('status_id', Quote::STATUS_DRAFT); diff --git a/app/Http/Livewire/RecurringInvoicesTable.php b/app/Http/Livewire/RecurringInvoicesTable.php index 9dc2830c98..d4e4e3dceb 100644 --- a/app/Http/Livewire/RecurringInvoicesTable.php +++ b/app/Http/Livewire/RecurringInvoicesTable.php @@ -17,9 +17,8 @@ class RecurringInvoicesTable extends Component { $query = RecurringInvoice::query(); - // ->whereClientId(auth()->user()->client->id) // auth()->user() null. - $query = $query + ->where('company_id', auth('contact')->user()->company->id) ->whereIn('status_id', [RecurringInvoice::STATUS_PENDING, RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_COMPLETED]) ->orderBy('status_id', 'asc') ->with('client')