From 6c448ed4d5593395d74a5de411c7ebf7dd4d3f28 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Wed, 11 Jan 2023 10:23:51 +0000 Subject: [PATCH 1/5] OCM via ScienceMesh Signed-off-by: Michiel de Jong --- .../lib/Controller/ShareesController.php | 13 +++++ apps/files_sharing/tests/API/ShareesTest.php | 3 +- changelog/unreleased/40577 | 10 ++++ lib/public/Share/IRemoteShareesSearch.php | 49 +++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/40577 create mode 100644 lib/public/Share/IRemoteShareesSearch.php diff --git a/apps/files_sharing/lib/Controller/ShareesController.php b/apps/files_sharing/lib/Controller/ShareesController.php index d907c5f7a371..63ea141f7274 100644 --- a/apps/files_sharing/lib/Controller/ShareesController.php +++ b/apps/files_sharing/lib/Controller/ShareesController.php @@ -41,6 +41,7 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\Share; +use OCA\Files_Sharing\AppInfo\Application; use OCA\Files_Sharing\SharingBlacklist; use OCP\Util\UserSearch; @@ -381,6 +382,18 @@ protected function getGroups($search) { * @return void */ protected function getRemote($search) { + $pluginClass = $this->config->getSystemValue('sharing.remoteShareesSearch'); + if ($pluginClass !== '') { + $this->result['remotes'] = []; + $app = new Application(); + $container = $app->getContainer(); + /** @var \OCP\Share\IRemoteShareesSearch $plugin */ + $plugin = $container->query($pluginClass); + $result = $plugin->search($search); + $this->result['exact']['remotes'] = $result; + $this->reachedEndFor[] = 'remotes'; + return; + } $this->result['remotes'] = []; // Fetch remote search properties from app config /** diff --git a/apps/files_sharing/tests/API/ShareesTest.php b/apps/files_sharing/tests/API/ShareesTest.php index 364a5401ba6a..dd869cbfa1dd 100644 --- a/apps/files_sharing/tests/API/ShareesTest.php +++ b/apps/files_sharing/tests/API/ShareesTest.php @@ -1513,7 +1513,8 @@ public function testGetRemote($searchTerm, $contacts, $shareeEnumeration, $exact $configMap = [ ['trusted_domains', [], ['trusted.domain.tld', 'trusted2.domain.tld']], - ['accounts.enable_medial_search', true, true] + ['accounts.enable_medial_search', true, true], + ['sharing.remoteShareesSearch', '', ''] ]; $this->config->expects($this->any()) diff --git a/changelog/unreleased/40577 b/changelog/unreleased/40577 new file mode 100644 index 000000000000..02ebc8dcb44e --- /dev/null +++ b/changelog/unreleased/40577 @@ -0,0 +1,10 @@ +Enhancement: Add support for OCM via ScienceMesh + + +We've added an if-statement in the files_sharing ShareesController +code that searches for remote sharees. When the 'sciencemesh' app +is installed, use it instead of the federatedfilesharing app to +find sharee matches for OCM sharing. + +https://github.com/owncloud/core/issues/40577 +https://github.com/pondersource/oc-sciencemesh/pull/39 \ No newline at end of file diff --git a/lib/public/Share/IRemoteShareesSearch.php b/lib/public/Share/IRemoteShareesSearch.php new file mode 100644 index 000000000000..0f3ce75d97e1 --- /dev/null +++ b/lib/public/Share/IRemoteShareesSearch.php @@ -0,0 +1,49 @@ + + * + * @copyright Copyright (c) 2018, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + * + */ + +namespace OCP\Share; + +/** + * Interface IRemoteShareesSearch + * Used in the ShareesController of the files_sharing app. + * See the 'sciencemesh' app for an example implementation + * of this interface. + * + * @package OCP\Share + * @since 10.12.0 + */ +interface IRemoteShareesSearch { + /** + * Return the identifier of this provider. + * @param string search string for autocomplete + * @return array[] this function should return an array + * where each element is an associative array, containing: + * - label: a string to display as label + * - value: an associative array containing: + * - shareType: int, to be used as share type + * - shareWith: string, identifying the sharee + * - server (optional): string, URL of the server, e.g. + * https://github.com/owncloud/core/blob/v10.12.0-beta.1/apps/files_sharing/lib/Controller/ShareesController.php#L421 + * + * @since 10.12.0 + */ + public function search($search); +} From ca3e29a6fb77b6ae387199027bda08be428656f1 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Mon, 20 Feb 2023 10:04:17 +0000 Subject: [PATCH 2/5] Get plugin from \OC::$server->query() --- apps/files_sharing/lib/Controller/ShareesController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareesController.php b/apps/files_sharing/lib/Controller/ShareesController.php index 63ea141f7274..09325535ff3f 100644 --- a/apps/files_sharing/lib/Controller/ShareesController.php +++ b/apps/files_sharing/lib/Controller/ShareesController.php @@ -385,10 +385,8 @@ protected function getRemote($search) { $pluginClass = $this->config->getSystemValue('sharing.remoteShareesSearch'); if ($pluginClass !== '') { $this->result['remotes'] = []; - $app = new Application(); - $container = $app->getContainer(); /** @var \OCP\Share\IRemoteShareesSearch $plugin */ - $plugin = $container->query($pluginClass); + $plugin = \OC::$server->query($pluginClass); $result = $plugin->search($search); $this->result['exact']['remotes'] = $result; $this->reachedEndFor[] = 'remotes'; From bee4fbd782baeeb4d2ec9ce787ed1b66900513d0 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Mon, 20 Feb 2023 14:27:06 +0100 Subject: [PATCH 3/5] Improve changelog entry Signed-off-by: Michiel de Jong --- changelog/unreleased/40577 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/changelog/unreleased/40577 b/changelog/unreleased/40577 index 02ebc8dcb44e..a24d91587eee 100644 --- a/changelog/unreleased/40577 +++ b/changelog/unreleased/40577 @@ -2,9 +2,11 @@ Enhancement: Add support for OCM via ScienceMesh We've added an if-statement in the files_sharing ShareesController -code that searches for remote sharees. When the 'sciencemesh' app -is installed, use it instead of the federatedfilesharing app to -find sharee matches for OCM sharing. +code that searches for remote sharees. When `sharing.remoteShareesSearch` +defines a plugin that implements `IRemoteShareesSearch`, for instance the +'ScienceMeshSearchPlugin' from the 'sciencemesh' app or similar, +use it instead of the federatedfilesharing app to find sharee matches for +OCM sharing. https://github.com/owncloud/core/issues/40577 -https://github.com/pondersource/oc-sciencemesh/pull/39 \ No newline at end of file +https://github.com/pondersource/oc-sciencemesh/pull/39 From ac6ff69b759a8bae9a29a97d39de5e793c3b316c Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Mon, 20 Feb 2023 14:30:13 +0100 Subject: [PATCH 4/5] improve changelog entry Signed-off-by: Michiel de Jong --- changelog/unreleased/40577 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/changelog/unreleased/40577 b/changelog/unreleased/40577 index a24d91587eee..b6977f3bd031 100644 --- a/changelog/unreleased/40577 +++ b/changelog/unreleased/40577 @@ -2,11 +2,12 @@ Enhancement: Add support for OCM via ScienceMesh We've added an if-statement in the files_sharing ShareesController -code that searches for remote sharees. When `sharing.remoteShareesSearch` -defines a plugin that implements `IRemoteShareesSearch`, for instance the -'ScienceMeshSearchPlugin' from the 'sciencemesh' app or similar, -use it instead of the federatedfilesharing app to find sharee matches for -OCM sharing. +code that searches for remote sharees. When the config entry +`sharing.remoteShareesSearch` is set to the name of a class that +is registered in the server container and that implements +`IRemoteShareesSearch`, for instance the 'ScienceMeshSearchPlugin' +that the 'sciencemesh' app registers, use it instead of the +federatedfilesharing app to find sharee matches for OCM sharing. https://github.com/owncloud/core/issues/40577 https://github.com/pondersource/oc-sciencemesh/pull/39 From 838d8819411aee8d661e2b29514efca6d101eefc Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Tue, 21 Feb 2023 14:29:21 +0100 Subject: [PATCH 5/5] Whitespace change to re-trigger CI Signed-off-by: Michiel de Jong --- changelog/unreleased/40577 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog/unreleased/40577 b/changelog/unreleased/40577 index b6977f3bd031..42b493dfab80 100644 --- a/changelog/unreleased/40577 +++ b/changelog/unreleased/40577 @@ -3,8 +3,8 @@ Enhancement: Add support for OCM via ScienceMesh We've added an if-statement in the files_sharing ShareesController code that searches for remote sharees. When the config entry -`sharing.remoteShareesSearch` is set to the name of a class that -is registered in the server container and that implements +`sharing.remoteShareesSearch` is set to the name of a class +that is registered in the server container and that implements `IRemoteShareesSearch`, for instance the 'ScienceMeshSearchPlugin' that the 'sciencemesh' app registers, use it instead of the federatedfilesharing app to find sharee matches for OCM sharing.