1
0

PushService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
  5. *
  6. * @author Côme Chilliet <come.chilliet@nextcloud.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Settings\SetupChecks;
  25. use OCP\AppFramework\Utility\ITimeFactory;
  26. use OCP\IConfig;
  27. use OCP\IL10N;
  28. use OCP\Notification\IManager;
  29. use OCP\SetupCheck\ISetupCheck;
  30. use OCP\SetupCheck\SetupResult;
  31. use OCP\Support\Subscription\IRegistry;
  32. class PushService implements ISetupCheck {
  33. public function __construct(
  34. private IL10N $l10n,
  35. private IConfig $config,
  36. private IManager $notificationsManager,
  37. private IRegistry $subscriptionRegistry,
  38. private ITimeFactory $timeFactory,
  39. ) {
  40. }
  41. public function getName(): string {
  42. return $this->l10n->t('Push service');
  43. }
  44. public function getCategory(): string {
  45. return 'system';
  46. }
  47. /**
  48. * Check if is fair use of free push service
  49. */
  50. private function isFairUseOfFreePushService(): bool {
  51. $rateLimitReached = (int) $this->config->getAppValue('notifications', 'rate_limit_reached', '0');
  52. if ($rateLimitReached >= ($this->timeFactory->now()->getTimestamp() - 7 * 24 * 3600)) {
  53. // Notifications app is showing a message already
  54. return true;
  55. }
  56. return $this->notificationsManager->isFairUseOfFreePushService();
  57. }
  58. public function run(): SetupResult {
  59. if ($this->subscriptionRegistry->delegateHasValidSubscription()) {
  60. return SetupResult::success($this->l10n->t('Valid enterprise license'));
  61. }
  62. if ($this->isFairUseOfFreePushService()) {
  63. return SetupResult::success($this->l10n->t('Free push service'));
  64. }
  65. return SetupResult::error(
  66. $this->l10n->t('This is the unsupported community build of Nextcloud. Given the size of this instance, performance, reliability and scalability cannot be guaranteed. Push notifications are limited to avoid overloading our free service. Learn more about the benefits of Nextcloud Enterprise at {link}.'),
  67. descriptionParameters:[
  68. 'link' => [
  69. 'type' => 'highlight',
  70. 'id' => 'link',
  71. 'name' => 'https://nextcloud.com/enterprise',
  72. 'link' => 'https://nextcloud.com/enterprise',
  73. ],
  74. ],
  75. );
  76. }
  77. }