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
3 changes: 1 addition & 2 deletions ProcessMaker/Events/TemplateDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(ProcessTemplates $template)
public function getData(): array
{
return [
'template_name' => $this->template->name,
'name' => $this->template->name,
'deleted_at' => Carbon::now(),
];
}
Expand All @@ -45,7 +45,6 @@ public function getChanges(): array
{
return [
'id' => $this->template->id,
'template_name' => $this->template->name,
];
}

Expand Down
24 changes: 15 additions & 9 deletions ProcessMaker/Events/TemplateUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
use Illuminate\Foundation\Events\Dispatchable;
use ProcessMaker\Contracts\SecurityLogEventInterface;
use ProcessMaker\Helpers\ArrayHelper;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessCategory;
use ProcessMaker\Models\ProcessTemplates;
use ProcessMaker\Traits\FormatSecurityLogChanges;

class TemplateUpdated implements SecurityLogEventInterface
{
use Dispatchable;
use FormatSecurityLogChanges;

private Process|ProcessTemplates $process;
private array $changes;

private array $original;
Expand All @@ -25,11 +28,16 @@ class TemplateUpdated implements SecurityLogEventInterface
*
* @return void
*/
public function __construct(array $changes, array $original, bool $processType)
{
public function __construct(
array $changes,
array $original,
bool $processType,
Process|ProcessTemplates $process = null
) {
$this->changes = $changes;
$this->original = $original;
$this->processType = $processType;
$this->process = $process;

// Get category name
$this->original['category'] = isset($original['process_category_id'])
Expand All @@ -49,19 +57,15 @@ public function getData(): array
{
if ($this->processType) {
return [
'name' => [
'label' => $this->processType,
],
'name' => $this->process->name ?? '',
'last_modified' => $this->changes['updated_at'] ?? Carbon::now(),
];
} else {
$oldData = array_diff_assoc($this->original, $this->changes);
$newData = array_diff_assoc($this->changes, $this->original);

return array_merge([
'name' => [
'label' => $this->processType,
],
'name' => $this->process->name ?? '',
'last_modified' => $this->changes['updated_at'] ?? Carbon::now(),
], ArrayHelper::getArrayDifferencesWithFormat($newData, $oldData));
}
Expand All @@ -74,7 +78,9 @@ public function getData(): array
*/
public function getChanges(): array
{
return [];
return [
'id' => $this->process->id ?? ''
];
}

/**
Expand Down
27 changes: 17 additions & 10 deletions ProcessMaker/Events/TokenCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,52 @@

namespace ProcessMaker\Events;

use Carbon\Carbon;
use Illuminate\Foundation\Events\Dispatchable;
use Laravel\Passport\Token;
use ProcessMaker\Contracts\SecurityLogEventInterface;
use ProcessMaker\Models\User;

class TokenCreated implements SecurityLogEventInterface
{
use Dispatchable;

private array $data;
private Token $data;
private User $user;
private string $name;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Token $token)
public function __construct(Token $token, User $user, string $name = '')
{
$this->data = [
'token_id' => $token->getKey(),
'created_at' => Carbon::now(),
];
$this->data = $token;
$this->user = $user;
$this->name = $name;
}

/**
* Return event data
* Return event data
*/
public function getData(): array
{
return $this->data;
return [
'name' => $this->name,
'id' => substr($this->data->getAttribute('id'), 0, 5),
'user' => $this->user->username,
'created_at' => $this->data->getAttribute('created_at'),
];
}

/**
* Return event changes
*/
public function getChanges(): array
{
return [];
return [
'client_id' => $this->data->getAttribute('client_id'),
];
}

/**
Expand Down
27 changes: 18 additions & 9 deletions ProcessMaker/Events/TokenDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,53 @@

namespace ProcessMaker\Events;

use Carbon\Carbon;
use Illuminate\Foundation\Events\Dispatchable;
use Laravel\Passport\Token;
use ProcessMaker\Contracts\SecurityLogEventInterface;
use ProcessMaker\Models\User;

class TokenDeleted implements SecurityLogEventInterface
{
use Dispatchable;

private array $data;

private array $changes;
private Token $data;
private User $user;
private string $name;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Token $token)
public function __construct(Token $token, User $user, string $name = '')
{
$this->data = [
'token_id' => $token->getKey(),
];
$this->data = $token;
$this->user = $user;
$this->name = $name;
}

/**
* Return event data
*/
public function getData(): array
{
return $this->data;
return [
'name' => $this->name,
'id' => substr($this->data->getAttribute('id'), 0, 5),
'user' => $this->user->username,
'deleted_at' => Carbon::now(),
];
}

/**
* Return event changes
*/
public function getChanges(): array
{
return $this->data;
return [
'client_id' => $this->data->getAttribute('client_id'),
];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Http/Controllers/Api/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public function update(Request $request, Process $process)
$response = (new TemplateController(new Template()))->updateTemplateManifest('process', $process->id, $request);

//Call Event to Log Template Changes
TemplateUpdated::dispatch([], [], true);
TemplateUpdated::dispatch([], [], true, $process);

return new Resource($process->refresh());
} catch (\Exception $error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ public function delete(Request $request, ScriptExecutor $scriptExecutor)
}
}

ScriptExecutorDeleted::dispatch($scriptExecutor->getAttributes());

ScriptExecutor::destroy($scriptExecutor->id);

ScriptExecutorDeleted::dispatch($scriptExecutor->getAttributes());

return ['status' => 'done'];
}

Expand Down
5 changes: 3 additions & 2 deletions ProcessMaker/Http/Controllers/Api/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ public function updateTemplate(string $type, Request $request)
public function updateTemplateConfigs(string $type, Request $request)
{
$request->validate(Template::rules($request->id, $this->types[$type][4]));
$proTemplates = ProcessTemplates::select()->find($request->id)->getOriginal();
$changes = $request->all();
$original = ProcessTemplates::select(array_keys($changes))->find($request->id)->getOriginal();
$original = array_intersect_key($proTemplates->getOriginal(), $changes);
$response = $this->template->updateTemplateConfigs($type, $request);
//Call event to log Template Config changes
TemplateUpdated::dispatch($changes, $original, false);
TemplateUpdated::dispatch($changes, $original, false, $proTemplates);

return $response;
}
Expand Down
4 changes: 2 additions & 2 deletions ProcessMaker/Http/Controllers/Api/UserTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function store(Request $request, User $user)
$request->scopes ?: []
);

event(new TokenCreated($token->token));
event(new TokenCreated($token->token, $user, $request->name));

return new UserTokenResource($token);
}
Expand Down Expand Up @@ -264,7 +264,7 @@ public function destroy(Request $request, User $user, $tokenId)

$token->revoke();

event(new TokenDeleted($token));
event(new TokenDeleted($token, $user, $token->name));

return response([], 204);
}
Expand Down
Loading