- Added a new CSRF token verification Middleware.
- Added a new ActionLog middleware to catch every modifying request and save the changes made and the user who did. - Added a new RequestLog to catch every request made whenever required.
This commit is contained in:
1 parent
9571c6a462
commit
4b86ac9e82
42 files changed
+1331
-148
No files matched your search
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Form\Security;
|
||||
|
||||
use CSSLSJ\TransportScolaire\Api\{Entity};
|
||||
use Lean\Api\Attribute\ContextField;
|
||||
use Lean\Api\Lib\FormContext;
|
||||
use Ulmus\Entity\EntityInterface;
|
||||
use Ulmus\Event\Entity\DatasetFill;
|
||||
use Ulmus\Ulmus;
|
||||
|
||||
#[ContextField(description: "")]
|
||||
class ActionLogContext extends FormContext
|
||||
{
|
||||
protected EntityInterface $entity;
|
||||
|
||||
#[ContextField(mandatory: true)]
|
||||
public string $event;
|
||||
|
||||
#[ContextField(mandatory: true)]
|
||||
public string $method;
|
||||
|
||||
#[ContextField(mandatory: true)]
|
||||
public int $object_id;
|
||||
|
||||
#[ContextField(mandatory: true)]
|
||||
public string $object_type;
|
||||
|
||||
#[ContextField]
|
||||
public ? int $user_id;
|
||||
|
||||
#[ContextField]
|
||||
public string $user_type;
|
||||
|
||||
#[ContextField]
|
||||
public string $description;
|
||||
|
||||
#[ContextField]
|
||||
public array $data = [];
|
||||
|
||||
private DatasetFill $datasetFillEvent;
|
||||
|
||||
public function attachEntity(EntityInterface $entity) : void
|
||||
{
|
||||
$this->entity = $entity;
|
||||
|
||||
$this->datasetFillEvent = new class() implements \Ulmus\Event\Entity\DatasetFill
|
||||
{
|
||||
public readonly array $data;
|
||||
|
||||
public function execute(\Generator $generator, \Ulmus\Entity\EntityInterface $entity): void
|
||||
{
|
||||
$this->data = $entity::repository()->generateDatasetDiff($entity);
|
||||
}
|
||||
};
|
||||
|
||||
$this->entity->eventRegister($this->datasetFillEvent);
|
||||
}
|
||||
|
||||
public function initializeEntity(\Lean\Api\Entity\Security\ApiActionLog $actionLog) : void
|
||||
{
|
||||
if (isset($this->entity) && $this->entity->isLoaded()) {
|
||||
if ($pk = array_key_first($this->entity::resolveEntity()->getPrimaryKeyField())) {
|
||||
if (isset($this->entity->$pk)) {
|
||||
$this->object_id = $this->entity->$pk;
|
||||
$this->object_type = $this->entity::class;
|
||||
|
||||
if (isset($this->datasetFillEvent->data)) {
|
||||
$this->data = $this->datasetFillEvent->data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new \InvalidArgumentException("An EntityInterface must be provided using the attachEntity() method.");
|
||||
}
|
||||
}
|
||||
|
||||
public function valid(? \Lean\Api\Entity\Security\ApiActionLog $actionLog = null): bool
|
||||
{
|
||||
return isset($this->object_id) && isset($this->object_type);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user