on('propFind', [$this, 'propFind']); } public function propFind(PropFind $propFind, INode $node) { if (!in_array(static::DOWNLOAD_LIMITS_PROPERTY, $propFind->getRequestedProperties(), true)) { return; } if (!($node instanceof SabreFile)) { // Only allowed on files return; } $propFind->handle( static::DOWNLOAD_LIMITS_PROPERTY, function () use ($node) { $user = $this->userSession->getUser(); if (!($user instanceof IUser)) { return new LimitList([]); } $externalShares = $this->getSharesForTypes( $user, $node->getNode(), [ IShare::TYPE_LINK, IShare::TYPE_EMAIL, ], ); /** @var Limit[] $limits */ $limits = array_values(array_filter(array_map(function (IShare $share) { try { return $this->limitMapper->get($share->getToken()); } catch (DoesNotExistException $e) { // Allow as no limit has been set return null; } }, $externalShares))); return new LimitList($limits); }, ); } /** * @param int[] $types * @return IShare[] */ private function getSharesForTypes(IUser $user, File $file, array $types) { /** @var IShare[] $shares */ $shares = []; foreach ($types as $type) { $shares = array_merge($shares, $this->shareManager->getSharesBy($user->getUID(), $type, $file, false, -1, 0)); } return $shares; } }