aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
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/Group/Database.php24
-rw-r--r--lib/private/Route/Router.php17
-rw-r--r--lib/private/Search/SearchComposer.php9
-rw-r--r--lib/private/Search/SearchQuery.php28
-rw-r--r--lib/private/Server.php2
-rw-r--r--lib/private/UserStatus/Manager.php105
-rw-r--r--lib/public/Search/IProvider.php5
-rw-r--r--lib/public/Search/ISearchQuery.php12
-rw-r--r--lib/public/UserStatus/IManager.php44
-rw-r--r--lib/public/UserStatus/IProvider.php44
-rw-r--r--lib/public/UserStatus/IUserStatus.php105
13 files changed, 390 insertions, 13 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 49801a253b9..5f61b848a83 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -495,6 +495,9 @@ return array(
'OCP\\Template' => $baseDir . '/lib/public/Template.php',
'OCP\\User' => $baseDir . '/lib/public/User.php',
'OCP\\UserInterface' => $baseDir . '/lib/public/UserInterface.php',
+ 'OCP\\UserStatus\\IManager' => $baseDir . '/lib/public/UserStatus/IManager.php',
+ 'OCP\\UserStatus\\IProvider' => $baseDir . '/lib/public/UserStatus/IProvider.php',
+ 'OCP\\UserStatus\\IUserStatus' => $baseDir . '/lib/public/UserStatus/IUserStatus.php',
'OCP\\User\\Backend\\ABackend' => $baseDir . '/lib/public/User/Backend/ABackend.php',
'OCP\\User\\Backend\\ICheckPasswordBackend' => $baseDir . '/lib/public/User/Backend/ICheckPasswordBackend.php',
'OCP\\User\\Backend\\ICountUsersBackend' => $baseDir . '/lib/public/User/Backend/ICountUsersBackend.php',
@@ -1344,6 +1347,7 @@ return array(
'OC\\Updater\\ChangesMapper' => $baseDir . '/lib/private/Updater/ChangesMapper.php',
'OC\\Updater\\ChangesResult' => $baseDir . '/lib/private/Updater/ChangesResult.php',
'OC\\Updater\\VersionCheck' => $baseDir . '/lib/private/Updater/VersionCheck.php',
+ 'OC\\UserStatus\\Manager' => $baseDir . '/lib/private/UserStatus/Manager.php',
'OC\\User\\Backend' => $baseDir . '/lib/private/User/Backend.php',
'OC\\User\\Database' => $baseDir . '/lib/private/User/Database.php',
'OC\\User\\LoginException' => $baseDir . '/lib/private/User/LoginException.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 0a9879e19d0..a37769e9ed6 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -524,6 +524,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Template' => __DIR__ . '/../../..' . '/lib/public/Template.php',
'OCP\\User' => __DIR__ . '/../../..' . '/lib/public/User.php',
'OCP\\UserInterface' => __DIR__ . '/../../..' . '/lib/public/UserInterface.php',
+ 'OCP\\UserStatus\\IManager' => __DIR__ . '/../../..' . '/lib/public/UserStatus/IManager.php',
+ 'OCP\\UserStatus\\IProvider' => __DIR__ . '/../../..' . '/lib/public/UserStatus/IProvider.php',
+ 'OCP\\UserStatus\\IUserStatus' => __DIR__ . '/../../..' . '/lib/public/UserStatus/IUserStatus.php',
'OCP\\User\\Backend\\ABackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ABackend.php',
'OCP\\User\\Backend\\ICheckPasswordBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICheckPasswordBackend.php',
'OCP\\User\\Backend\\ICountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/User/Backend/ICountUsersBackend.php',
@@ -1373,6 +1376,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Updater\\ChangesMapper' => __DIR__ . '/../../..' . '/lib/private/Updater/ChangesMapper.php',
'OC\\Updater\\ChangesResult' => __DIR__ . '/../../..' . '/lib/private/Updater/ChangesResult.php',
'OC\\Updater\\VersionCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/VersionCheck.php',
+ 'OC\\UserStatus\\Manager' => __DIR__ . '/../../..' . '/lib/private/UserStatus/Manager.php',
'OC\\User\\Backend' => __DIR__ . '/../../..' . '/lib/private/User/Backend.php',
'OC\\User\\Database' => __DIR__ . '/../../..' . '/lib/private/User/Database.php',
'OC\\User\\LoginException' => __DIR__ . '/../../..' . '/lib/private/User/LoginException.php',
diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php
index 8e6181a56cd..97094c67728 100644
--- a/lib/private/Group/Database.php
+++ b/lib/private/Group/Database.php
@@ -348,15 +348,27 @@ class Database extends ABackend implements
$this->fixDI();
$query = $this->dbConn->getQueryBuilder();
- $query->select('uid')
- ->from('group_user')
+ $query->select('g.uid')
+ ->from('group_user', 'g')
->where($query->expr()->eq('gid', $query->createNamedParameter($gid)))
- ->orderBy('uid', 'ASC');
+ ->orderBy('g.uid', 'ASC');
if ($search !== '') {
- $query->andWhere($query->expr()->like('uid', $query->createNamedParameter(
- '%' . $this->dbConn->escapeLikeParameter($search) . '%'
- )));
+ $query->leftJoin('g', 'users', 'u', $query->expr()->eq('g.uid', 'u.uid'))
+ ->leftJoin('u', 'preferences', 'p', $query->expr()->andX(
+ $query->expr()->eq('p.userid', 'u.uid'),
+ $query->expr()->eq('p.appid', $query->expr()->literal('settings')),
+ $query->expr()->eq('p.configkey', $query->expr()->literal('email')))
+ )
+ // sqlite doesn't like re-using a single named parameter here
+ ->andWhere(
+ $query->expr()->orX(
+ $query->expr()->ilike('g.uid', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')),
+ $query->expr()->ilike('u.displayname', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%')),
+ $query->expr()->ilike('p.configvalue', $query->createNamedParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))
+ )
+ )
+ ->orderBy('u.uid_lower', 'ASC');
}
if ($limit !== -1) {
diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php
index de7c720f271..6de581ffa96 100644
--- a/lib/private/Route/Router.php
+++ b/lib/private/Route/Router.php
@@ -239,9 +239,9 @@ class Router implements IRouter {
*
* @param string $url The url to find
* @throws \Exception
- * @return void
+ * @return array
*/
- public function match($url) {
+ public function findMatchingRoute(string $url): array {
if (substr($url, 0, 6) === '/apps/') {
// empty string / 'apps' / $app / rest of the route
list(, , $app,) = explode('/', $url, 4);
@@ -287,6 +287,19 @@ class Router implements IRouter {
}
}
+ return $parameters;
+ }
+
+ /**
+ * Find and execute the route matching $url
+ *
+ * @param string $url The url to find
+ * @throws \Exception
+ * @return void
+ */
+ public function match($url) {
+ $parameters = $this->findMatchingRoute($url);
+
\OC::$server->getEventLogger()->start('run_route', 'Run route');
if (isset($parameters['caller'])) {
$caller = $parameters['caller'];
diff --git a/lib/private/Search/SearchComposer.php b/lib/private/Search/SearchComposer.php
index 7ba6296c9de..fdac9c5612a 100644
--- a/lib/private/Search/SearchComposer.php
+++ b/lib/private/Search/SearchComposer.php
@@ -109,17 +109,20 @@ class SearchComposer {
* Get a list of all provider IDs & Names for the consecutive calls to `search`
* Sort the list by the order property
*
+ * @param string $route the route the user is currently at
+ * @param array $routeParameters the parameters of the route the user is currently at
+ *
* @return array
*/
- public function getProviders(): array {
+ public function getProviders(string $route, array $routeParameters): array {
$this->loadLazyProviders();
$providers = array_values(
- array_map(function (IProvider $provider) {
+ array_map(function (IProvider $provider) use ($route, $routeParameters) {
return [
'id' => $provider->getId(),
'name' => $provider->getName(),
- 'order' => $provider->getOrder()
+ 'order' => $provider->getOrder($route, $routeParameters),
];
}, $this->providers)
);
diff --git a/lib/private/Search/SearchQuery.php b/lib/private/Search/SearchQuery.php
index 186b4ccf18f..7ba63de90ec 100644
--- a/lib/private/Search/SearchQuery.php
+++ b/lib/private/Search/SearchQuery.php
@@ -42,20 +42,32 @@ class SearchQuery implements ISearchQuery {
/** @var int|string|null */
private $cursor;
+ /** @var string */
+ private $route;
+
+ /** @var array */
+ private $routeParameters;
+
/**
* @param string $term
* @param int $sortOrder
* @param int $limit
* @param int|string|null $cursor
+ * @param string $route
+ * @param array $routeParameters
*/
public function __construct(string $term,
int $sortOrder = ISearchQuery::SORT_DATE_DESC,
int $limit = self::LIMIT_DEFAULT,
- $cursor = null) {
+ $cursor = null,
+ string $route = '',
+ array $routeParameters = []) {
$this->term = $term;
$this->sortOrder = $sortOrder;
$this->limit = $limit;
$this->cursor = $cursor;
+ $this->route = $route;
+ $this->routeParameters = $routeParameters;
}
/**
@@ -85,4 +97,18 @@ class SearchQuery implements ISearchQuery {
public function getCursor() {
return $this->cursor;
}
+
+ /**
+ * @inheritDoc
+ */
+ public function getRoute(): string {
+ return $this->route;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getRouteParameters(): array {
+ return $this->routeParameters;
+ }
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 09bb7336785..e054d8230d9 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1370,6 +1370,8 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias(IInitialStateService::class, InitialStateService::class);
+ $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
+
$this->connectDispatcher();
}
diff --git a/lib/private/UserStatus/Manager.php b/lib/private/UserStatus/Manager.php
new file mode 100644
index 00000000000..c7726a88028
--- /dev/null
+++ b/lib/private/UserStatus/Manager.php
@@ -0,0 +1,105 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020, Georg Ehrke
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\UserStatus;
+
+use OCP\ILogger;
+use OCP\IServerContainer;
+use OCP\UserStatus\IManager;
+use OCP\UserStatus\IProvider;
+use Psr\Container\ContainerExceptionInterface;
+
+class Manager implements IManager {
+
+ /** @var IServerContainer */
+ private $container;
+
+ /** @var ILogger */
+ private $logger;
+
+ /** @var null */
+ private $providerClass;
+
+ /** @var IProvider */
+ private $provider;
+
+ /**
+ * Manager constructor.
+ *
+ * @param IServerContainer $container
+ * @param ILogger $logger
+ */
+ public function __construct(IServerContainer $container,
+ ILogger $logger) {
+ $this->container = $container;
+ $this->logger = $logger;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getUserStatuses(array $userIds): array {
+ $this->setupProvider();
+ if (!$this->provider) {
+ return [];
+ }
+
+ return $this->provider->getUserStatuses($userIds);
+ }
+
+ /**
+ * @param string $class
+ * @since 20.0.0
+ * @internal
+ */
+ public function registerProvider(string $class): void {
+ $this->providerClass = $class;
+ $this->provider = null;
+ }
+
+ /**
+ * Lazily set up provider
+ */
+ private function setupProvider(): void {
+ if ($this->provider !== null) {
+ return;
+ }
+ if ($this->providerClass === null) {
+ return;
+ }
+
+ try {
+ $provider = $this->container->get($this->providerClass);
+ } catch (ContainerExceptionInterface $e) {
+ $this->logger->logException($e, [
+ 'message' => 'Could not load user-status provider dynamically: ' . $e->getMessage(),
+ 'level' => ILogger::ERROR,
+ ]);
+ return;
+ }
+
+ $this->provider = $provider;
+ }
+}
diff --git a/lib/public/Search/IProvider.php b/lib/public/Search/IProvider.php
index 66db62c6829..a91efa55fe1 100644
--- a/lib/public/Search/IProvider.php
+++ b/lib/public/Search/IProvider.php
@@ -68,11 +68,14 @@ interface IProvider {
* Get the search provider order
* The lower the int, the higher it will be sorted (0 will be before 10)
*
+ * @param string $route the route the user is currently at, e.g. files.view.index
+ * @param array $routeParameters the parameters of the route the user is currently at, e.g. [fileId = 982, dir = "/"]
+ *
* @return int
*
* @since 20.0.0
*/
- public function getOrder(): int;
+ public function getOrder(string $route, array $routeParameters): int;
/**
* Find matching search entries in an app
diff --git a/lib/public/Search/ISearchQuery.php b/lib/public/Search/ISearchQuery.php
index 00d538050d4..f89251dd134 100644
--- a/lib/public/Search/ISearchQuery.php
+++ b/lib/public/Search/ISearchQuery.php
@@ -76,4 +76,16 @@ interface ISearchQuery {
* @since 20.0.0
*/
public function getCursor();
+
+ /**
+ * @return string
+ * @since 20.0.0
+ */
+ public function getRoute(): string;
+
+ /**
+ * @return array
+ * @since 20.0.0
+ */
+ public function getRouteParameters(): array;
}
diff --git a/lib/public/UserStatus/IManager.php b/lib/public/UserStatus/IManager.php
new file mode 100644
index 00000000000..7ef1fdf2396
--- /dev/null
+++ b/lib/public/UserStatus/IManager.php
@@ -0,0 +1,44 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020, Georg Ehrke
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\UserStatus;
+
+/**
+ * Interface IManager
+ *
+ * @package OCP\UserStatus
+ * @since 20.0.0
+ */
+interface IManager {
+
+ /**
+ * Gets the statuses for all users in $users
+ *
+ * @param string[] $userIds
+ * @return IUserStatus[]
+ * @since 20.0.0
+ */
+ public function getUserStatuses(array $userIds):array;
+}
diff --git a/lib/public/UserStatus/IProvider.php b/lib/public/UserStatus/IProvider.php
new file mode 100644
index 00000000000..10269502969
--- /dev/null
+++ b/lib/public/UserStatus/IProvider.php
@@ -0,0 +1,44 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020, Georg Ehrke
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\UserStatus;
+
+/**
+ * Interface IManager
+ *
+ * @package OCP\UserStatus
+ * @since 20.0.0
+ */
+interface IProvider {
+
+ /**
+ * Gets the statuses for all users in $users
+ *
+ * @param string[] $userIds
+ * @return IUserStatus[]
+ * @since 20.0.0
+ */
+ public function getUserStatuses(array $userIds):array;
+}
diff --git a/lib/public/UserStatus/IUserStatus.php b/lib/public/UserStatus/IUserStatus.php
new file mode 100644
index 00000000000..e892203aeca
--- /dev/null
+++ b/lib/public/UserStatus/IUserStatus.php
@@ -0,0 +1,105 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020, Georg Ehrke
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP\UserStatus;
+
+use DateTimeImmutable;
+
+/**
+ * Interface IUserStatus
+ *
+ * @package OCP\UserStatus
+ * @since 20.0.0
+ */
+interface IUserStatus {
+
+ /**
+ * @var string
+ * @since 20.0.0
+ */
+ public const ONLINE = 'online';
+
+ /**
+ * @var string
+ * @since 20.0.0
+ */
+ public const AWAY = 'away';
+
+ /**
+ * @var string
+ * @since 20.0.0
+ */
+ public const DND = 'dnd';
+
+ /**
+ * @var string
+ * @since 20.0.0
+ */
+ public const OFFLINE = 'offline';
+
+ /**
+ * Get the user this status is connected to
+ *
+ * @return string
+ * @since 20.0.0
+ */
+ public function getUserId():string;
+
+ /**
+ * Get the status
+ *
+ * It will return one of the constants defined above.
+ * It will never return invisible. In case a user marked
+ * themselves as invisible, it will return offline.
+ *
+ * @return string See IUserStatus constants
+ * @since 20.0.0
+ */
+ public function getStatus():string;
+
+ /**
+ * Get a custom message provided by the user
+ *
+ * @return string|null
+ * @since 20.0.0
+ */
+ public function getMessage():?string;
+
+ /**
+ * Get a custom icon provided by the user
+ *
+ * @return string|null
+ * @since 20.0.0
+ */
+ public function getIcon():?string;
+
+ /**
+ * Gets the time that the custom status will be cleared at
+ *
+ * @return DateTimeImmutable|null
+ * @since 20.0.0
+ */
+ public function getClearAt():?DateTimeImmutable;
+}