Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/admin_audit/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'OCA\\AdminAudit\\Actions\\Action' => $baseDir . '/../lib/Actions/Action.php',
'OCA\\AdminAudit\\Actions\\Files' => $baseDir . '/../lib/Actions/Files.php',
'OCA\\AdminAudit\\Actions\\Sharing' => $baseDir . '/../lib/Actions/Sharing.php',
'OCA\\AdminAudit\\Actions\\Trashbin' => $baseDir . '/../lib/Actions/Trashbin.php',
'OCA\\AdminAudit\\Actions\\Versions' => $baseDir . '/../lib/Actions/Versions.php',
'OCA\\AdminAudit\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\AdminAudit\\AuditLogger' => $baseDir . '/../lib/AuditLogger.php',
Expand All @@ -26,6 +25,7 @@
'OCA\\AdminAudit\\Listener\\SecurityEventListener' => $baseDir . '/../lib/Listener/SecurityEventListener.php',
'OCA\\AdminAudit\\Listener\\SharingEventListener' => $baseDir . '/../lib/Listener/SharingEventListener.php',
'OCA\\AdminAudit\\Listener\\TagEventListener' => $baseDir . '/../lib/Listener/TagEventListener.php',
'OCA\\AdminAudit\\Listener\\TrashbinEventListener' => $baseDir . '/../lib/Listener/TrashbinEventListener.php',
'OCA\\AdminAudit\\Listener\\UserManagementEventListener' => $baseDir . '/../lib/Listener/UserManagementEventListener.php',
'OCA\\AdminAudit\\Operation' => $baseDir . '/../lib/Operation.php',
);
2 changes: 1 addition & 1 deletion apps/admin_audit/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ComposerStaticInitAdminAudit
'OCA\\AdminAudit\\Actions\\Action' => __DIR__ . '/..' . '/../lib/Actions/Action.php',
'OCA\\AdminAudit\\Actions\\Files' => __DIR__ . '/..' . '/../lib/Actions/Files.php',
'OCA\\AdminAudit\\Actions\\Sharing' => __DIR__ . '/..' . '/../lib/Actions/Sharing.php',
'OCA\\AdminAudit\\Actions\\Trashbin' => __DIR__ . '/..' . '/../lib/Actions/Trashbin.php',
'OCA\\AdminAudit\\Actions\\Versions' => __DIR__ . '/..' . '/../lib/Actions/Versions.php',
'OCA\\AdminAudit\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\AdminAudit\\AuditLogger' => __DIR__ . '/..' . '/../lib/AuditLogger.php',
Expand All @@ -41,6 +40,7 @@ class ComposerStaticInitAdminAudit
'OCA\\AdminAudit\\Listener\\SecurityEventListener' => __DIR__ . '/..' . '/../lib/Listener/SecurityEventListener.php',
'OCA\\AdminAudit\\Listener\\SharingEventListener' => __DIR__ . '/..' . '/../lib/Listener/SharingEventListener.php',
'OCA\\AdminAudit\\Listener\\TagEventListener' => __DIR__ . '/..' . '/../lib/Listener/TagEventListener.php',
'OCA\\AdminAudit\\Listener\\TrashbinEventListener' => __DIR__ . '/..' . '/../lib/Listener/TrashbinEventListener.php',
'OCA\\AdminAudit\\Listener\\UserManagementEventListener' => __DIR__ . '/..' . '/../lib/Listener/UserManagementEventListener.php',
'OCA\\AdminAudit\\Operation' => __DIR__ . '/..' . '/../lib/Operation.php',
);
Expand Down
25 changes: 0 additions & 25 deletions apps/admin_audit/lib/Actions/Trashbin.php

This file was deleted.

15 changes: 7 additions & 8 deletions apps/admin_audit/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use OCA\AdminAudit\Actions\Files;
use OCA\AdminAudit\Actions\Sharing;
use OCA\AdminAudit\Actions\Trashbin;
use OCA\AdminAudit\Actions\Versions;
use OCA\AdminAudit\AuditLogger;
use OCA\AdminAudit\IAuditLogger;
Expand All @@ -25,7 +24,10 @@
use OCA\AdminAudit\Listener\SecurityEventListener;
use OCA\AdminAudit\Listener\SharingEventListener;
use OCA\AdminAudit\Listener\TagEventListener;
use OCA\AdminAudit\Listener\TrashbinEventListener;
use OCA\AdminAudit\Listener\UserManagementEventListener;
use OCA\Files_Trashbin\Events\BeforeNodeDeletedEvent as TrashbinBeforeNodeDeletedEvent;
use OCA\Files_Trashbin\Events\NodeRestoredEvent;
use OCA\Files_Versions\Events\VersionRestoredEvent;
use OCP\App\Events\AppDisableEvent;
use OCP\App\Events\AppEnableEvent;
Expand Down Expand Up @@ -156,6 +158,10 @@ public function register(IRegistrationContext $context): void {
// Files sharing recipient events
$context->registerEventListener(ShareAcceptedEvent::class, SharingEventListener::class);
$context->registerEventListener(ShareDeletedFromSelfEvent::class, SharingEventListener::class);

// Trashbin events
$context->registerEventListener(TrashbinBeforeNodeDeletedEvent::class, TrashbinEventListener::class);
$context->registerEventListener(NodeRestoredEvent::class, TrashbinEventListener::class);
}

