Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont load UI on embedded pages #1013

Merged
merged 2 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@
use OC\Authentication\Token\IProvider;
use OCA\Notifications\App;
use OCA\Notifications\Capabilities;
use OCA\Notifications\Listener\BeforeTemplateRenderedListener;
use OCA\Notifications\Listener\UserDeletedListener;
use OCA\Notifications\Notifier\AdminNotifications;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\IAppContainer;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Notification\IManager;
use OCP\User\Events\UserDeletedEvent;
use OCP\Util;

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

$context->registerNotifierService(AdminNotifications::class);

$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
}

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

public function registerAppAndNotifier(IManager $notificationManager, IRequest $request, IUserSession $userSession): void {
public function registerAppAndNotifier(IManager $notificationManager): void {
// notification app
$notificationManager->registerApp(App::class);

// admin notifications
$notificationManager->registerNotifierService(AdminNotifications::class);

// User interface
if ($userSession->getUser() !== null
&& strpos($request->getPathInfo(), '/s/') !== 0
&& strpos($request->getPathInfo(), '/login/') !== 0
&& substr($request->getScriptName(), 0 - \strlen('/index.php')) === '/index.php') {
Util::addScript('notifications', 'notifications-main');
Util::addStyle('notifications', 'styles');
}
}
}
49 changes: 49 additions & 0 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2021 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\Notifications\Listener;

use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

class BeforeTemplateRenderedListener implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof BeforeTemplateRenderedEvent)) {
// Unrelated
return;
}

if ($event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_USER) {
return;
}

Util::addScript('notifications', 'notifications-main');
Util::addStyle('notifications', 'styles');
}
}