Skip to content

Commit 6a74ba3

Browse files
Merge pull request #1013 from nextcloud/bugfix/1012/dont-load-ui-on-embedded-pages
Dont load UI on embedded pages
2 parents a1e1277 + d5183d8 commit 6a74ba3

2 files changed

Lines changed: 55 additions & 16 deletions

File tree

lib/AppInfo/Application.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@
2626
use OC\Authentication\Token\IProvider;
2727
use OCA\Notifications\App;
2828
use OCA\Notifications\Capabilities;
29+
use OCA\Notifications\Listener\BeforeTemplateRenderedListener;
2930
use OCA\Notifications\Listener\UserDeletedListener;
3031
use OCA\Notifications\Notifier\AdminNotifications;
3132
use OCP\AppFramework\Bootstrap\IBootContext;
3233
use OCP\AppFramework\Bootstrap\IBootstrap;
3334
use OCP\AppFramework\Bootstrap\IRegistrationContext;
35+
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
3436
use OCP\AppFramework\IAppContainer;
35-
use OCP\IRequest;
36-
use OCP\IUserSession;
3737
use OCP\Notification\IManager;
3838
use OCP\User\Events\UserDeletedEvent;
39-
use OCP\Util;
4039

4140
class Application extends \OCP\AppFramework\App implements IBootstrap {
4241
public const APP_ID = 'notifications';
@@ -52,27 +51,18 @@ public function register(IRegistrationContext $context): void {
5251
return $c->getServer()->get(IProvider::class);
5352
});
5453

54+
$context->registerNotifierService(AdminNotifications::class);
55+
5556
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
57+
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
5658
}
5759

5860
public function boot(IBootContext $context): void {
5961
$context->injectFn(\Closure::fromCallable([$this, 'registerAppAndNotifier']));
6062
}
6163

62-
public function registerAppAndNotifier(IManager $notificationManager, IRequest $request, IUserSession $userSession): void {
64+
public function registerAppAndNotifier(IManager $notificationManager): void {
6365
// notification app
6466
$notificationManager->registerApp(App::class);
65-
66-
// admin notifications
67-
$notificationManager->registerNotifierService(AdminNotifications::class);
68-
69-
// User interface
70-
if ($userSession->getUser() !== null
71-
&& strpos($request->getPathInfo(), '/s/') !== 0
72-
&& strpos($request->getPathInfo(), '/login/') !== 0
73-
&& substr($request->getScriptName(), 0 - \strlen('/index.php')) === '/index.php') {
74-
Util::addScript('notifications', 'notifications-main');
75-
Util::addStyle('notifications', 'styles');
76-
}
7767
}
7868
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
7+
*
8+
* @author Joas Schilling <coding@schilljs.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCA\Notifications\Listener;
28+
29+
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
30+
use OCP\AppFramework\Http\TemplateResponse;
31+
use OCP\EventDispatcher\Event;
32+
use OCP\EventDispatcher\IEventListener;
33+
use OCP\Util;
34+
35+
class BeforeTemplateRenderedListener implements IEventListener {
36+
public function handle(Event $event): void {
37+
if (!($event instanceof BeforeTemplateRenderedEvent)) {
38+
// Unrelated
39+
return;
40+
}
41+
42+
if ($event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_USER) {
43+
return;
44+
}
45+
46+
Util::addScript('notifications', 'notifications-main');
47+
Util::addStyle('notifications', 'styles');
48+
}
49+
}

0 commit comments

Comments
 (0)