CoreNotifier.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. use OCP\Notification\UnknownNotificationException;
  15. class CoreNotifier implements INotifier {
  16. public function __construct(
  17. private IConfig $config,
  18. private IFactory $factory,
  19. private IURLGenerator $url,
  20. ) {
  21. }
  22. /**
  23. * Identifier of the notifier, only use [a-z0-9_]
  24. *
  25. * @return string
  26. * @since 17.0.0
  27. */
  28. public function getID(): string {
  29. return 'core';
  30. }
  31. /**
  32. * Human readable name describing the notifier
  33. *
  34. * @return string
  35. * @since 17.0.0
  36. */
  37. public function getName(): string {
  38. return $this->factory->get('core')->t('Nextcloud Server');
  39. }
  40. public function prepare(INotification $notification, string $languageCode): INotification {
  41. if ($notification->getApp() !== 'core') {
  42. throw new UnknownNotificationException();
  43. }
  44. $l = $this->factory->get('core', $languageCode);
  45. if ($notification->getSubject() === 'repair_exposing_links') {
  46. $notification->setParsedSubject($l->t('Some of your link shares have been removed'));
  47. $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.'));
  48. $notification->setLink('https://nextcloud.com/security/advisory/?id=NC-SA-2019-003');
  49. return $notification;
  50. }
  51. if ($notification->getSubject() === 'user_limit_reached') {
  52. $notification->setParsedSubject($l->t('The account limit of this instance is reached.'));
  53. $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.'));
  54. $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'places/contacts.svg')));
  55. $action = $notification->createAction();
  56. $label = $l->t('Learn more ↗');
  57. $link = $this->config->getSystemValueString('one-click-instance.link', 'https://nextcloud.com/enterprise/');
  58. $action->setLabel($label)
  59. ->setParsedLabel($label)
  60. ->setLink($link, IAction::TYPE_WEB)
  61. ->setPrimary(true);
  62. $notification->addParsedAction($action);
  63. return $notification;
  64. }
  65. throw new UnknownNotificationException('Invalid subject');
  66. }
  67. }