diff options
Diffstat (limited to 'apps/theming/lib/Listener')
-rw-r--r-- | apps/theming/lib/Listener/BeforePreferenceListener.php | 56 | ||||
-rw-r--r-- | apps/theming/lib/Listener/BeforeTemplateRenderedListener.php | 13 |
2 files changed, 69 insertions, 0 deletions
diff --git a/apps/theming/lib/Listener/BeforePreferenceListener.php b/apps/theming/lib/Listener/BeforePreferenceListener.php new file mode 100644 index 00000000000..a1add86e600 --- /dev/null +++ b/apps/theming/lib/Listener/BeforePreferenceListener.php @@ -0,0 +1,56 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com> + * + * @author 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\Theming\Listener; + +use OCA\Theming\AppInfo\Application; +use OCP\Config\BeforePreferenceDeletedEvent; +use OCP\Config\BeforePreferenceSetEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; + +class BeforePreferenceListener implements IEventListener { + public function handle(Event $event): void { + if (!$event instanceof BeforePreferenceSetEvent + && !$event instanceof BeforePreferenceDeletedEvent) { + return; + } + + if ($event->getAppId() !== Application::APP_ID) { + return; + } + + if ($event->getConfigKey() !== 'shortcuts_disabled') { + return; + } + + if ($event instanceof BeforePreferenceSetEvent) { + $event->setValid($event->getConfigValue() === 'yes'); + return; + } + + $event->setValid(true); + } +} diff --git a/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php b/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php index d6e00b927ae..1d28a1d4399 100644 --- a/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php +++ b/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php @@ -29,6 +29,8 @@ use OCA\Theming\AppInfo\Application; use OCA\Theming\Service\BackgroundService; use OCA\Theming\Service\JSDataService; use OCA\Theming\Service\ThemeInjectionService; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; @@ -64,6 +66,17 @@ class BeforeTemplateRenderedListener implements IEventListener { fn () => $this->container->get(JSDataService::class), ); + /** @var BeforeTemplateRenderedEvent $event */ + if ($event->getResponse()->getRenderAs() === TemplateResponse::RENDER_AS_USER) { + $this->initialState->provideLazyInitialState('shortcutsDisabled', function () { + if ($this->userSession->getUser()) { + $uid = $this->userSession->getUser()->getUID(); + return $this->config->getUserValue($uid, Application::APP_ID, 'shortcuts_disabled', 'no') === 'yes'; + } + return false; + }); + } + $this->themeInjectionService->injectHeaders(); $user = $this->userSession->getUser(); |