Skip to content

Commit b0403b9

Browse files
ArtificialOwlbackportbot[bot]
authored andcommitted
fix(trashbin): deletedBy of a file from a federated folder
Signed-off-by: Maxence Lange <[email protected]> d [skip ci]
1 parent c19d37f commit b0403b9

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

apps/files_trashbin/lib/Trashbin.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
use OCP\Lock\ILockingProvider;
4343
use OCP\Lock\LockedException;
4444
use OCP\Server;
45+
use OCP\Share\Exceptions\ShareNotFound;
4546
use OCP\Util;
47+
use Psr\Container\ContainerExceptionInterface;
48+
use Psr\Container\NotFoundExceptionInterface;
4649
use Psr\Log\LoggerInterface;
4750

4851
/** @template-implements IEventListener<BeforeNodeDeletedEvent> */
@@ -329,7 +332,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
329332
->setValue('timestamp', $query->createNamedParameter($timestamp))
330333
->setValue('location', $query->createNamedParameter($location))
331334
->setValue('user', $query->createNamedParameter($owner))
332-
->setValue('deleted_by', $query->createNamedParameter($user));
335+
->setValue('deleted_by', $query->createNamedParameter($deletedBy));
333336
$result = $query->executeStatement();
334337
if (!$result) {
335338
\OC::$server->get(LoggerInterface::class)->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']);
@@ -1188,6 +1191,29 @@ private static function getNodeForPath(string $path): Node {
11881191
}
11891192
}
11901193

1194+
/**
1195+
* in case the request is authed, and user token is from a federated share
1196+
* we use shared_with as initiator of the deletion
1197+
*/
1198+
private static function overwriteDeletedBy(string $user) {
1199+
try {
1200+
$request = Server::get(IRequest::class);
1201+
/** @psalm-suppress NoInterfaceProperties */
1202+
$token = $request->server['PHP_AUTH_USER'] ?? '';
1203+
if ($token === '') {
1204+
return $user;
1205+
}
1206+
1207+
$federatedShareProvider = Server::get(\OCA\FederatedFileSharing\FederatedShareProvider::class);
1208+
$share = $federatedShareProvider->getShareByToken($token);
1209+
1210+
return $share->getSharedWith();
1211+
} catch (NotFoundExceptionInterface|ContainerExceptionInterface|ShareNotFound) {
1212+
}
1213+
1214+
return $user;
1215+
}
1216+
11911217
public function handle(Event $event): void {
11921218
if ($event instanceof BeforeNodeDeletedEvent) {
11931219
self::ensureFileScannedHook($event->getNode());

0 commit comments

Comments
 (0)