You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CoreNotifier.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OC\Core\Notification;
  28. use OCP\IConfig;
  29. use OCP\IURLGenerator;
  30. use OCP\L10N\IFactory;
  31. use OCP\Notification\IAction;
  32. use OCP\Notification\INotification;
  33. use OCP\Notification\INotifier;
  34. class CoreNotifier implements INotifier {
  35. public function __construct(
  36. private IConfig $config,
  37. private IFactory $factory,
  38. private IURLGenerator $url,
  39. ) {
  40. }
  41. /**
  42. * Identifier of the notifier, only use [a-z0-9_]
  43. *
  44. * @return string
  45. * @since 17.0.0
  46. */
  47. public function getID(): string {
  48. return 'core';
  49. }
  50. /**
  51. * Human readable name describing the notifier
  52. *
  53. * @return string
  54. * @since 17.0.0
  55. */
  56. public function getName(): string {
  57. return $this->factory->get('core')->t('Nextcloud Server');
  58. }
  59. public function prepare(INotification $notification, string $languageCode): INotification {
  60. if ($notification->getApp() !== 'core') {
  61. throw new \InvalidArgumentException();
  62. }
  63. $l = $this->factory->get('core', $languageCode);
  64. if ($notification->getSubject() === 'repair_exposing_links') {
  65. $notification->setParsedSubject($l->t('Some of your link shares have been removed'));
  66. $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.'));
  67. $notification->setLink('https://nextcloud.com/security/advisory/?id=NC-SA-2019-003');
  68. return $notification;
  69. }
  70. if ($notification->getSubject() === 'user_limit_reached') {
  71. $notification->setParsedSubject($l->t('The user limit of this instance is reached.'));
  72. $notification->setParsedMessage($l->t('Enter your subscription key in the support app in order to increase the user limit. This does also grant you all additional benefits that Nextcloud Enterprise offers and is highly recommended for the operation in companies.'));
  73. $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/contacts.svg')));
  74. $action = $notification->createAction();
  75. $label = $l->t('Learn more ↗');
  76. $link = $this->config->getSystemValueString('one-click-instance.link', 'https://nextcloud.com/enterprise/');
  77. $action->setLabel($label)
  78. ->setParsedLabel($label)
  79. ->setLink($link, IAction::TYPE_WEB)
  80. ->setPrimary(true);
  81. $notification->addParsedAction($action);
  82. return $notification;
  83. }
  84. throw new \InvalidArgumentException('Invalid subject');
  85. }
  86. }