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
11 changes: 5 additions & 6 deletions apps/dav/appinfo/v1/publicwebdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
}

$share = $authBackend->getShare();
$owner = $share->getShareOwner();
$isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ;
$fileId = $share->getNodeId();

Expand All @@ -97,18 +96,18 @@
\OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog);

OC_Util::tearDownFS();
OC_Util::setupFS($owner);
$ownerView = new \OC\Files\View('/'. $owner . '/files');
$path = $ownerView->getPath($fileId);
$fileInfo = $ownerView->getFileInfo($path);
OC_Util::setupFS($share->getSharedBy());
$initiatorView = new \OC\Files\View('/'. $share->getSharedBy() . '/files');
$path = $initiatorView->getPath($fileId);
$fileInfo = $initiatorView->getFileInfo($path);
$linkCheckPlugin->setFileInfo($fileInfo);

// If not readable (files_drop) enable the filesdrop plugin
if (!$isReadable) {
$filesDropPlugin->enable();
}

$view = new \OC\Files\View($ownerView->getAbsolutePath($path));
$view = new \OC\Files\View($initiatorView->getAbsolutePath($path));
$filesDropPlugin->setView($view);

return $view;
Expand Down
11 changes: 5 additions & 6 deletions apps/dav/appinfo/v2/publicremote.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
}

$share = $authBackend->getShare();
$owner = $share->getShareOwner();
$isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ;
$fileId = $share->getNodeId();

Expand All @@ -130,10 +129,10 @@
Filesystem::logWarningWhenAddingStorageWrapper($previousLog);

OC_Util::tearDownFS();
OC_Util::setupFS($owner);
$ownerView = new View('/'. $owner . '/files');
$path = $ownerView->getPath($fileId);
$fileInfo = $ownerView->getFileInfo($path);
OC_Util::setupFS($share->getSharedBy());
$initiatorView = new View('/'. $share->getSharedBy() . '/files');
$path = $initiatorView->getPath($fileId);
$fileInfo = $initiatorView->getFileInfo($path);

if ($fileInfo === false) {
throw new NotFound();
Expand All @@ -146,7 +145,7 @@
$filesDropPlugin->enable();
}

$view = new View($ownerView->getAbsolutePath($path));
$view = new View($initiatorView->getAbsolutePath($path));
$filesDropPlugin->setView($view);

return $view;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Files/Sharing/PublicLinkCheckPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function initialize(\Sabre\DAV\Server $server) {
}

public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
// verify that the owner didn't have his share permissions revoked
// verify that the initiator didn't have their share permissions revoked
if ($this->fileInfo && !$this->fileInfo->isShareable()) {
throw new NotFound();
}
Expand Down
86 changes: 24 additions & 62 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,30 +160,30 @@
$share->setSharedWith($cloudId->getId());

try {
$remoteShare = $this->getShareFromExternalShareTable($share);
$remoteShare = $this->getShareFromExternalShareTable($share->getShareOwner(), $share->getTarget());
} catch (ShareNotFound $e) {
$remoteShare = null;
}

if ($remoteShare) {
try {
$ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time(), $shareType, $expirationDate);
$share->setId($shareId);
[$token, $remoteId] = $this->askOwnerToReShare($shareWith, $share, $shareId);
// remote share was create successfully if we get a valid token as return
$send = is_string($token) && $token !== '';
} catch (\Exception $e) {
// fall back to old re-share behavior if the remote server
// doesn't support flat re-shares (was introduced with Nextcloud 9.1)
$this->removeShareFromTable($share);
$shareId = $this->createFederatedShare($share);
}
if ($send) {
$ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
$shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time(), $shareType, $expirationDate);

Check notice

Code scanning / Psalm

PossiblyNullArgument Note

