- E-mail intake (IMAP), optional and off by default: clients can create a ticket or reply to an existing one just by sending/replying to an e-mail. Configure any number of mailboxes in the new Admin > Poczta page (SMTP + IMAP together, replacing the old "E-MAIL" tab), each routed to a specific subcategory or a whole category (new tickets.category_id column). Replies are matched to their ticket via the number/checksum already in every notification subject; autoresponders/bounces are detected and rejected; "restrict tickets to LDAP" is enforced for e-mail like the guest web form. Manual "Pobierz teraz" per-mailbox fetch button; dedicated storage/logs/imap-*.log regardless of the app's log level; mail-icon badges on e-mail-originated tickets/messages in the operator queue and ticket view. - Operator queue: "select all" checkbox in the table header for every currently visible ticket under the active filter/tab. - Fixed: scheduled commands (SLA breach check, automation rules, and now IMAP fetch) always sent notifications through .env's default mailer instead of the configured SMTP server, because AppServiceProvider's Settings override used to skip itself for any console command, not just migrate. - Fixed: visiting a ticket that no longer exists (deleted mid-session, or a stale background refresh) showed a raw 404 instead of redirecting back to the operator queue / client dashboard. - Docs: README/ARCHITECTURE/CLAUDE/install/wiki updated for all of the above, including the previously-missing host crontab entry for schedule:run. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
|
|
|
#[Fillable(['ticket_id', 'author_name', 'internal', 'body', 'edited', 'api_client_id', 'source', 'created_at', 'updated_at'])]
|
|
class TicketMessage extends Model
|
|
{
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'internal' => 'boolean',
|
|
'edited' => 'boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* "role" and "author_id" are read-only virtual attributes derived from
|
|
* authorLink (see below) — neither is a real column anymore, so this
|
|
* keeps every existing `$message->role`/`$message->author_id` read
|
|
* working unchanged. Write via attachAuthor() instead.
|
|
*/
|
|
public function getAttribute($key)
|
|
{
|
|
if ($key === 'role') {
|
|
return $this->authorLink?->role?->key ?? 'system';
|
|
}
|
|
|
|
if ($key === 'author_id') {
|
|
return $this->authorLink?->user_id;
|
|
}
|
|
|
|
return parent::getAttribute($key);
|
|
}
|
|
|
|
public function ticket(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Ticket::class);
|
|
}
|
|
|
|
public function apiClient(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ApiClient::class);
|
|
}
|
|
|
|
/**
|
|
* Who wrote this message and in what role — replaces the old flat
|
|
* author_id/role columns. A message with no row here is a
|
|
* system-generated entry (no author, no role).
|
|
*/
|
|
public function authorLink(): HasOne
|
|
{
|
|
return $this->hasOne(TicketMessageAuthor::class);
|
|
}
|
|
|
|
public function author(): HasOneThrough
|
|
{
|
|
return $this->hasOneThrough(User::class, TicketMessageAuthor::class, 'ticket_message_id', 'id', 'id', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* Links this message to the given author + role (or does nothing for a
|
|
* system message, i.e. $roleKey === null) — the write-side counterpart
|
|
* to the role/author_id reads above, since neither is a plain column
|
|
* anymore.
|
|
*/
|
|
public function attachAuthor(?int $userId, ?string $roleKey): void
|
|
{
|
|
if ($roleKey === null) {
|
|
return;
|
|
}
|
|
|
|
$this->authorLink()->create([
|
|
'user_id' => $userId,
|
|
'role_id' => Role::query()->where('key', $roleKey)->value('id'),
|
|
]);
|
|
}
|
|
|
|
public function attachments(): HasMany
|
|
{
|
|
return $this->hasMany(TicketAttachment::class, 'message_id');
|
|
}
|
|
}
|