Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions ProcessMaker/Events/SecurityLogDownloadFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace ProcessMaker\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use ProcessMaker\Models\User;

class SecurityLogDownloadFailed implements ShouldBroadcastNow
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

public $user;

private bool $success;

private ?string $link;

private ?string $message;

/**
* Create a new event instance.
*
* @param User $user
* @param bool $success
* @param string $message
* @param string|null $link
*/
public function __construct(User $user, bool $success, string $message, string $link = null)
{
$this->user = $user;
$this->success = $success;
$this->message = $message;
$this->link = $link;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel("ProcessMaker.Models.User.{$this->user->id}");
}

/**
* Set the event name
*
* @return string
*/
public function broadcastAs()
{
return 'SecurityLogDownloadFailed';
}

/**
* Set the data to broadcast with this event
*
* @return array
*/
public function broadcastWith()
{
return [
'success' => $this->success,
'message' => $this->message,
'link' => $this->link,
];
}
}
4 changes: 3 additions & 1 deletion ProcessMaker/Events/SecurityLogDownloadJobCompleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

class SecurityLogDownloadJobCompleted implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

public $user;

Expand Down
17 changes: 13 additions & 4 deletions ProcessMaker/Http/Controllers/Api/SecurityLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use ProcessMaker\Http\Resources\ApiResource;
use ProcessMaker\Http\Resources\SecurityLogs;
use ProcessMaker\Jobs\DownloadSecurityLog;
use ProcessMaker\Models\Media;
use ProcessMaker\Models\SecurityLog;
use ProcessMaker\Models\User;

Expand Down Expand Up @@ -129,7 +130,7 @@ public function store(Request $request)
{
$request->validate(SecurityLog::rules());

$securityLog = new SecurityLog;
$securityLog = new SecurityLog();
$fields = SensitiveDataHelper::parseArray($request->json()->all());
$securityLog->fill($fields);
$securityLog->saveOrFail();
Expand All @@ -139,17 +140,25 @@ public function store(Request $request)

private function download(Request $request, User $user = null)
{
if (!Media::s3IsReady()) {
return response()->json([
'success' => false,
'message' => __('Sorry, this feature requires the configured AWS S3 service. Please contact the administrator.')
]);
}
$request->validate([
'format' => 'required|string|in:xml,csv',
]);
sleep(1);
$sessionUser = Auth::user();

// Call the Event
DownloadSecurityLog::dispatch($sessionUser, $request->input('format'), $user ? $user->id : null)
->delay(now()->addSeconds(5));

return response()->json([
'message' => __('The log file is being prepared and will be sent to your email as soon as it is ready.'),
], 200);
'success' => true,
'message' => __('The file is processing... Please wait for an alert with the download link.')
]);
}

public function downloadForAllUsers(Request $request)
Expand Down
Loading