Passed
Push — master ( dc3e05...4deff3 )
by Christoph
12:00 queued 10s
created

CoreNotifier::getID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]>
7
 *
8
 * @author Christoph Wurst <[email protected]>
9
 * @author Joas Schilling <[email protected]>
10
 * @author Morris Jobke <[email protected]>
11
 * @author Roeland Jago Douma <[email protected]>
12
 *
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
namespace OC\Core\Notification;
31
32
use OCP\L10N\IFactory;
33
use OCP\Notification\INotification;
34
use OCP\Notification\INotifier;
35
36
class CoreNotifier implements INotifier {
37
	/** @var IFactory */
38
	private $l10nFactory;
39
40
	public function __construct(IFactory $factory) {
41
		$this->l10nFactory = $factory;
42
	}
43
44
	/**
45
	 * Identifier of the notifier, only use [a-z0-9_]
46
	 *
47
	 * @return string
48
	 * @since 17.0.0
49
	 */
50
	public function getID(): string {
51
		return 'core';
52
	}
53
54
	/**
55
	 * Human readable name describing the notifier
56
	 *
57
	 * @return string
58
	 * @since 17.0.0
59
	 */
60
	public function getName(): string {
61
		return $this->l10nFactory->get('core')->t('Nextcloud Server');
62
	}
63
64
	public function prepare(INotification $notification, string $languageCode): INotification {
65
		if ($notification->getApp() !== 'core') {
66
			throw new \InvalidArgumentException();
67
		}
68
		$l = $this->l10nFactory->get('core', $languageCode);
69
70
		if ($notification->getSubject() === 'repair_exposing_links') {
71
			$notification->setParsedSubject($l->t('Some of your link shares have been removed'));
72
			$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.'));
73
			$notification->setLink('https://nextcloud.com/security/advisory/?id=NC-SA-2019-003');
74
			return $notification;
75
		}
76
77
		if ($notification->getSubject() === 'user_limit_reached') {
78
			$notification->setParsedSubject($l->t('The user limit of this instance is reached.'));
79
			$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.'));
80
			$notification->setLink('https://nextcloud.com/enterprise/order/');
81
			return $notification;
82
		}
83
84
		throw new \InvalidArgumentException('Invalid subject');
85
	}
86
}
87