summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-09-06 21:57:00 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-09-26 23:10:23 +0200
commitf7713e5f3f14db6f15eeec2aba7cbbdcb70830ab (patch)
treed20f50d3dbcc458beca9f091cb9efecc50ddfa3a
parent4a96e222588104f647f911857e370b3ab692ea22 (diff)
downloadnextcloud-server-f7713e5f3f14db6f15eeec2aba7cbbdcb70830ab.tar.gz
nextcloud-server-f7713e5f3f14db6f15eeec2aba7cbbdcb70830ab.zip
make it possible to register plugins and kick out the circle one
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r--lib/private/App/InfoParser.php3
-rw-r--r--lib/private/Collaboration/Collaborators/CirclePlugin.php52
-rw-r--r--lib/private/Collaboration/Collaborators/Search.php27
-rw-r--r--lib/private/legacy/app.php5
-rw-r--r--lib/public/Collaboration/Collaborators/ISearch.php7
5 files changed, 32 insertions, 62 deletions
diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php
index fef8ab7a1e8..2b1eb759964 100644
--- a/lib/private/App/InfoParser.php
+++ b/lib/private/App/InfoParser.php
@@ -165,6 +165,9 @@ class InfoParser {
if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) {
$array['activity']['providers'] = $array['activity']['providers']['provider'];
}
+ if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])) {
+ $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
+ }
if(!is_null($this->cache)) {
$this->cache->set($fileCacheKey, json_encode($array));
diff --git a/lib/private/Collaboration/Collaborators/CirclePlugin.php b/lib/private/Collaboration/Collaborators/CirclePlugin.php
deleted file mode 100644
index 951f70e968b..00000000000
--- a/lib/private/Collaboration/Collaborators/CirclePlugin.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @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 OC\Collaboration\Collaborators;
-
-
-use OCA\Circles\Api\Sharees;
-use OCP\Collaboration\Collaborators\ISearchPlugin;
-use OCP\Collaboration\Collaborators\ISearchResult;
-use OCP\Collaboration\Collaborators\SearchResultType;
-
-class CirclePlugin implements ISearchPlugin {
-
- public function search($search, $limit, $offset, ISearchResult $searchResult) {
- $result = ['wide' => [], 'exact' => []];
-
- if(\OC_App::isEnabled('circles')) {
- $circles = Sharees::search($search);
- if (array_key_exists('circles', $circles['exact'])) {
- $result['exact'] = $circles['exact']['circles'];
- }
- if (array_key_exists('circles', $circles)) {
- $result['wide'] = $circles['circles'];
- }
-
- $type = new SearchResultType('circles');
- $searchResult->addResultSet($type, $result['wide'], $result['exact']);
- }
-
- return false;
- }
-}
diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php
index 815b9eea3e9..97ec301ded5 100644
--- a/lib/private/Collaboration/Collaborators/Search.php
+++ b/lib/private/Collaboration/Collaborators/Search.php
@@ -34,6 +34,13 @@ class Search implements ISearch {
/** @var IContainer */
private $c;
+ protected $pluginList = [
+ Share::SHARE_TYPE_USER => UserPlugin::class,
+ Share::SHARE_TYPE_GROUP => GroupPlugin::class,
+ Share::SHARE_TYPE_EMAIL => MailPlugin::class,
+ Share::SHARE_TYPE_REMOTE => RemotePlugin::class,
+ ];
+
public function __construct(IContainer $c) {
$this->c = $c;
}
@@ -41,23 +48,15 @@ class Search implements ISearch {
public function search($search, array $shareTypes, $lookup, $limit, $offset) {
$hasMoreResults = false;
- $pluginList = [
- Share::SHARE_TYPE_USER => UserPlugin::class,
- Share::SHARE_TYPE_GROUP => GroupPlugin::class,
- Share::SHARE_TYPE_CIRCLE => CirclePlugin::class,
- Share::SHARE_TYPE_EMAIL => MailPlugin::class,
- Share::SHARE_TYPE_REMOTE => RemotePlugin::class,
- ];
-
/** @var ISearchResult $searchResult */
$searchResult = $this->c->resolve(SearchResult::class);
foreach ($shareTypes as $type) {
- if(!isset($pluginList[$type])) {
+ if(!isset($this->pluginList[$type])) {
continue;
}
/** @var ISearchPlugin $searchPlugin */
- $searchPlugin = $this->c->resolve($pluginList[$type]);
+ $searchPlugin = $this->c->resolve($this->pluginList[$type]);
$hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult);
}
@@ -82,4 +81,12 @@ class Search implements ISearch {
return [$searchResult->asArray(), $hasMoreResults];
}
+
+ public function registerPlugin(array $pluginInfo) {
+ $shareType = constant(Share::class . '::' . $pluginInfo['shareType']);
+ if($shareType === null) {
+ throw new \InvalidArgumentException('Provided ShareType is invalid');
+ }
+ $this->pluginList[$shareType] = $pluginInfo['class'];
+ }
}
diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php
index 24c7a344e00..cbbc9a46981 100644
--- a/lib/private/legacy/app.php
+++ b/lib/private/legacy/app.php
@@ -174,6 +174,11 @@ class OC_App {
\OC::$server->getActivityManager()->registerProvider($provider);
}
}
+ if (!empty($info['collaboration']['collaborators']['searchPlugins'])) {
+ foreach ($info['collaboration']['collaborators']['searchPlugins'] as $plugin) {
+ \OC::$server->getCollaboratorSearch()->registerPlugin($plugin);
+ }
+ }
}
/**
diff --git a/lib/public/Collaboration/Collaborators/ISearch.php b/lib/public/Collaboration/Collaborators/ISearch.php
index bed6066711e..281893908ee 100644
--- a/lib/public/Collaboration/Collaborators/ISearch.php
+++ b/lib/public/Collaboration/Collaborators/ISearch.php
@@ -40,4 +40,11 @@ interface ISearch {
* @since 13.0.0
*/
public function search($search, array $shareTypes, $lookup, $limit, $offset);
+
+ /**
+ * @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and
+ * 'class' with the class name of the plugin
+ * @since 13.0.0
+ */
+ public function registerPlugin(array $pluginInfo);
}