-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
[stable30] Fix federated reshares #58992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stable30
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| [$token, $remoteId] = $this->notifications->requestReShare( | ||
|
Check failure on line 141 in apps/federatedfilesharing/lib/FederatedShareProvider.php
|
||
Check failureCode scanning / Psalm TooManyArguments Error
Too many arguments for method OCA\FederatedFileSharing\Notifications::requestreshare - saw 8
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some changes may be missing, the shareType param is not in Check noticeCode scanning / Psalm PossiblyInvalidArrayAccess Note
Cannot access array value on non-array variable of type false
Check noticeCode scanning / Psalm PossiblyInvalidArrayAccess Note
Cannot access array value on non-array variable of type false
|
||
| $remoteShare['share_token'], | ||
| $remoteShare['remote_id'], | ||
| $shareId, | ||
Check noticeCode 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
|
||
Check failureCode 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); | ||
| } | ||
|
|
@@ -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(); | ||
|
|
@@ -183,7 +183,7 @@ | |
| $share->getShareOwner(), | ||
| $share->getPermissions(), | ||
| $token, | ||
| $share->getShareType(), | ||
| $share->getExpirationDate() | ||
| ); | ||
|
|
||
|
|
@@ -220,7 +220,7 @@ | |
| } | ||
|
|
||
| if ($failure) { | ||
| $this->removeShareFromTableById($shareId); | ||
| $this->removeShareFromTable($shareId); | ||
|
Check failure on line 223 in apps/federatedfilesharing/lib/FederatedShareProvider.php
|
||
Check failureCode 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); | ||
|
|
@@ -230,6 +230,7 @@ | |
| } | ||
|
|
||
| /** | ||
| <<<<<<< HEAD | ||
| * @param string $shareWith | ||
| * @param IShare $share | ||
| * @param string $shareId internal share Id | ||
|
|
@@ -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
|
||
| $token = $remoteShare['share_token']; | ||
| $remoteId = $remoteShare['remote_id']; | ||
| $remote = $remoteShare['remote']; | ||
|
|
@@ -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(); | ||
|
|
||
|
|
@@ -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()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -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))) | ||
|
|
||
Check notice
Code scanning / Psalm
PossiblyNullArgument Note
There was a problem hiding this comment.
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
createNamedParameterhandles this correctly.