Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-08-30 11:56:02 +0300
committerArthur Schiwon <blizzz@arthur-schiwon.de>2017-10-22 15:13:32 +0300
commitfd6daf8d195b985fcdec82c0c53e8ba230765f41 (patch)
treedbfbbfb8424604daeb0fba63a8e0d2b7cda9a3ac /lib
parent2b31b8289169e35be7bb1b129e9a978ddcd8f478 (diff)
AutoCompletion backend
* introduce a Controller for requests * introduce result sorting mechanism * extend Comments to retrieve commentors (actors) in a tree * add commenters sorter * add share recipients sorter Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php4
-rw-r--r--lib/composer/composer/autoload_static.php4
-rw-r--r--lib/private/Collaboration/AutoComplete/Manager.php81
-rw-r--r--lib/private/Comments/Manager.php65
-rw-r--r--lib/private/Server.php12
-rw-r--r--lib/private/Share20/Manager.php2
-rw-r--r--lib/private/legacy/app.php2
-rw-r--r--lib/public/Collaboration/AutoComplete/IManager.php46
-rw-r--r--lib/public/Collaboration/AutoComplete/ISorter.php50
-rw-r--r--lib/public/Comments/ICommentsManager.php22
10 files changed, 287 insertions, 1 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 07f815f85ce..e522d82edf7 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -68,6 +68,8 @@ return array(
'OCP\\BackgroundJob\\IJobList' => $baseDir . '/lib/public/BackgroundJob/IJobList.php',
'OCP\\Capabilities\\ICapability' => $baseDir . '/lib/public/Capabilities/ICapability.php',
'OCP\\Capabilities\\IPublicCapability' => $baseDir . '/lib/public/Capabilities/IPublicCapability.php',
+ 'OCP\\Collaboration\\AutoComplete\\IManager' => $baseDir . '/lib/public/Collaboration/AutoComplete/IManager.php',
+ 'OCP\\Collaboration\\AutoComplete\\ISorter' => $baseDir . '/lib/public/Collaboration/AutoComplete/ISorter.php',
'OCP\\Collaboration\\Collaborators\\ISearch' => $baseDir . '/lib/public/Collaboration/Collaborators/ISearch.php',
'OCP\\Collaboration\\Collaborators\\ISearchPlugin' => $baseDir . '/lib/public/Collaboration/Collaborators/ISearchPlugin.php',
'OCP\\Collaboration\\Collaborators\\ISearchResult' => $baseDir . '/lib/public/Collaboration/Collaborators/ISearchResult.php',
@@ -389,6 +391,7 @@ return array(
'OC\\Cache\\CappedMemoryCache' => $baseDir . '/lib/private/Cache/CappedMemoryCache.php',
'OC\\Cache\\File' => $baseDir . '/lib/private/Cache/File.php',
'OC\\CapabilitiesManager' => $baseDir . '/lib/private/CapabilitiesManager.php',
+ 'OC\\Collaboration\\AutoComplete\\Manager' => $baseDir . '/lib/private/Collaboration/AutoComplete/Manager.php',
'OC\\Collaboration\\Collaborators\\GroupPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/GroupPlugin.php',
'OC\\Collaboration\\Collaborators\\LookupPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/LookupPlugin.php',
'OC\\Collaboration\\Collaborators\\MailPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/MailPlugin.php',
@@ -494,6 +497,7 @@ return array(
'OC\\Core\\Command\\User\\Report' => $baseDir . '/core/Command/User/Report.php',
'OC\\Core\\Command\\User\\ResetPassword' => $baseDir . '/core/Command/User/ResetPassword.php',
'OC\\Core\\Command\\User\\Setting' => $baseDir . '/core/Command/User/Setting.php',
+ 'OC\\Core\\Controller\\AutoCompleteController' => $baseDir . '/core/Controller/AutoCompleteController.php',
'OC\\Core\\Controller\\AvatarController' => $baseDir . '/core/Controller/AvatarController.php',
'OC\\Core\\Controller\\ClientFlowLoginController' => $baseDir . '/core/Controller/ClientFlowLoginController.php',
'OC\\Core\\Controller\\ContactsMenuController' => $baseDir . '/core/Controller/ContactsMenuController.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 0d327b7267f..4f538e9602e 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -98,6 +98,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\BackgroundJob\\IJobList' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/IJobList.php',
'OCP\\Capabilities\\ICapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/ICapability.php',
'OCP\\Capabilities\\IPublicCapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/IPublicCapability.php',
+ 'OCP\\Collaboration\\AutoComplete\\IManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/IManager.php',
+ 'OCP\\Collaboration\\AutoComplete\\ISorter' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/ISorter.php',
'OCP\\Collaboration\\Collaborators\\ISearch' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/ISearch.php',
'OCP\\Collaboration\\Collaborators\\ISearchPlugin' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/ISearchPlugin.php',
'OCP\\Collaboration\\Collaborators\\ISearchResult' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/ISearchResult.php',
@@ -419,6 +421,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Cache\\CappedMemoryCache' => __DIR__ . '/../../..' . '/lib/private/Cache/CappedMemoryCache.php',
'OC\\Cache\\File' => __DIR__ . '/../../..' . '/lib/private/Cache/File.php',
'OC\\CapabilitiesManager' => __DIR__ . '/../../..' . '/lib/private/CapabilitiesManager.php',
+ 'OC\\Collaboration\\AutoComplete\\Manager' => __DIR__ . '/../../..' . '/lib/private/Collaboration/AutoComplete/Manager.php',
'OC\\Collaboration\\Collaborators\\GroupPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/GroupPlugin.php',
'OC\\Collaboration\\Collaborators\\LookupPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/LookupPlugin.php',
'OC\\Collaboration\\Collaborators\\MailPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/MailPlugin.php',
@@ -524,6 +527,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Command\\User\\Report' => __DIR__ . '/../../..' . '/core/Command/User/Report.php',
'OC\\Core\\Command\\User\\ResetPassword' => __DIR__ . '/../../..' . '/core/Command/User/ResetPassword.php',
'OC\\Core\\Command\\User\\Setting' => __DIR__ . '/../../..' . '/core/Command/User/Setting.php',
+ 'OC\\Core\\Controller\\AutoCompleteController' => __DIR__ . '/../../..' . '/core/Controller/AutoCompleteController.php',
'OC\\Core\\Controller\\AvatarController' => __DIR__ . '/../../..' . '/core/Controller/AvatarController.php',
'OC\\Core\\Controller\\ClientFlowLoginController' => __DIR__ . '/../../..' . '/core/Controller/ClientFlowLoginController.php',
'OC\\Core\\Controller\\ContactsMenuController' => __DIR__ . '/../../..' . '/core/Controller/ContactsMenuController.php',
diff --git a/lib/private/Collaboration/AutoComplete/Manager.php b/lib/private/Collaboration/AutoComplete/Manager.php
new file mode 100644
index 00000000000..f801ea23338
--- /dev/null
+++ b/lib/private/Collaboration/AutoComplete/Manager.php
@@ -0,0 +1,81 @@
+<?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\AutoComplete;
+
+use OCP\Collaboration\AutoComplete\IManager;
+use OCP\Collaboration\AutoComplete\ISorter;
+use OCP\IServerContainer;
+
+class Manager implements IManager {
+ /** @var string[] */
+ protected $sorters =[];
+
+ /** @var ISorter[] */
+ protected $sorterInstances = [];
+ /** @var IServerContainer */
+ private $c;
+
+ public function __construct(IServerContainer $container) {
+ $this->c = $container;
+ }
+
+ public function runSorters(array $sorters, array &$sortArray, array $context) {
+ $sorterInstances = $this->getSorters();
+ while($sorter = array_shift($sorters)) {
+ if(isset($sorterInstances[$sorter])) {
+ $sorterInstances[$sorter]->sort($sortArray, $context);
+ } else {
+ $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [
+ 'app' => 'core', 'id' => $sorter
+ ]);
+ }
+ }
+ }
+
+ public function registerSorter($className) {
+ $sorters[] = $className;
+ }
+
+ protected function getSorters() {
+ if(count($this->sorterInstances) === 0) {
+ foreach ($this->sorters as $sorter) {
+ /** @var ISorter $instance */
+ $instance = $this->c->resolve($sorter);
+ if(!$instance instanceof ISorter) {
+ $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}',
+ ['app' => 'core', 'class' => $sorter]);
+ continue;
+ }
+ $sorterId = trim($instance->getId());
+ if(trim($sorterId) === '') {
+ $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}',
+ ['app' => 'core', 'class' => $sorter]);
+ continue;
+ }
+ $this->sorterInstances[$sorterId] = $instance;
+ }
+ }
+ return $this->sorterInstances;
+ }
+}
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index 078e1eef4d3..a6b2102da67 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -318,6 +318,71 @@ class Manager implements ICommentsManager {
}
/**
+ * Get the actor types and ID that commented in the tree specified by the ID
+ *
+ * @param string $id
+ * @return array
+ * @since 13.0.0
+ *
+ * The return array looks like this:
+ *
+ * [
+ * 'user' => [
+ * 'alice' => 2,
+ * 'bob' => 3
+ * ],
+ * 'robot' => [
+ * 'r2-d2' => 5,
+ * 'c-3po' => 17,
+ * ]
+ * ]
+ */
+ public function getActorsInTree($id) {
+ $tree = $this->getTree($id);
+ $actors = [];
+ $this->extractActor($tree, $actors);
+ return $actors;
+ }
+
+ /**
+ * @param array $node
+ * @param array &$actors
+ *
+ * build an array that looks like:
+ *
+ * [
+ * 'user' => [
+ * 'alice' => 2,
+ * 'bob' => 3
+ * ],
+ * 'robot' => [
+ * 'r2-d2' => 5,
+ * 'c-3po' => 17,
+ * ]
+ * ]
+ *
+ */
+ protected function extractActor(array $node, array &$actors) {
+ if(isset($node['replies'])) {
+ foreach ($node['replies'] as $subNode) {
+ $this->extractActor($subNode, $actors);
+ }
+ }
+ if(isset($node['comment']) && $node['comment'] instanceof IComment) {
+ /** @var IComment $comment */
+ $comment = $node['comment'];
+ if(!isset($actors[$comment->getActorType()])) {
+ $actors[$comment->getActorType()] = [];
+ }
+ if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) {
+ $actors[$comment->getActorType()][$comment->getActorId()] = 1;
+ } else {
+ $actors[$comment->getActorType()][$comment->getActorId()] += 1;
+ }
+ }
+ }
+
+ /**
* returns comments for a specific object (e.g. a file).
*
* The sort order is always newest to oldest.
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 29aee06d896..c03b7e04606 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1011,6 +1011,11 @@ class Server extends ServerContainer implements IServerContainer {
});
$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
+ $this->registerService(\OCP\Collaboration\AutoComplete\IManager::class, function (Server $c) {
+ return new Collaboration\AutoComplete\Manager($c);
+ });
+ $this->registerAlias('AutoCompleteManager', \OCP\Collaboration\AutoComplete\IManager::class);
+
$this->registerService('SettingsManager', function (Server $c) {
$manager = new \OC\Settings\Manager(
$c->getLogger(),
@@ -1802,6 +1807,13 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
+ * @return \OCP\Collaboration\AutoComplete\IManager
+ */
+ public function getAutoCompleteManager(){
+ return $this->query('AutoCompleteManager');
+ }
+
+ /**
* Returns the LDAP Provider
*
* @return \OCP\LDAP\ILDAPProvider
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 42f2170122e..9245b9d4f51 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -1322,7 +1322,7 @@ class Manager implements IManager {
*
* @param \OCP\Files\Node $path
* @param bool $recursive Should we check all parent folders as well
- * @param bool $currentAccess Should the user have currently access to the file
+ * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it)
* @return array
*/
public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) {
diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php
index bd261b05e51..efa2afd7356 100644
--- a/lib/private/legacy/app.php
+++ b/lib/private/legacy/app.php
@@ -185,6 +185,8 @@ class OC_App {
'class' => $plugin['@value'],
];
\OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo);
+ } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') {
+ \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']);
}
}
}
diff --git a/lib/public/Collaboration/AutoComplete/IManager.php b/lib/public/Collaboration/AutoComplete/IManager.php
new file mode 100644
index 00000000000..e9f33727cd2
--- /dev/null
+++ b/lib/public/Collaboration/AutoComplete/IManager.php
@@ -0,0 +1,46 @@
+<?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 OCP\Collaboration\AutoComplete;
+
+/**
+ * Interface IManager
+ *
+ * @package OCP\Collaboration\AutoComplete
+ * @since 13.0.0
+ */
+interface IManager {
+ /**
+ * @param string $className – class name of the ISorter implementation
+ * @since 13.0.0
+ */
+ public function registerSorter($className);
+
+ /**
+ * @param array $sorters list of sorter IDs, seperated by "|"
+ * @param array $sortArray array representation of OCP\Collaboration\Collaborators\ISearchResult
+ * @param array $context context info of the search, keys: itemType, itemId
+ * @since 13.0.0
+ */
+ public function runSorters(array $sorters, array &$sortArray, array $context);
+}
diff --git a/lib/public/Collaboration/AutoComplete/ISorter.php b/lib/public/Collaboration/AutoComplete/ISorter.php
new file mode 100644
index 00000000000..538ca41003d
--- /dev/null
+++ b/lib/public/Collaboration/AutoComplete/ISorter.php
@@ -0,0 +1,50 @@
+<?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 OCP\Collaboration\AutoComplete;
+
+/**
+ * Interface ISorter
+ *
+ * Sorts the list of .e.g users for auto completion
+ *
+ * @package OCP\Collaboration\AutoComplete
+ * @since 13.0.0
+ */
+interface ISorter {
+
+ /**
+ * @return string The ID of the sorter, e.g. commenters
+ * @since 13.0.0
+ */
+ public function getId();
+
+ /**
+ * executes the sort action
+ *
+ * @param array $sortArray the array to be sorted, provided as reference
+ * @param array $context carries key 'itemType' and 'itemId' of the source object (e.g. a file)
+ * @since 13.0.0
+ */
+ public function sort(array &$sortArray, array $context);
+}
diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php
index 61633af95cd..e3ea7888ffd 100644
--- a/lib/public/Comments/ICommentsManager.php
+++ b/lib/public/Comments/ICommentsManager.php
@@ -138,6 +138,28 @@ interface ICommentsManager {
public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user);
/**
+ * Get the actor types and ID that commented in the tree specified by the ID
+ *
+ * @param string $id
+ * @return array
+ * @since 13.0.0
+ *
+ * The return array looks like this:
+ *
+ * [
+ * 'users' => [
+ * 'alice',
+ * 'bob',
+ * ],
+ * 'robots' => [
+ * 'r2-d2',
+ * 'c-3po',
+ * ]
+ * ]
+ */
+ public function getActorsInTree($id);
+
+ /**
* creates a new comment and returns it. At this point of time, it is not
* saved in the used data storage. Use save() after setting other fields
* of the comment (e.g. message or verb).