-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Write critical operations to the audit log #959
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,22 @@ | ||
<?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; | ||
} | ||
} |
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,22 @@ | ||
<?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; | ||
} | ||
} |
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,22 @@ | ||
<?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; | ||
juliushaertl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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,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; | ||
|
||
/** | ||
* @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(); | ||
$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, | ||
]); | ||
} | ||
} |
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,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; | ||
|
||
/** | ||
* @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(); | ||
$userId = $event->getUserId(); | ||
|
||
$this->auditLogService->log("Table with ID: $table->id was deleted by user with ID: $userId", [ | ||
'table' => $table->jsonSerialize(), | ||
'userId' => $userId, | ||
]); | ||
} | ||
} |
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,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; | ||
|
||
/** | ||
* @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(); | ||
$userId = $event->getUserId(); | ||
|
||
$this->auditLogService->log("View with ID: $view->id was deleted by user with ID: $userId", [ | ||
'view' => $view->jsonSerialize(), | ||
'userId' => $userId, | ||
juliushaertl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]); | ||
} | ||
} |
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; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem related to the implementation but fine to annotate here, just the static analysis fails due to the incomplete array description as the array gets enriched with a columnType key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juliushaertl Thank you for spot on! Wondering why the ci/cd checks keeps failing (Not immediately but after few days)
Changed to this: @psalm-param list<array{columnId?: int, columnType?: string, mode?: 'ASC'|'DESC'}> $sortArray
Because when running psalm at my local there a case only 2 of them present (columnId & mode)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI requires approval for outside contributors, i just approved it again, so results should appear more quickly now.
I'm also unsure why that may not happen for you locally, just checked and I get the same error. The only thing I could imagine is psalm cache which sometimes messes things up. You could try running with
composer run psalm -- --no-cache --threads=8
and see if that makes a difference.