From c0a05c0412e11fd80adc2059b28c8963ba4252dc Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 2 Dec 2020 10:07:34 +0100 Subject: Add notification for user limit Signed-off-by: Morris Jobke --- core/Application.php | 4 +- core/Notification/CoreNotifier.php | 86 ++++++++++++++++++++++++++ core/Notification/RemoveLinkSharesNotifier.php | 78 ----------------------- 3 files changed, 88 insertions(+), 80 deletions(-) create mode 100644 core/Notification/CoreNotifier.php delete mode 100644 core/Notification/RemoveLinkSharesNotifier.php (limited to 'core') diff --git a/core/Application.php b/core/Application.php index d9d6b92a2ad..bda271c41fe 100644 --- a/core/Application.php +++ b/core/Application.php @@ -39,7 +39,7 @@ use OC\Authentication\Listeners\RemoteWipeNotificationsListener; use OC\Authentication\Listeners\UserDeletedStoreCleanupListener; use OC\Authentication\Listeners\UserDeletedTokenCleanupListener; use OC\Authentication\Notifications\Notifier as AuthenticationNotifier; -use OC\Core\Notification\RemoveLinkSharesNotifier; +use OC\Core\Notification\CoreNotifier; use OC\DB\MissingColumnInformation; use OC\DB\MissingIndexInformation; use OC\DB\MissingPrimaryKeyInformation; @@ -71,7 +71,7 @@ class Application extends App { $eventDispatcher = $server->query(IEventDispatcher::class); $notificationManager = $server->getNotificationManager(); - $notificationManager->registerNotifierService(RemoveLinkSharesNotifier::class); + $notificationManager->registerNotifierService(CoreNotifier::class); $notificationManager->registerNotifierService(AuthenticationNotifier::class); $oldEventDispatcher = $server->getEventDispatcher(); diff --git a/core/Notification/CoreNotifier.php b/core/Notification/CoreNotifier.php new file mode 100644 index 00000000000..dd362dac8c1 --- /dev/null +++ b/core/Notification/CoreNotifier.php @@ -0,0 +1,86 @@ + + * + * @author Christoph Wurst + * @author Joas Schilling + * @author Morris Jobke + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OC\Core\Notification; + +use OCP\L10N\IFactory; +use OCP\Notification\INotification; +use OCP\Notification\INotifier; + +class CoreNotifier implements INotifier { + /** @var IFactory */ + private $l10nFactory; + + public function __construct(IFactory $factory) { + $this->l10nFactory = $factory; + } + + /** + * Identifier of the notifier, only use [a-z0-9_] + * + * @return string + * @since 17.0.0 + */ + public function getID(): string { + return 'core'; + } + + /** + * Human readable name describing the notifier + * + * @return string + * @since 17.0.0 + */ + public function getName(): string { + return $this->l10nFactory->get('core')->t('Nextcloud Server'); + } + + public function prepare(INotification $notification, string $languageCode): INotification { + if ($notification->getApp() !== 'core') { + throw new \InvalidArgumentException(); + } + $l = $this->l10nFactory->get('core', $languageCode); + + if ($notification->getSubject() === 'repair_exposing_links') { + $notification->setParsedSubject($l->t('Some of your link shares have been removed')); + $notification->setParsedMessage($l->t('Due to a security bug we had to remove some of your link shares. Please see the link for more information.')); + $notification->setLink('https://nextcloud.com/security/advisory/?id=NC-SA-2019-003'); + return $notification; + } + + if ($notification->getSubject() === 'user_limit_reached') { + $notification->setParsedSubject($l->t('The user limit of this instance is reached.')); + $notification->setParsedMessage($l->t('Add a subscription key to increase the user limit of this instance. For more information have a look at the Enterprise subscription page.')); + $notification->setLink('https://nextcloud.com/enterprise/order/'); + return $notification; + } + + throw new \InvalidArgumentException('Invalid subject'); + } +} diff --git a/core/Notification/RemoveLinkSharesNotifier.php b/core/Notification/RemoveLinkSharesNotifier.php deleted file mode 100644 index 52a71fced25..00000000000 --- a/core/Notification/RemoveLinkSharesNotifier.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * @author Christoph Wurst - * @author Joas Schilling - * @author Roeland Jago Douma - * - * @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 . - * - */ - -namespace OC\Core\Notification; - -use OCP\L10N\IFactory; -use OCP\Notification\INotification; -use OCP\Notification\INotifier; - -class RemoveLinkSharesNotifier implements INotifier { - /** @var IFactory */ - private $l10nFactory; - - public function __construct(IFactory $factory) { - $this->l10nFactory = $factory; - } - - /** - * Identifier of the notifier, only use [a-z0-9_] - * - * @return string - * @since 17.0.0 - */ - public function getID(): string { - return 'core'; - } - - /** - * Human readable name describing the notifier - * - * @return string - * @since 17.0.0 - */ - public function getName(): string { - return $this->l10nFactory->get('core')->t('Nextcloud Server'); - } - - public function prepare(INotification $notification, string $languageCode): INotification { - if ($notification->getApp() !== 'core') { - throw new \InvalidArgumentException(); - } - $l = $this->l10nFactory->get('core', $languageCode); - - if ($notification->getSubject() === 'repair_exposing_links') { - $notification->setParsedSubject($l->t('Some of your link shares have been removed')); - $notification->setParsedMessage($l->t('Due to a security bug we had to remove some of your link shares. Please see the link for more information.')); - $notification->setLink('https://nextcloud.com/security/advisory/?id=NC-SA-2019-003'); - return $notification; - } - - throw new \InvalidArgumentException('Invalid subject'); - } -} -- cgit v1.2.3