diff --git a/app/Http/Controllers/Api/UploadedFilesController.php b/app/Http/Controllers/Api/UploadedFilesController.php index 5278dea6cd..787a6669b4 100644 --- a/app/Http/Controllers/Api/UploadedFilesController.php +++ b/app/Http/Controllers/Api/UploadedFilesController.php @@ -113,12 +113,15 @@ class UploadedFilesController extends Controller $object->logUpload($file_name, $request->input('notes')); } - $files = Actionlog::select('action_logs.*')->where('action_type', '=', 'uploaded') - ->where('item_type', '=', self::$map_object_type[$object_type]) - ->where('item_id', '=', $id)->whereIn('filename', $files) - ->get(); + if ($files) { + $file_results = Actionlog::select('action_logs.*')->where('action_type', '=', 'uploaded') + ->where('item_type', '=', self::$map_object_type[$object_type]) + ->where('item_id', '=', $id)->whereIn('filename', $files) + ->get(); + + return response()->json(Helper::formatStandardApiResponse('success', (new UploadedFilesTransformer())->transformFiles($file_results, count($file_results)), trans_choice('general.file_upload_status.upload.success', count($files)))); + } - return response()->json(Helper::formatStandardApiResponse('success', (new UploadedFilesTransformer())->transformFiles($files, count($files)), trans_choice('general.file_upload_status.upload.success', count($files)))); } // No files were submitted diff --git a/app/Models/Traits/Loggable.php b/app/Models/Traits/Loggable.php index 4ea08c1525..d38ac4066f 100644 --- a/app/Models/Traits/Loggable.php +++ b/app/Models/Traits/Loggable.php @@ -10,10 +10,12 @@ use App\Models\Location; use App\Models\Setting; use App\Models\User; use App\Notifications\AuditNotification; +use GuzzleHttp\Exception\ConnectException; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use Osama\LaravelTeamsNotification\TeamsNotification; +use Throwable; trait Loggable { @@ -282,10 +284,29 @@ trait Loggable 'location' => ($location) ? $location->name : '', 'note' => $note, ]; + if(Setting::getSettings()->webhook_selected === 'microsoft' && Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) { - $message = AuditNotification::toMicrosoftTeams($params); - $notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint); - $notification->success()->sendMessage($message[0], $message[1]); + + $endpoint = Setting::getSettings()->webhook_endpoint; + + try { + $message = AuditNotification::toMicrosoftTeams($params); + $notification = new TeamsNotification($endpoint); + $notification->success()->sendMessage($message[0], $message[1]); + + } catch (ConnectException $e) { + Log::warning('Teams webhook connection failed', [ + 'endpoint' => $endpoint, + 'error' => $e->getMessage(), + ]); + + } catch (Throwable $e) { + Log::error('Teams webhook failed unexpectedly', [ + 'endpoint' => $endpoint, + 'exception' => get_class($e), + 'error' => $e->getMessage(), + ]); + } } else { Setting::getSettings()->notify(new AuditNotification($params));