Add settings sections to unified search

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/22095/head
Joas Schilling 4 years ago
parent 489fecac32
commit 5d41a3f9a2
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA

@ -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',

@ -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',

@ -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

@ -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 {
}

@ -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;
}
}
Loading…
Cancel
Save