From 6fbaf4bfc37a7bc63bdae939fb350424e3ed70f4 Mon Sep 17 00:00:00 2001 From: Antoine Le Gonidec Date: Mon, 8 Jul 2024 17:35:23 +0200 Subject: [PATCH] Display all Customers when using an admin account --- .../views/conversations/search.blade.php | 175 ++++++++++++++++++ .../partials/customers_table.blade.php | 26 +++ .../Controllers/ConversationsController.php | 11 +- src/Http/Controllers/CustomersController.php | 2 +- 4 files changed, 209 insertions(+), 5 deletions(-) create mode 100644 resources/views/conversations/search.blade.php create mode 100644 resources/views/customers/partials/customers_table.blade.php diff --git a/resources/views/conversations/search.blade.php b/resources/views/conversations/search.blade.php new file mode 100644 index 0000000..494be29 --- /dev/null +++ b/resources/views/conversations/search.blade.php @@ -0,0 +1,175 @@ +@extends('layouts.app') + +@section('title', ($q ? $q.' - ' : '').strip_tags(Eventy::filter('search.title', __('Search')))) +@section('body_class', 'body-search') + +@section('sidebar') + @include('partials/sidebar_menu_toggle') + + +@endsection + +@section('content') + + + +
+ + @if ($mode == App\Conversation::SEARCH_MODE_CONV) + @include('conversations/conversations_table', ['mailbox' => $search_mailbox, 'params' => ['target_blank' => true, 'show_mailbox' => (count(Auth::user()->mailboxesCanView(true)) > 1)]]) + @else + @include('freescout-restricted-customers::customers/partials/customers_table') + @endif +
+@endsection + +@include('partials/include_datepicker') + +@section('javascript') + @parent + searchInit(); +@endsection diff --git a/resources/views/customers/partials/customers_table.blade.php b/resources/views/customers/partials/customers_table.blade.php new file mode 100644 index 0000000..e70eb3c --- /dev/null +++ b/resources/views/customers/partials/customers_table.blade.php @@ -0,0 +1,26 @@ +@if (count($customers)) +
+ + + @if ($customers->lastPage() > 1) +
+ {{ $customers->links('conversations/conversations_pagination') }} +
+ @endif +
+@else + @include('partials/empty', ['empty_text' => __('No customers found')]) +@endif diff --git a/src/Http/Controllers/ConversationsController.php b/src/Http/Controllers/ConversationsController.php index d30a511..c8ce45b 100644 --- a/src/Http/Controllers/ConversationsController.php +++ b/src/Http/Controllers/ConversationsController.php @@ -7,6 +7,7 @@ namespace MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers; use App\Conversation; +use App\User; use Illuminate\Http\Request; use App\Http\Controllers\ConversationsController as BaseConversationsController; use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer; @@ -90,7 +91,7 @@ class ConversationsController extends BaseConversationsController { $search_mailbox = $mailboxes[0]; } - return view('conversations/search', [ + return view('freescout-restricted-customers::conversations/search', [ 'folder' => $folder, 'q' => $request->q, 'filters' => $filters, @@ -154,9 +155,11 @@ class ConversationsController extends BaseConversationsController { $query->orWhere('customers.phones', $like_op, '%"'.$phone_numeric.'"%'); } - }) - // Restrict the query to the Customers the current User is allowed to access. - ->whereIn('customers.mailbox_id', $mailbox_ids); + }); + // Restrict the query to the Customers the current User is allowed to access. + if ( $user->role != User::ROLE_ADMIN ) { + $query_customers->whereIn('customers.mailbox_id', $mailbox_ids); + } if (!empty($filters['mailbox']) && in_array($filters['mailbox'], $mailbox_ids)) { $query_customers->where('customers.mailbox_id', '=', $filters['mailbox']); diff --git a/src/Http/Controllers/CustomersController.php b/src/Http/Controllers/CustomersController.php index 59e2a7b..8a59737 100644 --- a/src/Http/Controllers/CustomersController.php +++ b/src/Http/Controllers/CustomersController.php @@ -377,7 +377,7 @@ class CustomersController extends BaseCustomersController { $response['status'] = 'success'; - $response['html'] = view('customers/partials/customers_table', [ + $response['html'] = view('freescout-restricted-customers::customers/partials/customers_table', [ 'customers' => $customers, ])->render(); break;