feat: harden admin auth and ticket workflows
- add rotating admin refresh tokens and password gates\n- expand ticket galleries, exports, and client resources\n- improve IP allocation auditing and dashboard data\n- enforce encrypted client access tokens on public routes
This commit is contained in:
@@ -5,11 +5,32 @@ namespace App\Models;
|
||||
use App\Traits\LogsActivity;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class Ticket extends Model
|
||||
{
|
||||
use HasFactory, LogsActivity;
|
||||
|
||||
public const UNRESOLVED_STATUSES = ['open', 'pending'];
|
||||
|
||||
public const STATUS_LABELS = [
|
||||
'open' => 'Mở',
|
||||
'pending' => 'Đang xử lý',
|
||||
'resolved' => 'Đã giải quyết',
|
||||
'closed' => 'Đã đóng',
|
||||
];
|
||||
|
||||
public const PRIORITY_LABELS = [
|
||||
'low' => 'Thấp',
|
||||
'medium' => 'Trung bình',
|
||||
'high' => 'Cao',
|
||||
];
|
||||
|
||||
public const ROOM_LABELS = [
|
||||
'technical' => 'Kỹ thuật',
|
||||
'sales' => 'Bán hàng',
|
||||
];
|
||||
|
||||
protected $table = 'ticket';
|
||||
|
||||
protected $fillable = [
|
||||
@@ -28,6 +49,39 @@ class Ticket extends Model
|
||||
'gallery' => 'array',
|
||||
];
|
||||
|
||||
public function priority(): ?string
|
||||
{
|
||||
$data = is_string($this->data) ? json_decode($this->data, true) : $this->data;
|
||||
|
||||
return is_array($data) ? ($data['priority'] ?? null) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, array{from: ?string, to: string, causer_type: ?string, causer_name: ?string, created_at: mixed}>
|
||||
*/
|
||||
public function statusHistory(): Collection
|
||||
{
|
||||
return ActivityLog::query()
|
||||
->where('subject_type', self::class)
|
||||
->where('subject_id', $this->id)
|
||||
->whereIn('event', ['created', 'updated'])
|
||||
->whereNotNull('new_values->status')
|
||||
->latest('id')
|
||||
->get(['old_values', 'new_values', 'causer_type', 'causer_name', 'created_at'])
|
||||
->map(fn (ActivityLog $log) => [
|
||||
'from' => $log->old_values['status'] ?? null,
|
||||
'to' => $log->new_values['status'],
|
||||
'causer_type' => $log->causer_type,
|
||||
'causer_name' => $log->causer_name,
|
||||
'created_at' => $log->created_at,
|
||||
]);
|
||||
}
|
||||
|
||||
public function roomLabel(): ?string
|
||||
{
|
||||
return $this->room ? (self::ROOM_LABELS[$this->room] ?? $this->room) : null;
|
||||
}
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Customer::class);
|
||||
|
||||
Reference in New Issue
Block a user