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
3 changes: 1 addition & 2 deletions apps/dav/appinfo/v1/publicwebdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
}

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

Expand All @@ -73,7 +72,7 @@
\OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog);

$rootFolder = \OCP\Server::get(\OCP\Files\IRootFolder::class);
$userFolder = $rootFolder->getUserFolder($owner);
$userFolder = $rootFolder->getUserFolder($share->getSharedBy());
$node = $userFolder->getFirstNodeById($fileId);
if (!$node) {
throw new \Sabre\DAV\Exception\NotFound();
Expand Down
3 changes: 1 addition & 2 deletions apps/dav/appinfo/v2/publicremote.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
}

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

Expand Down Expand Up @@ -113,7 +112,7 @@
Filesystem::logWarningWhenAddingStorageWrapper($previousLog);

$rootFolder = \OCP\Server::get(\OCP\Files\IRootFolder::class);
$userFolder = $rootFolder->getUserFolder($owner);
$userFolder = $rootFolder->getUserFolder($share->getSharedBy());
$node = $userFolder->getFirstNodeById($fileId);
if (!$node) {
throw new NotFound();
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 @@ -41,7 +41,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
63 changes: 27 additions & 36 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,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
Copy link
Contributor

Choose a reason for hiding this comment

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

The expiration column is nullable so null is acceptable, provided that createNamedParameter handles this correctly.

[$token, $remoteId] = $this->notifications->requestReShare(

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

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooManyArguments

apps/federatedfilesharing/lib/FederatedShareProvider.php:141: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
Copy link
Contributor

Choose a reason for hiding this comment

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

Some changes may be missing, the shareType param is not in requestReShare

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 156 in apps/federatedfilesharing/lib/FederatedShareProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

apps/federatedfilesharing/lib/FederatedShareProvider.php:156: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 All @@ -167,11 +167,11 @@

/**
* create federated share and inform the recipient
*
* @param IShare $share
* @return int
* @throws ShareNotFound
* @throws \Exception
*/
protected function createFederatedShare(IShare $share) {
$token = $this->tokenHandler->generateToken();
Expand All @@ -183,7 +183,7 @@
$share->getShareOwner(),
$share->getPermissions(),
$token,
$share->getShareType(),
$share->getExpirationDate()
);

Expand Down Expand Up @@ -220,7 +220,7 @@
}

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

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

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

apps/federatedfilesharing/lib/FederatedShareProvider.php:223: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 @@ -230,6 +230,7 @@
}

