workign comments strucuture

This commit is contained in:
Mark Gregory
2026-06-17 10:09:42 +01:00
parent 878f383f7a
commit fe05ef8104
13 changed files with 575 additions and 104 deletions
+20
View File
@@ -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) {