-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Event; | ||
|
||
use OCA\Tables\Db\Row2; | ||
use OCP\EventDispatcher\Event; | ||
|
||
final class RowDeletedEvent extends Event | ||
{ | ||
public function __construct(protected Row2 $row, protected string $userId) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function getRow(): Row2 | ||
{ | ||
return $this->row; | ||
} | ||
|
||
public function getUserId(): string | ||
{ | ||
return $this->userId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Event; | ||
|
||
use OCA\Tables\Db\Table; | ||
use OCP\EventDispatcher\Event; | ||
|
||
final class TableDeletedEvent extends Event | ||
{ | ||
public function __construct(protected Table $table, protected string $userId) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function getTable(): Table | ||
{ | ||
return $this->table; | ||
} | ||
|
||
public function getUserId(): string | ||
{ | ||
return $this->userId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Event; | ||
|
||
use OCA\Tables\Db\Table; | ||
use OCP\EventDispatcher\Event; | ||
|
||
final class TableOwnershipTransferredEvent extends Event | ||
{ | ||
public function __construct(protected Table $table, protected string $toUserId, protected ?string $fromUserId = null) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function getTable(): Table | ||
{ | ||
return $this->table; | ||
} | ||
|
||
public function getFromUserId(): string | ||
Check failure on line 22 in lib/Event/TableOwnershipTransferredEvent.php GitHub Actions / static-psalm-analysis dev-masterInvalidNullableReturnType
Check failure on line 22 in lib/Event/TableOwnershipTransferredEvent.php GitHub Actions / static-psalm-analysis dev-stable28InvalidNullableReturnType
|
||
{ | ||
return $this->fromUserId; | ||
Check failure on line 24 in lib/Event/TableOwnershipTransferredEvent.php GitHub Actions / static-psalm-analysis dev-masterNullableReturnStatement
Check failure on line 24 in lib/Event/TableOwnershipTransferredEvent.php GitHub Actions / static-psalm-analysis dev-stable28NullableReturnStatement
|
||
} | ||
|
||
public function getToUserId(): string | ||
{ | ||
return $this->toUserId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Event; | ||
|
||
use OCA\Tables\Db\View; | ||
use OCP\EventDispatcher\Event; | ||
|
||
final class ViewDeletedEvent extends Event | ||
{ | ||
public function __construct(protected View $view, protected string $userId) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function getView(): View | ||
{ | ||
return $this->view; | ||
} | ||
|
||
public function getUserId(): string | ||
{ | ||
return $this->userId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Listener; | ||
|
||
use OCA\Tables\Event\RowDeletedEvent; | ||
use OCA\Tables\Service\Support\AuditLogServiceInterface; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
|
||
final class WhenRowDeletedAuditLogListener implements IEventListener | ||
Check failure on line 12 in lib/Listener/WhenRowDeletedAuditLogListener.php GitHub Actions / static-psalm-analysis dev-masterMissingTemplateParam
Check failure on line 12 in lib/Listener/WhenRowDeletedAuditLogListener.php GitHub Actions / static-psalm-analysis dev-stable28MissingTemplateParam
|
||
{ | ||
public function __construct(protected AuditLogServiceInterface $auditLogService) | ||
{ | ||
} | ||
|
||
public function handle(Event $event): void | ||
{ | ||
if (!($event instanceof RowDeletedEvent)) { | ||
return; | ||
} | ||
|
||
$row = $event->getRow(); | ||
$userId = $event->getUserId(); | ||
$rowId = $row->getId(); | ||
|
||
$this->auditLogService->log("Row with ID: $rowId was deleted by user with ID: $userId", [ | ||
'row' => $row->jsonSerialize(), | ||
'userId' => $userId, | ||
]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Listener; | ||
|
||
use OCA\Tables\Event\TableDeletedEvent; | ||
use OCA\Tables\Service\Support\AuditLogServiceInterface; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
|
||
final class WhenTableDeletedAuditLogListener implements IEventListener | ||
Check failure on line 12 in lib/Listener/WhenTableDeletedAuditLogListener.php GitHub Actions / static-psalm-analysis dev-masterMissingTemplateParam
Check failure on line 12 in lib/Listener/WhenTableDeletedAuditLogListener.php GitHub Actions / static-psalm-analysis dev-stable28MissingTemplateParam
|
||
{ | ||
public function __construct(protected AuditLogServiceInterface $auditLogService) | ||
{ | ||
} | ||
|
||
public function handle(Event $event): void | ||
{ | ||
if (!($event instanceof TableDeletedEvent)) { | ||
return; | ||
} | ||
|
||
$table = $event->getTable(); | ||
$userId = $event->getUserId(); | ||
|
||
$this->auditLogService->log("Table with ID: $table->id was deleted by user with ID: $userId", [ | ||
'table' => $table->jsonSerialize(), | ||
'userId' => $userId, | ||
]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Listener; | ||
|
||
use OCA\Tables\Event\TableOwnershipTransferredEvent; | ||
use OCA\Tables\Service\Support\AuditLogServiceInterface; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
|
||
final class WhenTableTransferredAuditLogListener implements IEventListener | ||
Check failure on line 12 in lib/Listener/WhenTableTransferredAuditLogListener.php GitHub Actions / static-psalm-analysis dev-masterMissingTemplateParam
Check failure on line 12 in lib/Listener/WhenTableTransferredAuditLogListener.php GitHub Actions / static-psalm-analysis dev-stable28MissingTemplateParam
|
||
{ | ||
public function __construct(protected AuditLogServiceInterface $auditLogService) | ||
{ | ||
} | ||
|
||
public function handle(Event $event): void | ||
{ | ||
if (!($event instanceof TableOwnershipTransferredEvent)) { | ||
return; | ||
} | ||
|
||
$table = $event->getTable(); | ||
$fromUserId = $event->getFromUserId(); | ||
$toUserId = $event->getToUserId(); | ||
|
||
$this->auditLogService->log("Table with ID: $table->id was transferred from user with ID: $fromUserId to user with ID: $toUserId", [ | ||
'table' => $table->jsonSerialize(), | ||
'fromUserId' => $fromUserId, | ||
'toUserId' => $toUserId, | ||
]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Listener; | ||
|
||
use OCA\Tables\Event\ViewDeletedEvent; | ||
use OCA\Tables\Service\Support\AuditLogServiceInterface; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
|
||
final class WhenViewDeletedAuditLogListener implements IEventListener | ||
Check failure on line 12 in lib/Listener/WhenViewDeletedAuditLogListener.php GitHub Actions / static-psalm-analysis dev-masterMissingTemplateParam
Check failure on line 12 in lib/Listener/WhenViewDeletedAuditLogListener.php GitHub Actions / static-psalm-analysis dev-stable28MissingTemplateParam
|
||
{ | ||
public function __construct(protected AuditLogServiceInterface $auditLogService) | ||
{ | ||
} | ||
|
||
public function handle(Event $event): void | ||
{ | ||
if (!($event instanceof ViewDeletedEvent)) { | ||
return; | ||
} | ||
|
||
$view = $event->getView(); | ||
$userId = $event->getUserId(); | ||
|
||
$this->auditLogService->log("View with ID: $view->id was deleted by user with ID: $userId", [ | ||
'view' => $view->jsonSerialize(), | ||
'userId' => $userId, | ||
]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Service\Support; | ||
|
||
interface AuditLogServiceInterface | ||
{ | ||
public function log(string $message, array $context): void; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Service\Support; | ||
|
||
use OCP\EventDispatcher\IEventDispatcher; | ||
use OCP\Log\Audit\CriticalActionPerformedEvent; | ||
|
||
final class DefaultAuditLogService implements AuditLogServiceInterface | ||
{ | ||
public function __construct(private IEventDispatcher $eventDispatcher) | ||
{ | ||
} | ||
|
||
public function log(string $message, array $context): void | ||
{ | ||
$auditEvent = new CriticalActionPerformedEvent($message, $context); | ||
|
||
$this->eventDispatcher->dispatchTyped($auditEvent); | ||
} | ||
} |