Argument 9 of OCA\FederatedFileSharing\FederatedShareProvider::addShareToDB cannot be null, possibly null value provided
[$token, $remoteId] = $this->notifications->requestReShare(

Check failure on line 171 in apps/federatedfilesharing/lib/FederatedShareProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooManyArguments

apps/federatedfilesharing/lib/FederatedShareProvider.php:171:48: TooManyArguments: Too many arguments for method OCA\FederatedFileSharing\Notifications::requestreshare - saw 8 (see https://psalm.dev/026)

Check failure

Code scanning / Psalm

TooManyArguments Error

Too many arguments for method OCA\FederatedFileSharing\Notifications::requestreshare - saw 8

Check notice

Code scanning / Psalm

PossiblyInvalidArrayAccess Note

Cannot access array value on non-array variable of type false

Check notice

Code scanning / Psalm

PossiblyInvalidArrayAccess Note

Cannot access array value on non-array variable of type false
$remoteShare['share_token'],
$remoteShare['remote_id'],
$shareId,

Check notice

Code scanning / Psalm

InvalidArgument Note

Argument 3 of OCA\FederatedFileSharing\Notifications::requestReShare expects string, but int provided
$remoteShare['remote'],
$shareWith,
$permissions,
$share->getNode()->getName(),
$shareType,
);
// remote share was create successfully if we get a valid token as return
if (is_string($token) && $token !== '') {
$this->updateSuccessfulReshare($shareId, $token);
$this->storeRemoteId($shareId, $remoteId);
} else {
$this->removeShareFromTable($share);
$this->removeShareFromTable($shareId);

Check failure on line 186 in apps/federatedfilesharing/lib/FederatedShareProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

apps/federatedfilesharing/lib/FederatedShareProvider.php:186:33: InvalidScalarArgument: Argument 1 of OCA\FederatedFileSharing\FederatedShareProvider::removeShareFromTable expects string, but int provided (see https://psalm.dev/012)

Check failure

Code scanning / Psalm

InvalidScalarArgument Error

Argument 1 of OCA\FederatedFileSharing\FederatedShareProvider::removeShareFromTable expects string, but int provided
$message_t = $this->l->t('File is already shared with %s', [$shareWith]);
throw new \Exception($message_t);
}
Expand Down Expand Up @@ -250,7 +250,7 @@
}

if ($failure) {
$this->removeShareFromTableById($shareId);
$this->removeShareFromTable($shareId);

Check failure on line 253 in apps/federatedfilesharing/lib/FederatedShareProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

apps/federatedfilesharing/lib/FederatedShareProvider.php:253:32: InvalidScalarArgument: Argument 1 of OCA\FederatedFileSharing\FederatedShareProvider::removeShareFromTable expects string, but int provided (see https://psalm.dev/012)

Check failure

Code scanning / Psalm

InvalidScalarArgument Error

Argument 1 of OCA\FederatedFileSharing\FederatedShareProvider::removeShareFromTable expects string, but int provided
$message_t = $this->l->t('Sharing %1$s failed, could not find %2$s, maybe the server is currently unreachable or uses a self-signed certificate.',
[$share->getNode()->getName(), $share->getSharedWith()]);
throw new \Exception($message_t);
Expand All @@ -259,45 +259,18 @@
return $shareId;
}

/**
* @param string $shareWith
* @param IShare $share
* @param string $shareId internal share Id
* @return array
* @throws \Exception
*/
protected function askOwnerToReShare($shareWith, IShare $share, $shareId) {
$remoteShare = $this->getShareFromExternalShareTable($share);
$token = $remoteShare['share_token'];
$remoteId = $remoteShare['remote_id'];
$remote = $remoteShare['remote'];

[$token, $remoteId] = $this->notifications->requestReShare(
$token,
$remoteId,
$shareId,
$remote,
$shareWith,
$share->getPermissions(),
$share->getNode()->getName()
);

return [$token, $remoteId];
}

/**
* get federated share from the share_external table but exclude mounted link shares
*
* @param IShare $share
* @return array
* @throws ShareNotFound
*/
protected function getShareFromExternalShareTable(IShare $share) {
protected function getShareFromExternalShareTable(string $owner, string $target) {
$query = $this->dbConnection->getQueryBuilder();
$query->select('*')->from($this->externalShareTable)
->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner())))
->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget())));
$qResult = $query->execute();
->where($query->expr()->eq('user', $query->createNamedParameter($owner)))
->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($target)));
$qResult = $query->executeQuery();
$result = $qResult->fetchAll();
$qResult->closeCursor();

Expand Down Expand Up @@ -505,7 +478,7 @@

// only remove the share when all messages are send to not lose information
// about the share to early
$this->removeShareFromTable($share);
$this->removeShareFromTable($share->getId());
}

/**
Expand Down Expand Up @@ -536,20 +509,9 @@
}

/**
* remove share from table
*
* @param IShare $share
*/
public function removeShareFromTable(IShare $share) {
$this->removeShareFromTableById($share->getId());
}

/**
* remove share from table
*
* @param string $shareId
* Remove share from table.
*/
private function removeShareFromTableById($shareId) {
public function removeShareFromTable(string $shareId): void {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ protected function shareDeclined($id, array $notification) {
* @param IShare $share
* @throws ShareNotFound
*/
protected function executeDeclineShare(IShare $share) {
$this->federatedShareProvider->removeShareFromTable($share);
protected function executeDeclineShare(IShare $share): void {
$this->federatedShareProvider->removeShareFromTable($share->getId());

try {
$fileId = (int)$share->getNode()->getId();
Expand Down Expand Up @@ -437,7 +437,7 @@ private function undoReshare($id, array $notification) {
$share = $this->federatedShareProvider->getShareById($id);

$this->verifyShare($share, $token);
$this->federatedShareProvider->removeShareFromTable($share);
$this->federatedShareProvider->removeShareFromTable($share->getId());
return [];
}

Expand Down
Loading
Loading