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
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-08-03 18:03:06 +0300
committerJoas Schilling <coding@schilljs.com>2020-08-03 18:03:06 +0300
commit5d41a3f9a2a79cecb5f7278dc4b83f9d8a6e3b6c (patch)
treee406b376ed6c71a7a48072320a4528195c1861f4 /apps/settings
parent489fecac32ae8c3d5c857b803d0d597ac0b37f4a (diff)
Add settings sections to unified search
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/settings')
-rw-r--r--apps/settings/composer/composer/autoload_classmap.php2
-rw-r--r--apps/settings/composer/composer/autoload_static.php2
-rw-r--r--apps/settings/lib/AppInfo/Application.php2
-rw-r--r--apps/settings/lib/Search/SectionResult.php29
-rw-r--r--apps/settings/lib/Search/SectionSearch.php134
5 files changed, 169 insertions, 0 deletions
diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php
index ce594d9b46d..a20138455e7 100644
--- a/apps/settings/composer/composer/autoload_classmap.php
+++ b/apps/settings/composer/composer/autoload_classmap.php
@@ -31,6 +31,8 @@ return array(
'OCA\\Settings\\Hooks' => $baseDir . '/../lib/Hooks.php',
'OCA\\Settings\\Mailer\\NewUserMailHelper' => $baseDir . '/../lib/Mailer/NewUserMailHelper.php',
'OCA\\Settings\\Middleware\\SubadminMiddleware' => $baseDir . '/../lib/Middleware/SubadminMiddleware.php',
+ 'OCA\\Settings\\Search\\SectionResult' => $baseDir . '/../lib/Search/SectionResult.php',
+ 'OCA\\Settings\\Search\\SectionSearch' => $baseDir . '/../lib/Search/SectionSearch.php',
'OCA\\Settings\\Sections\\Admin\\Additional' => $baseDir . '/../lib/Sections/Admin/Additional.php',
'OCA\\Settings\\Sections\\Admin\\Groupware' => $baseDir . '/../lib/Sections/Admin/Groupware.php',
'OCA\\Settings\\Sections\\Admin\\Overview' => $baseDir . '/../lib/Sections/Admin/Overview.php',
diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php
index b77b581a0fc..6cddcda5e44 100644
--- a/apps/settings/composer/composer/autoload_static.php
+++ b/apps/settings/composer/composer/autoload_static.php
@@ -46,6 +46,8 @@ class ComposerStaticInitSettings
'OCA\\Settings\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php',
'OCA\\Settings\\Mailer\\NewUserMailHelper' => __DIR__ . '/..' . '/../lib/Mailer/NewUserMailHelper.php',
'OCA\\Settings\\Middleware\\SubadminMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/SubadminMiddleware.php',
+ 'OCA\\Settings\\Search\\SectionResult' => __DIR__ . '/..' . '/../lib/Search/SectionResult.php',
+ 'OCA\\Settings\\Search\\SectionSearch' => __DIR__ . '/..' . '/../lib/Search/SectionSearch.php',
'OCA\\Settings\\Sections\\Admin\\Additional' => __DIR__ . '/..' . '/../lib/Sections/Admin/Additional.php',
'OCA\\Settings\\Sections\\Admin\\Groupware' => __DIR__ . '/..' . '/../lib/Sections/Admin/Groupware.php',
'OCA\\Settings\\Sections\\Admin\\Overview' => __DIR__ . '/..' . '/../lib/Sections/Admin/Overview.php',
diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php
index 6e6eb26d011..0fd39f71b36 100644
--- a/apps/settings/lib/AppInfo/Application.php
+++ b/apps/settings/lib/AppInfo/Application.php
@@ -46,6 +46,7 @@ use OCA\Settings\Activity\Provider;
use OCA\Settings\Hooks;
use OCA\Settings\Mailer\NewUserMailHelper;
use OCA\Settings\Middleware\SubadminMiddleware;
+use OCA\Settings\Search\SectionSearch;
use OCP\Activity\IManager as IActivityManager;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
@@ -77,6 +78,7 @@ class Application extends App implements IBootstrap {
// Register Middleware
$context->registerServiceAlias('SubadminMiddleware', SubadminMiddleware::class);
$context->registerMiddleware(SubadminMiddleware::class);
+ $context->registerSearchProvider(SectionSearch::class);
/**
* Core class wrappers
diff --git a/apps/settings/lib/Search/SectionResult.php b/apps/settings/lib/Search/SectionResult.php
new file mode 100644
index 00000000000..d7e4e6b21fb
--- /dev/null
+++ b/apps/settings/lib/Search/SectionResult.php
@@ -0,0 +1,29 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
+ *
+ * @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 OCA\Settings\Search;
+
+use OCP\Search\ASearchResultEntry;
+
+class SectionResult extends ASearchResultEntry {
+}
diff --git a/apps/settings/lib/Search/SectionSearch.php b/apps/settings/lib/Search/SectionSearch.php
new file mode 100644
index 00000000000..818fa055bb4
--- /dev/null
+++ b/apps/settings/lib/Search/SectionSearch.php
@@ -0,0 +1,134 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
+ *
+ * @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 OCA\Settings\Search;
+
+use OCP\IGroupManager;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\Search\IProvider;
+use OCP\Search\ISearchQuery;
+use OCP\Search\SearchResult;
+use OCP\Settings\IIconSection;
+use OCP\Settings\ISection;
+use OCP\Settings\IManager;
+
+class SectionSearch implements IProvider {
+
+ /** @var IManager */
+ protected $settingsManager;
+ /** @var IGroupManager */
+ protected $groupManager;
+ /** @var IURLGenerator */
+ protected $urlGenerator;
+ /** @var IL10N */
+ protected $l;
+
+ public function __construct(IManager $settingsManager,
+ IGroupManager $groupManager,
+ IURLGenerator $urlGenerator,
+ IL10N $l) {
+ $this->settingsManager = $settingsManager;
+ $this->groupManager = $groupManager;
+ $this->urlGenerator = $urlGenerator;
+ $this->l = $l;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getId(): string {
+ return 'settings_sections';
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getName(): string {
+ return $this->l->t('Settings');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function search(IUser $user, ISearchQuery $query): SearchResult {
+ $isAdmin = $this->groupManager->isAdmin($user->getUID());
+
+ $result = $this->searchSections(
+ $query,
+ $this->settingsManager->getPersonalSections(),
+ $isAdmin ? $this->l->t('Personal') : '',
+ 'settings.PersonalSettings.index'
+ );
+
+ if ($this->groupManager->isAdmin($user->getUID())) {
+ $result = array_merge($result, $this->searchSections(
+ $query,
+ $this->settingsManager->getAdminSections(),
+ $this->l->t('Administration'),
+ 'settings.AdminSettings.index'
+ ));
+ }
+
+ return SearchResult::complete(
+ $this->l->t('Settings'),
+ $result
+ );
+ }
+
+ /**
+ * @param ISearchQuery $query
+ * @param ISection[][] $sections
+ * @param string $subline
+ * @param string $routeName
+ * @return array
+ */
+ public function searchSections(ISearchQuery $query, array $sections, string $subline, string $routeName): array {
+ $result = [];
+ foreach ($sections as $priority => $sectionsByPriority) {
+ foreach ($sectionsByPriority as $section) {
+ if (
+ stripos($section->getName(), $query->getTerm()) === false &&
+ stripos($section->getID(), $query->getTerm()) === false
+ ) {
+ continue;
+ }
+
+ $iconUrl = '';
+ if ($section instanceof IIconSection) {
+ $iconUrl = $section->getIcon();
+ }
+
+ $result[] = new SectionResult(
+ $iconUrl,
+ $section->getName(),
+ $subline,
+ $this->urlGenerator->linkToRouteAbsolute($routeName, ['section' => $section->getID()])
+ );
+ }
+ }
+
+ return $result;
+ }
+}