Skip to content
Open
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
1 change: 1 addition & 0 deletions apps/admin_audit/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
'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',
);
1 change: 1 addition & 0 deletions apps/admin_audit/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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',
);

Expand Down
14 changes: 7 additions & 7 deletions apps/admin_audit/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 @@ -130,6 +133,10 @@ public function register(IRegistrationContext $context): void {

// System tag event
$context->registerEventListener(TagCreatedEvent::class, TagEventListener::class);

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

#[\Override]
Expand All @@ -152,7 +159,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 @@ -215,10 +221,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');
}
}
36 changes: 36 additions & 0 deletions apps/admin_audit/lib/Listener/TrashbinEventListener.php
Comment thread
CarlSchwan marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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\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('File "%s" deleted from trash bin.',
['path' => $event->getSource()->getPath()], ['path']
);
} elseif ($event instanceof NodeRestoredEvent) {
$this->log('File "%s" restored from trash bin.',
['path' => $event->getTarget()->getPath()], ['path']
);
}
}
}
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
31 changes: 31 additions & 0 deletions apps/files_trashbin/lib/Events/BeforeNodeDeletedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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 send before a node is deleted definitively.
*
* If you are doing anything with the database, prefer using BeforeAllNodeDeletedEvent instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no BeforeAllNodeDeletedEvent for trashbin, is there? If it’s from another namespace put the fully qualified name in the comment.

* @since 35.0.0
*/
class BeforeNodeDeletedEvent extends Event {
public function __construct(
private readonly Node $source,
) {
parent::__construct();
}

public function getSource(): Node {
return $this->source;
}
}
30 changes: 30 additions & 0 deletions apps/files_trashbin/lib/Events/NodeDeletedEvent.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 send before a node is deleted definitively.
*
* @since 35.0.0
*/
class NodeDeletedEvent extends Event {
public function __construct(
private readonly string $sourcePath,
) {
parent::__construct();
}

public function getSourcePath(): string {
return $this->sourcePath;
}
}
4 changes: 2 additions & 2 deletions apps/files_trashbin/lib/Sabre/TrashRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Sabre\DAV\ICollection;

class TrashRoot implements ICollection {

public function __construct(
private IUser $user,
private ITrashManager $trashManager,
Expand All @@ -33,7 +32,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 Expand Up @@ -75,6 +74,7 @@ public function getChildren(): array {

#[\Override]
public function getChild($name): ITrash {
/** @var list<ITrash&ICollection> $entries */
$entries = $this->getChildren();

foreach ($entries as $entry) {
Expand Down
Loading
Loading