Repository navigation
refactor(trash): Port deletion code of Trashbin to node based API #54278
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\AdminAudit\Listener; | ||
|
|
||
| use OCA\AdminAudit\Actions\Action; | ||
| use OCA\AdminAudit\Operation; | ||
| use OCA\Files_Trashbin\Events\BeforeNodeDeletedEvent; | ||
| use OCA\Files_Trashbin\Events\NodeRestoredEvent; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
| use Override; | ||
|
|
||
| /** | ||
| * @template-implements IEventListener<BeforeNodeDeletedEvent|NodeRestoredEvent> | ||
| */ | ||
| class TrashbinEventListener extends Action implements IEventListener { | ||
|
|
||
| #[Override] | ||
| public function handle(Event $event): void { | ||
| if ($event instanceof BeforeNodeDeletedEvent) { | ||
| $this->log(Operation::TrashbinFileDeleted, 'File "%s" deleted from trash bin.', | ||
| ['path' => $event->getSource()->getPath()], ['path'] | ||
| ); | ||
| } elseif ($event instanceof NodeRestoredEvent) { | ||
| $this->log(Operation::TrashbinFileRestored, 'File "%s" restored from trash bin.', | ||
| ['path' => $event->getTarget()->getPath()], ['path'] | ||
| ); | ||
| } | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
apps/admin_audit/tests/Listener/TrashbinEventListenerTest.php
This file contains hidden or 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,64 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\AdminAudit\Tests\Listener; | ||
|
|
||
| use OCA\AdminAudit\IAuditLogger; | ||
| use OCA\AdminAudit\Listener\TrashbinEventListener; | ||
| use OCA\Files_Trashbin\Events\BeforeNodeDeletedEvent; | ||
| use OCA\Files_Trashbin\Events\NodeRestoredEvent; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\Files\Node; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Test\TestCase; | ||
|
|
||
| class TrashbinEventListenerTest extends TestCase { | ||
| private IAuditLogger&MockObject $logger; | ||
| private TrashbinEventListener $listener; | ||
|
|
||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
|
|
||
| $this->logger = $this->createMock(IAuditLogger::class); | ||
| $this->listener = new TrashbinEventListener($this->logger); | ||
| } | ||
|
|
||
| private function createNode(string $path): Node&MockObject { | ||
| $node = $this->createMock(Node::class); | ||
| $node->method('getPath')->willReturn($path); | ||
| return $node; | ||
| } | ||
|
|
||
| private function expectInfo(string $message, string $operation, array $params): void { | ||
| $this->logger->expects($this->once()) | ||
| ->method('info') | ||
| ->with($message, ['app' => 'admin_audit', 'operation' => $operation, 'params' => $params]); | ||
| } | ||
|
|
||
| public function testDelete(): void { | ||
| $path = '/alice/files_trashbin/files/a.txt.d1700000000'; | ||
| $this->expectInfo('File "' . $path . '" deleted from trash bin.', 'trashbin.file.deleted', ['path' => $path]); | ||
|
|
||
| $this->listener->handle(new BeforeNodeDeletedEvent($this->createNode($path))); | ||
| } | ||
|
|
||
| public function testRestore(): void { | ||
| $source = $this->createNode('/alice/files_trashbin/files/a.txt.d1700000000'); | ||
| $target = $this->createNode('/alice/files/a.txt'); | ||
| $this->expectInfo('File "/alice/files/a.txt" restored from trash bin.', 'trashbin.file.restored', ['path' => '/alice/files/a.txt']); | ||
|
|
||
| $this->listener->handle(new NodeRestoredEvent($source, $target)); | ||
| } | ||
|
|
||
| public function testUnrelatedEventIsIgnored(): void { | ||
| $this->logger->expects($this->never())->method('info'); | ||
|
|
||
| $this->listener->handle(new Event()); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Files_Trashbin\Events; | ||
|
|
||
| use OCP\EventDispatcher\Event; | ||
| use OCP\Files\Node; | ||
|
|
||
| /** | ||
| * Event sent before a node is permanently deleted from the trash bin. | ||
| * | ||
| * @since 35.0.0 | ||
| */ | ||
| class BeforeNodeDeletedEvent extends Event { | ||
| public function __construct( | ||
| private readonly Node $source, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| public function getSource(): Node { | ||
| return $this->source; | ||
| } | ||
| } |
This file contains hidden or 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,29 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Files_Trashbin\Events; | ||
|
|
||
| use OCP\EventDispatcher\Event; | ||
|
|
||
| /** | ||
| * Event sent after a node was permanently deleted from the trash bin. | ||
| * | ||
| * @since 35.0.0 | ||
| */ | ||
| class NodeDeletedEvent extends Event { | ||
| public function __construct( | ||
| private readonly string $sourcePath, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| public function getSourcePath(): string { | ||
| return $this->sourcePath; | ||
| } | ||
| } |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.