workign comments strucuture
This commit is contained in:
@@ -11,6 +11,7 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
@@ -302,6 +303,9 @@ final class TicketShow extends Component
|
||||
|
||||
$comments = Comment::query()
|
||||
->where('ticket_id', $ticket->id)
|
||||
->when(! $this->canSeeInternalNotes(), static function ($query): void {
|
||||
$query->where('is_internal', false);
|
||||
})
|
||||
->with(['user.company', 'attachments'])
|
||||
->oldest()
|
||||
->get();
|
||||
@@ -381,6 +385,22 @@ final class TicketShow extends Component
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* MPBA/core-company users can see internal notes. Other tenants only see public comments.
|
||||
*/
|
||||
private function canSeeInternalNotes(): bool
|
||||
{
|
||||
$company = Auth::user()?->company;
|
||||
|
||||
if ($company === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) ($company->is_system_company ?? false)
|
||||
|| Str::lower((string) ($company->slug ?? '')) === 'mpba-limited'
|
||||
|| Str::contains(Str::lower((string) ($company->name ?? '')), 'mpba');
|
||||
}
|
||||
|
||||
private function buildCommentTree(Collection $grouped, ?int $parentId = null): Collection
|
||||
{
|
||||
return $grouped->get($parentId, collect())->map(function ($comment) use ($grouped) {
|
||||
|
||||
Reference in New Issue
Block a user