Add more permissions

This commit is contained in:
Simon Pocrnjič
2025-10-31 10:16:38 +01:00
parent 7d4d18143d
commit ed4f67effb
18 changed files with 404 additions and 193 deletions
+24 -2
View File
@@ -33,6 +33,8 @@ public function __construct(
public ?int $templateId = null,
public ?int $clientCaseId = null,
public ?int $userId = null,
// If provided, update this activity on failure instead of creating a new one
public ?int $activityId = null,
) {}
/**
@@ -86,8 +88,28 @@ public function handle(SmsService $sms): void
clientReference: $this->clientReference,
);
}
// If invoked from the case UI with a selected template, create an Activity
if ($this->templateId && $this->clientCaseId && $log) {
// Update an existing pre-created activity ONLY on failure when activityId is provided
if ($this->activityId && $log && ($log->status === 'failed')) {
try {
$activity = \App\Models\Activity::find($this->activityId);
if ($activity) {
$note = (string) ($activity->note ?? '');
$append = sprintf(
' | Napaka: %s',
'SMS ni bil poslan!'
);
$activity->update(['note' => $note.$append]);
}
} catch (\Throwable $e) {
\Log::warning('SendSmsJob activity update failed', [
'error' => $e->getMessage(),
'activity_id' => $this->activityId,
]);
}
}
// If no pre-created activity is provided and invoked from the case UI with a selected template, create an Activity
if (!$this->activityId && $this->templateId && $this->clientCaseId && $log) {
try {
/** @var SmsTemplate|null $template */
$template = SmsTemplate::find($this->templateId);