#[\Override]
Expand All @@ -178,7 +184,6 @@ private function registerLegacyHooks(IAuditLogger $logger, ContainerInterface $s
$eventDispatcher = $serverContainer->get(IEventDispatcher::class);
$this->sharingLegacyHooks($logger);
$this->fileHooks($logger, $eventDispatcher);
$this->trashbinHooks($logger);
$this->versionsHooks($logger);
}

Expand Down Expand Up @@ -241,10 +246,4 @@ private function versionsHooks(IAuditLogger $logger): void {
$versionsActions = new Versions($logger);
Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete');
}

private function trashbinHooks(IAuditLogger $logger): void {
$trashActions = new Trashbin($logger);
Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete');
Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore');
}
}
37 changes: 37 additions & 0 deletions apps/admin_audit/lib/Listener/TrashbinEventListener.php
Comment thread
CarlSchwan marked this conversation as resolved.
Resolved
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']
);
}
}
}
43 changes: 0 additions & 43 deletions apps/admin_audit/tests/Actions/TrashbinTest.php

This file was deleted.

64 changes: 64 additions & 0 deletions apps/admin_audit/tests/Listener/TrashbinEventListenerTest.php
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());
}
}
2 changes: 2 additions & 0 deletions apps/files_trashbin/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
'OCA\\Files_Trashbin\\Command\\RestoreAllFiles' => $baseDir . '/../lib/Command/RestoreAllFiles.php',
'OCA\\Files_Trashbin\\Command\\Size' => $baseDir . '/../lib/Command/Size.php',
'OCA\\Files_Trashbin\\Controller\\PreviewController' => $baseDir . '/../lib/Controller/PreviewController.php',
'OCA\\Files_Trashbin\\Events\\BeforeNodeDeletedEvent' => $baseDir . '/../lib/Events/BeforeNodeDeletedEvent.php',
'OCA\\Files_Trashbin\\Events\\BeforeNodeRestoredEvent' => $baseDir . '/../lib/Events/BeforeNodeRestoredEvent.php',
'OCA\\Files_Trashbin\\Events\\MoveToTrashEvent' => $baseDir . '/../lib/Events/MoveToTrashEvent.php',
'OCA\\Files_Trashbin\\Events\\NodeDeletedEvent' => $baseDir . '/../lib/Events/NodeDeletedEvent.php',
'OCA\\Files_Trashbin\\Events\\NodeRestoredEvent' => $baseDir . '/../lib/Events/NodeRestoredEvent.php',
'OCA\\Files_Trashbin\\Exceptions\\CopyRecursiveException' => $baseDir . '/../lib/Exceptions/CopyRecursiveException.php',
'OCA\\Files_Trashbin\\Expiration' => $baseDir . '/../lib/Expiration.php',
Expand Down
2 changes: 2 additions & 0 deletions apps/files_trashbin/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class ComposerStaticInitFiles_Trashbin
'OCA\\Files_Trashbin\\Command\\RestoreAllFiles' => __DIR__ . '/..' . '/../lib/Command/RestoreAllFiles.php',
'OCA\\Files_Trashbin\\Command\\Size' => __DIR__ . '/..' . '/../lib/Command/Size.php',
'OCA\\Files_Trashbin\\Controller\\PreviewController' => __DIR__ . '/..' . '/../lib/Controller/PreviewController.php',
'OCA\\Files_Trashbin\\Events\\BeforeNodeDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/BeforeNodeDeletedEvent.php',
'OCA\\Files_Trashbin\\Events\\BeforeNodeRestoredEvent' => __DIR__ . '/..' . '/../lib/Events/BeforeNodeRestoredEvent.php',
'OCA\\Files_Trashbin\\Events\\MoveToTrashEvent' => __DIR__ . '/..' . '/../lib/Events/MoveToTrashEvent.php',
'OCA\\Files_Trashbin\\Events\\NodeDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/NodeDeletedEvent.php',
'OCA\\Files_Trashbin\\Events\\NodeRestoredEvent' => __DIR__ . '/..' . '/../lib/Events/NodeRestoredEvent.php',
'OCA\\Files_Trashbin\\Exceptions\\CopyRecursiveException' => __DIR__ . '/..' . '/../lib/Exceptions/CopyRecursiveException.php',
'OCA\\Files_Trashbin\\Expiration' => __DIR__ . '/..' . '/../lib/Expiration.php',
Expand Down
30 changes: 30 additions & 0 deletions apps/files_trashbin/lib/Events/BeforeNodeDeletedEvent.php
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;
}
}
29 changes: 29 additions & 0 deletions apps/files_trashbin/lib/Events/NodeDeletedEvent.php
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;
}
}
3 changes: 1 addition & 2 deletions apps/files_trashbin/lib/Sabre/TrashRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Sabre\DAV\INode;

class TrashRoot implements ICollection {

public function __construct(
private readonly IUser $user,
private readonly ITrashManager $trashManager,
Expand All @@ -35,7 +34,7 @@ public function delete() {
throw new Forbidden('Not allowed to delete items from the trash bin');
}

Trashbin::deleteAll();
Trashbin::deleteAll($this->user);
foreach ($this->trashManager->listTrashRoot($this->user) as $trashItem) {
$this->trashManager->removeItem($trashItem);
}
Expand Down
Loading
Loading