/**
<<<<<<< HEAD
* @param string $shareWith
* @param IShare $share
* @param string $shareId internal share Id
Expand All @@ -237,7 +238,7 @@
* @throws \Exception
*/
protected function askOwnerToReShare($shareWith, IShare $share, $shareId) {
$remoteShare = $this->getShareFromExternalShareTable($share);

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

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooFewArguments

apps/federatedfilesharing/lib/FederatedShareProvider.php:241:25: TooFewArguments: Too few arguments for method OCA\FederatedFileSharing\FederatedShareProvider::getsharefromexternalsharetable saw 1 (see https://psalm.dev/025)

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

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooFewArguments

apps/federatedfilesharing/lib/FederatedShareProvider.php:241:25: TooFewArguments: Too few arguments for OCA\FederatedFileSharing\FederatedShareProvider::getShareFromExternalShareTable - expecting target to be passed (see https://psalm.dev/025)
$token = $remoteShare['share_token'];
$remoteId = $remoteShare['remote_id'];
$remote = $remoteShare['remote'];
Expand All @@ -249,25 +250,26 @@
$remote,
$shareWith,
$share->getPermissions(),
$share->getNode()->getName()
);

return [$token, $remoteId];
}

/**
=======
>>>>>>> 045ad43237c (fix(federatedfilesharing): Do not set the share id for an existing share)
* 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 @@ -475,7 +477,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 @@ -506,20 +508,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 @@ -382,8 +382,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 @@ -420,7 +420,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
51 changes: 34 additions & 17 deletions apps/federatedfilesharing/tests/FederatedShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public function testCreate($expirationDate, $expectedDataDate) {
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setExpirationDate($expirationDate)
->setNode($node);
->setNode($node)
->setTarget('');

$this->tokenHandler->method('generateToken')->willReturn('token');

Expand Down Expand Up @@ -234,7 +235,8 @@ public function testCreateCouldNotFindServer() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');

$this->tokenHandler->method('generateToken')->willReturn('token');

Expand Down Expand Up @@ -295,7 +297,8 @@ public function testCreateException() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');

$this->tokenHandler->method('generateToken')->willReturn('token');

Expand Down Expand Up @@ -403,7 +406,8 @@ public function testCreateAlreadyShared() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');

$this->tokenHandler->method('generateToken')->willReturn('token');

Expand Down Expand Up @@ -475,7 +479,8 @@ public function testUpdate($owner, $sharedBy, $expirationDate) {
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setExpirationDate(new \DateTime('2019-02-01T01:02:03'))
->setNode($node);
->setNode($node)
->setTarget('');

$this->tokenHandler->method('generateToken')->willReturn('token');
$this->addressHandler->expects($this->any())->method('generateRemoteURL')
Expand Down Expand Up @@ -552,7 +557,8 @@ public function testGetSharedBy() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share);

$share2 = $this->shareManager->newShare();
Expand All @@ -561,7 +567,8 @@ public function testGetSharedBy() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share2);

$shares = $this->provider->getSharesBy('sharedBy', IShare::TYPE_REMOTE, null, false, -1, 0);
Expand Down Expand Up @@ -596,7 +603,8 @@ public function testGetSharedByWithNode() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share);

$node2 = $this->getMockBuilder(File::class)->getMock();
Expand All @@ -609,7 +617,8 @@ public function testGetSharedByWithNode() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node2);
->setNode($node2)
->setTarget('');
$this->provider->create($share2);

$shares = $this->provider->getSharesBy('sharedBy', IShare::TYPE_REMOTE, $node2, false, -1, 0);
Expand Down Expand Up @@ -643,7 +652,8 @@ public function testGetSharedByWithReshares() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share);

$share2 = $this->shareManager->newShare();
Expand All @@ -652,7 +662,8 @@ public function testGetSharedByWithReshares() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share2);

$shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_REMOTE, null, true, -1, 0);
Expand Down Expand Up @@ -693,7 +704,8 @@ public function testGetSharedByWithLimit() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share);

$share2 = $this->shareManager->newShare();
Expand All @@ -702,7 +714,8 @@ public function testGetSharedByWithLimit() {
->setShareOwner('shareOwner')
->setPermissions(19)
->setShareType(IShare::TYPE_REMOTE)
->setNode($node);
->setNode($node)
->setTarget('');
$this->provider->create($share2);

$shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_REMOTE, null, true, 1, 1);
Expand Down Expand Up @@ -903,7 +916,8 @@ public function testGetSharesInFolder() {
->setShareOwner($u1->getUID())
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file1);
->setNode($file1)
->setTarget('');
$this->provider->create($share1);

$share2 = $this->shareManager->newShare();
Expand All @@ -912,7 +926,8 @@ public function testGetSharesInFolder() {
->setShareOwner($u1->getUID())
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file2);
->setNode($file2)
->setTarget('');
$this->provider->create($share2);

$result = $this->provider->getSharesInFolder($u1->getUID(), $folder1, false);
Expand Down Expand Up @@ -963,7 +978,8 @@ public function testGetAccessList() {
->setShareOwner($u1->getUID())
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file1);
->setNode($file1)
->setTarget('');
$this->provider->create($share1);

$share2 = $this->shareManager->newShare();
Expand All @@ -972,7 +988,8 @@ public function testGetAccessList() {
->setShareOwner($u1->getUID())
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setShareType(IShare::TYPE_REMOTE)
->setNode($file1);
->setNode($file1)
->setTarget('');
$this->provider->create($share2);

$result = $this->provider->getAccessList([$file1], true);
Expand Down
Loading