diff --git a/apps/federatedfilesharing/lib/Controller/OcmController.php b/apps/federatedfilesharing/lib/Controller/OcmController.php index d739d268e633..6f0b9c219476 100644 --- a/apps/federatedfilesharing/lib/Controller/OcmController.php +++ b/apps/federatedfilesharing/lib/Controller/OcmController.php @@ -177,6 +177,23 @@ public function createShare( $resourceType, $protocol ) { + // Allow the Federated Groups app to overwrite the behaviour of this endpoint (but only for group shares) + if (\OC::$server->getAppManager()->isEnabledForUser('federatedgroups') && ($shareType === 'group')) { + $controller = \OCA\FederatedGroups\Application::getOcmController($this->request); + return $controller->createShare( + $shareWith, + $name, + $description, + $providerId, + $owner, + $ownerDisplayName, + $sender, + $senderDisplayName, + $shareType, + $resourceType, + $protocol + ); + } try { $this->ocmMiddleware->assertIncomingSharingEnabled(); $this->ocmMiddleware->assertNotNull( @@ -284,6 +301,17 @@ public function processNotification( $providerId, $notification ) { + // Allow the Federated Groups app to overwrite the behaviour of this endpoint + if (\OC::$server->getAppManager()->isEnabledForUser('federatedgroups')) { + $controller = \OCA\FederatedGroups\Application::getOcmController($this->request); + return $controller->processNotification( + $notificationType, + $resourceType, + $providerId, + $notification + ); + } + try { if (!\is_array($notification)) { throw new BadRequestException( diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js index e9eb3ac5d9ca..41afb6d45b7e 100644 --- a/apps/files_sharing/js/external.js +++ b/apps/files_sharing/js/external.js @@ -142,16 +142,20 @@ shares[index], false, function(result, share) { + let shareType = "user"; + if (share.hasOwnProperty('share_type') ){ + shareType = share.share_type; + } if (result) { // Accept - $.post(OC.generateUrl('/apps/files_sharing/api/externalShares'), {id: share.id}) + $.post(OC.generateUrl('/apps/files_sharing/api/externalShares'), {id: share.id, share_type: shareType }) .then(function() { fileList.reload(); }); } else { // Delete $.ajax({ - url: OC.generateUrl('/apps/files_sharing/api/externalShares/'+share.id), + url: OC.generateUrl('/apps/files_sharing/api/externalShares/'+share.id+"?share_type="+shareType), type: 'DELETE' }); } diff --git a/apps/files_sharing/lib/Controller/Share20OcsController.php b/apps/files_sharing/lib/Controller/Share20OcsController.php index 38e9f141257c..4d8fbc376abc 100644 --- a/apps/files_sharing/lib/Controller/Share20OcsController.php +++ b/apps/files_sharing/lib/Controller/Share20OcsController.php @@ -552,7 +552,7 @@ public function createShare() { if ($password !== '') { $share->setPassword($password); } - } elseif ($shareType === Share::SHARE_TYPE_REMOTE) { + } elseif ($shareType === Share::SHARE_TYPE_REMOTE || $shareType === Share::SHARE_TYPE_REMOTE_GROUP) { if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { $share->getNode()->unlock(ILockingProvider::LOCK_SHARED); return new Result(null, 403, $this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); diff --git a/apps/files_sharing/lib/Controllers/ExternalSharesController.php b/apps/files_sharing/lib/Controllers/ExternalSharesController.php index 62e0cf2794db..02db6ef4acb4 100644 --- a/apps/files_sharing/lib/Controllers/ExternalSharesController.php +++ b/apps/files_sharing/lib/Controllers/ExternalSharesController.php @@ -39,8 +39,11 @@ * @package OCA\Files_Sharing\Controllers */ class ExternalSharesController extends Controller { + /** @var \OCA\Files_Sharing\External\Manager */ private $externalManager; + /** @var \OCA\Files_Sharing\External\Manager */ + private $groupExternalManager = null; /** @var IClientService */ private $clientService; /** @@ -68,6 +71,9 @@ public function __construct( $this->externalManager = $externalManager; $this->clientService = $clientService; $this->dispatcher = $eventDispatcher; + if (\OC::$server->getAppManager()->isEnabledForUser('federatedgroups')) { + $this->groupExternalManager = \OCA\FederatedGroups\Application::getExternalManager(); + } } /** @@ -77,7 +83,12 @@ public function __construct( * @return JSONResponse */ public function index() { - return new JSONResponse($this->externalManager->getOpenShares()); + $federatedGroupResult = []; + if ($this->groupExternalManager !== null) { + $federatedGroupResult = $this->groupExternalManager->getOpenShares(); + } + $result = array_merge($federatedGroupResult, $this->externalManager->getOpenShares()); + return new JSONResponse($result); } /** @@ -87,11 +98,17 @@ public function index() { * @param int $id * @return JSONResponse */ - public function create($id) { - $shareInfo = $this->externalManager->getShare($id); + public function create($id, $share_type) { + if($share_type === "group" && $this->groupExternalManager !== null) { + $manager = $this->groupExternalManager; + } else { + $manager = $this->externalManager; + } + $shareInfo = $manager->getShare($id); + if ($shareInfo !== false) { - $mountPoint = $this->externalManager->getShareRecipientMountPoint($shareInfo); - $fileId = $this->externalManager->getShareFileId($shareInfo, $mountPoint); + $mountPoint = $manager->getShareRecipientMountPoint($shareInfo); + $fileId = $manager->getShareFileId($shareInfo, $mountPoint); $event = new GenericEvent( null, @@ -105,7 +122,7 @@ public function create($id) { 'shareRecipient' => $shareInfo['user'], ] ); - $this->dispatcher->dispatch($event, 'remoteshare.accepted'); + $this->dispatcher->dispatch($event, 'remoteshare.accepted', $event); $this->externalManager->acceptShare($id); } return new JSONResponse(); diff --git a/lib/private/Share/Constants.php b/lib/private/Share/Constants.php index 8583b6da6b33..908e27395382 100644 --- a/lib/private/Share/Constants.php +++ b/lib/private/Share/Constants.php @@ -31,6 +31,7 @@ class Constants { public const SHARE_TYPE_GUEST = 4; public const SHARE_TYPE_CONTACT = 5; // ToDo Check if it is still in use otherwise remove it public const SHARE_TYPE_REMOTE = 6; + public const SHARE_TYPE_REMOTE_GROUP = 7; public const CONVERT_SHARE_TYPE_TO_STRING = [ self::SHARE_TYPE_USER => 'user', @@ -39,6 +40,7 @@ class Constants { self::SHARE_TYPE_GUEST => 'guest', self::SHARE_TYPE_CONTACT => 'contact', self::SHARE_TYPE_REMOTE => 'remote', + self::SHARE_TYPE_REMOTE_GROUP => 'remote_group', ]; /** diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index d06983a68bff..ed9a56cd13e8 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -254,7 +254,7 @@ protected function generalChecks(\OCP\Share\IShare $share) { if ($share->getSharedWith() !== null) { throw new \InvalidArgumentException('SharedWith should be empty'); } - } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { + } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE || $share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { if ($share->getSharedWith() === null) { throw new \InvalidArgumentException('SharedWith should not be empty'); } diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 243a702cc564..9200d1b57566 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -130,7 +130,7 @@ public function getProviderForType($shareType) { $shareType === \OCP\Share::SHARE_TYPE_GROUP || $shareType === \OCP\Share::SHARE_TYPE_LINK) { $provider = $this->defaultShareProvider(); - } elseif ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { + } elseif ($shareType === \OCP\Share::SHARE_TYPE_REMOTE || $shareType === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { $provider = $this->federatedShareProvider(); }