CoreNotifier.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Notification;
  8. use OCP\IConfig;
  9. use OCP\IURLGenerator;
  10. use OCP\L10N\IFactory;
  11. use OCP\Notification\IAction;
  12. use OCP\Notification\INotification;
  13. use OCP\Notification\INotifier;
  14. class CoreNotifier implements INotifier {
  15. public function __construct(
  16. private IConfig $config,
  17. private IFactory $factory,
  18. private IURLGenerator $url,
  19. ) {
  20. }
  21. /**
  22. * Identifier of the notifier, only use [a-z0-9_]
  23. *
  24. * @return string
  25. * @since 17.0.0
  26. */
  27. public function getID(): string {
  28. return 'core';
  29. }
  30. /**
  31. * Human readable name describing the notifier
  32. *
  33. * @return string
  34. * @since 17.0.0
  35. */
  36. public function getName(): string {
  37. return $this->factory->get('core')->t('Nextcloud Server');
  38. }
  39. public function prepare(INotification $notification, string $languageCode): INotification {
  40. if ($notification->getApp() !== 'core') {
  41. throw new \InvalidArgumentException();
  42. }
  43. $l = $this->factory->get('core', $languageCode);
  44. if ($notification->getSubject() === 'repair_exposing_links') {
  45. $notification->setParsedSubject($l->t('Some of your link shares have been removed'));
  46. $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.'));
  47. $notification->setLink('https://nextcloud.com/security/advisory/?id=NC-SA-2019-003');
  48. return $notification;
  49. }
  50. if ($notification->getSubject() === 'user_limit_reached') {
  51. $notification->setParsedSubject($l->t('The account limit of this instance is reached.'));
  52. $notification->setParsedMessage($l->t('Enter your subscription key in the support app in order to increase the account limit. This does also grant you all additional benefits that Nextcloud Enterprise offers and is highly recommended for the operation in companies.'));
  53. $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/contacts.svg')));
  54. $action = $notification->createAction();
  55. $label = $l->t('Learn more ↗');
  56. $link = $this->config->getSystemValueString('one-click-instance.link', 'https://nextcloud.com/enterprise/');
  57. $action->setLabel($label)
  58. ->setParsedLabel($label)
  59. ->setLink($link, IAction::TYPE_WEB)
  60. ->setPrimary(true);
  61. $notification->addParsedAction($action);
  62. return $notification;
  63. }
  64. throw new \InvalidArgumentException('Invalid subject');
  65. }
  66. }