-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add new share type for federated groups #34132
Changes from all commits
f2b5edf
a7e8a78
47eca65
30425db
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
* @author Bjoern Schiessle <[email protected]> | ||
* @author Christoph Wurst <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Sandro Mesterheide <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -177,6 +178,10 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $ | |
} | ||
} | ||
|
||
if ($shareType === 'federation') { | ||
// Allow creation of pending shares by federation provider | ||
} | ||
|
||
// if no explicit display name is given, we use the uid as display name | ||
$ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName; | ||
$sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName; | ||
|
@@ -188,7 +193,7 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $ | |
} | ||
|
||
try { | ||
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); | ||
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType, $shareType); | ||
$share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType); | ||
$share->setProtocol($protocol); | ||
$provider->shareReceived($share); | ||
|
@@ -249,7 +254,7 @@ public function receiveNotification($notificationType, $resourceType, $providerI | |
} | ||
|
||
try { | ||
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType); | ||
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType, $notification['shareType']); | ||
$result = $provider->notificationReceived($notificationType, $providerId, $notification); | ||
} catch (ProviderDoesNotExistsException $e) { | ||
return new JSONResponse( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
* @author Richard Steinmetz <[email protected]> | ||
* @author Robin Appelman <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Sandro Mesterheide <[email protected]> | ||
* @author Valdnet <[email protected]> | ||
* @author Vincent Petry <[email protected]> | ||
* @author waleczny <[email protected]> | ||
|
@@ -320,7 +321,15 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array | |
$result = array_merge($result, $this->getDeckShareHelper()->formatShare($share)); | ||
} catch (QueryException $e) { | ||
} | ||
} | ||
} elseif ($share->getShareType() === IShare::TYPE_FEDERATED_GROUP) { | ||
$group = $this->groupManager->get($share->getSharedWith()); | ||
$result['share_with'] = $share->getSharedWith(); | ||
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); | ||
try { | ||
$result = array_merge($result, $this->getFederatedGroupShareHelper()->formatShare($share)); | ||
} catch (QueryException $e) { | ||
} | ||
} | ||
|
||
|
||
$result['mail_send'] = $share->getMailSend() ? 1 : 0; | ||
|
@@ -648,7 +657,7 @@ public function createShare( | |
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); | ||
} | ||
} | ||
} elseif ($shareType === IShare::TYPE_REMOTE_GROUP) { | ||
} elseif ($shareType === IShare::TYPE_REMOTE_GROUP || $shareType === IShare::TYPE_FEDERATED_GROUP) { | ||
if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { | ||
throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$node->getPath(), $shareType])); | ||
} | ||
|
@@ -1609,6 +1618,16 @@ private function getShareById(string $id): IShare { | |
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { | ||
throw new ShareNotFound(); | ||
} | ||
|
||
try { | ||
if ($this->shareManager->shareProviderExists(IShare::TYPE_FEDERATED_GROUP)) { | ||
$share = $this->shareManager->getShareById('ocFederatedGroupShare:' . $id, $this->currentUser); | ||
return $share; | ||
} | ||
} catch (ShareNotFound $e) { | ||
// Do nothing, just try the other share type | ||
} | ||
|
||
$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser); | ||
|
||
return $share; | ||
|
@@ -1669,6 +1688,23 @@ private function getDeckShareHelper() { | |
return $this->serverContainer->get('\OCA\Deck\Sharing\ShareAPIHelper'); | ||
} | ||
|
||
/** | ||
* Returns the helper of ShareAPIHelper for federated group shares. | ||
* | ||
* If the VO federation application is not enabled or the helper is not available | ||
* a QueryException is thrown instead. | ||
* | ||
* @return \OCA\VO_Federation\Sharing\ShareAPIHelper | ||
* @throws QueryException | ||
*/ | ||
private function getFederatedGroupShareHelper() { | ||
if (!$this->appManager->isEnabledForUser('vo_federation')) { | ||
throw new QueryException(); | ||
Check failure Code scanning / Psalm UndefinedDocblockClass
Docblock-defined class, interface or enum named OCA\VO_Federation\Sharing\ShareAPIHelper does not exist
|
||
} | ||
|
||
return $this->serverContainer->get('\OCA\VO_Federation\Sharing\ShareAPIHelper'); | ||
} | ||
|
||
Check notice Code scanning / Psalm DeprecatedClass
OCP\AppFramework\QueryException is marked deprecated
|
||
/** | ||
* @param string $viewer | ||
* @param Node $node | ||
|
@@ -1710,6 +1746,12 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array | |
$federatedShares = $this->shareManager->getSharesBy( | ||
$this->currentUser, IShare::TYPE_REMOTE_GROUP, $node, $reShares, -1, 0 | ||
); | ||
if ($this->shareManager->shareProviderExists(IShare::TYPE_FEDERATED_GROUP)) { | ||
$federatedGroupShares = $this->shareManager->getSharesBy( | ||
$this->currentUser, IShare::TYPE_FEDERATED_GROUP, $node, $reShares, -1, 0 | ||
); | ||
$federatedShares = array_merge($federatedShares, $federatedGroupShares); | ||
} | ||
$shares = array_merge($shares, $federatedShares); | ||
} | ||
|
||
|
@@ -1840,18 +1882,18 @@ private function getAllShares(?Node $path = null, bool $reshares = false) { | |
$deckShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_DECK, $path, $reshares, -1, 0); | ||
|
||
// FEDERATION | ||
$federatedShares = []; | ||
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { | ||
$federatedShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE, $path, $reshares, -1, 0); | ||
} else { | ||
$federatedShares = []; | ||
$remoteShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE, $path, $reshares, -1, 0); | ||
$federatedShares = array_merge($federatedShares, $remoteShares); | ||
} | ||
if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) { | ||
$federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE_GROUP, $path, $reshares, -1, 0); | ||
} else { | ||
$federatedGroupShares = []; | ||
$remoteGroupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE_GROUP, $path, $reshares, -1, 0); | ||
$federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_FEDERATED_GROUP, $path, $reshares, -1, 0); | ||
$federatedShares = array_merge($federatedShares, $remoteGroupShares, $federatedGroupShares); | ||
} | ||
|
||
return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $deckShares, $federatedShares, $federatedGroupShares); | ||
return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $deckShares, $federatedShares); | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
* @author Morris Jobke <[email protected]> | ||
* @author Robin Appelman <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Sandro Mesterheide <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -82,6 +83,7 @@ class ShareesAPIController extends OCSController { | |
'groups' => [], | ||
'remotes' => [], | ||
'remote_groups' => [], | ||
'federated_groups' => [], | ||
'emails' => [], | ||
'circles' => [], | ||
'rooms' => [], | ||
|
@@ -91,6 +93,7 @@ class ShareesAPIController extends OCSController { | |
'groups' => [], | ||
'remotes' => [], | ||
'remote_groups' => [], | ||
'federated_groups' => [], | ||
'emails' => [], | ||
'lookup' => [], | ||
'circles' => [], | ||
|
@@ -178,6 +181,10 @@ public function search(string $search = '', string $itemType = null, int $page = | |
|
||
if ($this->isRemoteGroupSharingAllowed($itemType)) { | ||
$shareTypes[] = IShare::TYPE_REMOTE_GROUP; | ||
|
||
if ($this->shareManager->shareProviderExists(IShare::TYPE_FEDERATED_GROUP)) { | ||
$shareTypes[] = IShare::TYPE_FEDERATED_GROUP; | ||
} | ||
} | ||
|
||
if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) { | ||
|
@@ -284,6 +291,7 @@ private function sortShareesByFrequency(array $sharees): array { | |
IShare::TYPE_GROUP => 'groups', | ||
IShare::TYPE_REMOTE => 'remotes', | ||
IShare::TYPE_REMOTE_GROUP => 'remote_groups', | ||
IShare::TYPE_FEDERATED_GROUP => 'federated_groups', | ||
IShare::TYPE_EMAIL => 'emails', | ||
]; | ||
|
||
|
@@ -356,6 +364,10 @@ public function findRecommended(string $itemType = null, $shareType = null): Dat | |
|
||
if ($this->isRemoteGroupSharingAllowed($itemType)) { | ||
$shareTypes[] = IShare::TYPE_REMOTE_GROUP; | ||
|
||
if ($this->shareManager->shareProviderExists(IShare::TYPE_FEDERATED_GROUP)) { | ||
$shareTypes[] = IShare::TYPE_FEDERATED_GROUP; | ||
} | ||
} | ||
|
||
if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023 Sandro Mesterheide <[email protected]> | ||
* | ||
* @author Sandro Mesterheide <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Files_Sharing\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\DB\Types; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
/** | ||
* Auto-generated migration step: Please modify to your needs! | ||
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. Please remove the autocomment and instead add a line explaining what the migration do. |
||
*/ | ||
class Version26000Date20230117143027 extends SimpleMigrationStep { | ||
/** | ||
* @param IOutput $output | ||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
* @param array $options | ||
* @return null|ISchemaWrapper | ||
*/ | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
$table = $schema->getTable('share_external'); | ||
$changed = false; | ||
|
||
$column = $table->getColumn('user'); | ||
if ($column->getLength() < 255) { | ||
$column->setLength(255); | ||
$changed = true; | ||
} | ||
|
||
if (!$table->hasColumn('remote_share_type')) { | ||
$table->addColumn('remote_share_type', Types::INTEGER, [ | ||
'notnull' => false, | ||
'length' => 4, | ||
]); | ||
$changed = true; | ||
} | ||
|
||
if ($changed) { | ||
return $schema; | ||
} | ||
|
||
return null; | ||
} | ||
} |
Check failure
Code scanning / Psalm
UndefinedDocblockClass