fix: include coworkers (own business contacts) in chat targets
This commit is contained in:
@@ -78,11 +78,15 @@ class ChatController extends Controller
|
||||
$departments = CrmChannel::DEPARTMENTS;
|
||||
|
||||
// Get contacts for new conversation modal
|
||||
// Include: 1) Customer contacts (from businesses that ordered), 2) Own business contacts (coworkers)
|
||||
$customerBusinessIds = \App\Models\Order::whereHas('items.product.brand', fn ($q) => $q->where('business_id', $business->id))
|
||||
->pluck('business_id')
|
||||
->unique();
|
||||
|
||||
$contacts = \App\Models\Contact::whereIn('business_id', $customerBusinessIds)
|
||||
// Add the seller's own business ID to include coworkers
|
||||
$allBusinessIds = $customerBusinessIds->push($business->id)->unique();
|
||||
|
||||
$contacts = \App\Models\Contact::whereIn('business_id', $allBusinessIds)
|
||||
->with('business:id,name')
|
||||
->orderBy('first_name')
|
||||
->limit(200)
|
||||
@@ -224,13 +228,14 @@ class ChatController extends Controller
|
||||
'body' => 'required|string|max:10000',
|
||||
]);
|
||||
|
||||
// Get customer business IDs
|
||||
// Get allowed business IDs (customers + own business for coworkers)
|
||||
$customerBusinessIds = \App\Models\Order::whereHas('items.product.brand', fn ($q) => $q->where('business_id', $business->id))
|
||||
->pluck('business_id')
|
||||
->unique();
|
||||
$allBusinessIds = $customerBusinessIds->push($business->id)->unique();
|
||||
|
||||
// SECURITY: Verify contact belongs to a customer business
|
||||
$contact = \App\Models\Contact::whereIn('business_id', $customerBusinessIds)
|
||||
// SECURITY: Verify contact belongs to a customer business or own business (coworker)
|
||||
$contact = \App\Models\Contact::whereIn('business_id', $allBusinessIds)
|
||||
->findOrFail($validated['contact_id']);
|
||||
|
||||
$to = $validated['channel_type'] === CrmChannel::TYPE_EMAIL
|
||||
|
||||
Reference in New Issue
Block a user