|
42 | 42 | use OCP\Lock\ILockingProvider; |
43 | 43 | use OCP\Lock\LockedException; |
44 | 44 | use OCP\Server; |
| 45 | +use OCP\Share\Exceptions\ShareNotFound; |
45 | 46 | use OCP\Util; |
| 47 | +use Psr\Container\ContainerExceptionInterface; |
| 48 | +use Psr\Container\NotFoundExceptionInterface; |
46 | 49 | use Psr\Log\LoggerInterface; |
47 | 50 |
|
48 | 51 | /** @template-implements IEventListener<BeforeNodeDeletedEvent> */ |
@@ -329,7 +332,7 @@ public static function move2trash($file_path, $ownerOnly = false) { |
329 | 332 | ->setValue('timestamp', $query->createNamedParameter($timestamp)) |
330 | 333 | ->setValue('location', $query->createNamedParameter($location)) |
331 | 334 | ->setValue('user', $query->createNamedParameter($owner)) |
332 | | - ->setValue('deleted_by', $query->createNamedParameter($user)); |
| 335 | + ->setValue('deleted_by', $query->createNamedParameter($deletedBy)); |
333 | 336 | $result = $query->executeStatement(); |
334 | 337 | if (!$result) { |
335 | 338 | \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 { |
1188 | 1191 | } |
1189 | 1192 | } |
1190 | 1193 |
|
| 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 | + |
1191 | 1217 | public function handle(Event $event): void { |
1192 | 1218 | if ($event instanceof BeforeNodeDeletedEvent) { |
1193 | 1219 | self::ensureFileScannedHook($event->getNode()); |
|
0 commit comments