-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #959 from hweihwang/feat/956
- Loading branch information
Showing
21 changed files
with
526 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?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) { | ||
parent::__construct(); | ||
} | ||
|
||
public function getRow(): Row2 { | ||
return $this->row; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?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) { | ||
parent::__construct(); | ||
} | ||
|
||
public function getTable(): Table { | ||
return $this->table; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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|null { | ||
return $this->fromUserId; | ||
} | ||
|
||
public function getToUserId(): string { | ||
return $this->toUserId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?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) { | ||
parent::__construct(); | ||
} | ||
|
||
public function getView(): View { | ||
return $this->view; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?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; | ||
|
||
/** | ||
* @template-implements IEventListener<Event|RowDeletedEvent> | ||
*/ | ||
final class WhenRowDeletedAuditLogListener implements IEventListener { | ||
public function __construct(protected AuditLogServiceInterface $auditLogService) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof RowDeletedEvent)) { | ||
return; | ||
} | ||
|
||
$row = $event->getRow(); | ||
$rowId = $row->getId(); | ||
|
||
$this->auditLogService->log("Row with ID: $rowId was deleted", [ | ||
'row' => $row->jsonSerialize(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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; | ||
|
||
/** | ||
* @template-implements IEventListener<Event|TableDeletedEvent> | ||
*/ | ||
final class WhenTableDeletedAuditLogListener implements IEventListener { | ||
public function __construct(protected AuditLogServiceInterface $auditLogService) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof TableDeletedEvent)) { | ||
return; | ||
} | ||
|
||
$table = $event->getTable(); | ||
|
||
$this->auditLogService->log("Table with ID: $table->id was deleted", [ | ||
'table' => $table->jsonSerialize(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
/** | ||
* @template-implements IEventListener<Event|TableOwnershipTransferredEvent> | ||
*/ | ||
final class WhenTableTransferredAuditLogListener implements IEventListener { | ||
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, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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; | ||
|
||
/** | ||
* @template-implements IEventListener<Event|ViewDeletedEvent> | ||
*/ | ||
final class WhenViewDeletedAuditLogListener implements IEventListener { | ||
public function __construct(protected AuditLogServiceInterface $auditLogService) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof ViewDeletedEvent)) { | ||
return; | ||
} | ||
|
||
$view = $event->getView(); | ||
|
||
$this->auditLogService->log("View with ID: $view->id was deleted", [ | ||
'view' => $view->jsonSerialize(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Tables\Service\Support; | ||
|
||
interface AuditLogServiceInterface { | ||
public function log(string $message, array $context): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?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); | ||
} | ||
} |
Oops, something went wrong.