@@ -51,109 +51,109 @@ |
||
51 | 51 | */ |
52 | 52 | class Application extends App { |
53 | 53 | |
54 | - public function __construct() { |
|
55 | - parent::__construct('core'); |
|
56 | - |
|
57 | - $container = $this->getContainer(); |
|
58 | - |
|
59 | - $container->registerService('defaultMailAddress', function () { |
|
60 | - return Util::getDefaultEmailAddress('lostpassword-noreply'); |
|
61 | - }); |
|
62 | - |
|
63 | - $server = $container->getServer(); |
|
64 | - /** @var IEventDispatcher $eventDispatcher */ |
|
65 | - $eventDispatcher = $server->query(IEventDispatcher::class); |
|
66 | - |
|
67 | - $notificationManager = $server->getNotificationManager(); |
|
68 | - $notificationManager->registerNotifierService(RemoveLinkSharesNotifier::class); |
|
69 | - $notificationManager->registerNotifierService(AuthenticationNotifier::class); |
|
70 | - |
|
71 | - $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT, |
|
72 | - function (GenericEvent $event) use ($container) { |
|
73 | - /** @var MissingIndexInformation $subject */ |
|
74 | - $subject = $event->getSubject(); |
|
75 | - |
|
76 | - $schema = new SchemaWrapper($container->query(IDBConnection::class)); |
|
77 | - |
|
78 | - if ($schema->hasTable('share')) { |
|
79 | - $table = $schema->getTable('share'); |
|
80 | - |
|
81 | - if (!$table->hasIndex('share_with_index')) { |
|
82 | - $subject->addHintForMissingSubject($table->getName(), 'share_with_index'); |
|
83 | - } |
|
84 | - if (!$table->hasIndex('parent_index')) { |
|
85 | - $subject->addHintForMissingSubject($table->getName(), 'parent_index'); |
|
86 | - } |
|
87 | - if (!$table->hasIndex('owner_index')) { |
|
88 | - $subject->addHintForMissingSubject($table->getName(), 'owner_index'); |
|
89 | - } |
|
90 | - if (!$table->hasIndex('initiator_index')) { |
|
91 | - $subject->addHintForMissingSubject($table->getName(), 'initiator_index'); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - if ($schema->hasTable('filecache')) { |
|
96 | - $table = $schema->getTable('filecache'); |
|
97 | - |
|
98 | - if (!$table->hasIndex('fs_mtime')) { |
|
99 | - $subject->addHintForMissingSubject($table->getName(), 'fs_mtime'); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - if ($schema->hasTable('twofactor_providers')) { |
|
104 | - $table = $schema->getTable('twofactor_providers'); |
|
105 | - |
|
106 | - if (!$table->hasIndex('twofactor_providers_uid')) { |
|
107 | - $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid'); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - if ($schema->hasTable('login_flow_v2')) { |
|
112 | - $table = $schema->getTable('login_flow_v2'); |
|
113 | - |
|
114 | - if (!$table->hasIndex('poll_token')) { |
|
115 | - $subject->addHintForMissingSubject($table->getName(), 'poll_token'); |
|
116 | - } |
|
117 | - if (!$table->hasIndex('login_token')) { |
|
118 | - $subject->addHintForMissingSubject($table->getName(), 'login_token'); |
|
119 | - } |
|
120 | - if (!$table->hasIndex('timestamp')) { |
|
121 | - $subject->addHintForMissingSubject($table->getName(), 'timestamp'); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - if ($schema->hasTable('whats_new')) { |
|
126 | - $table = $schema->getTable('whats_new'); |
|
127 | - |
|
128 | - if (!$table->hasIndex('version')) { |
|
129 | - $subject->addHintForMissingSubject($table->getName(), 'version'); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - if ($schema->hasTable('cards')) { |
|
134 | - $table = $schema->getTable('cards'); |
|
135 | - |
|
136 | - if (!$table->hasIndex('cards_abid')) { |
|
137 | - $subject->addHintForMissingSubject($table->getName(), 'cards_abid'); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - if ($schema->hasTable('cards_properties')) { |
|
142 | - $table = $schema->getTable('cards_properties'); |
|
143 | - |
|
144 | - if (!$table->hasIndex('cards_prop_abid')) { |
|
145 | - $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid'); |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - ); |
|
150 | - |
|
151 | - $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class); |
|
152 | - $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class); |
|
153 | - $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class); |
|
154 | - $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class); |
|
155 | - $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class); |
|
156 | - $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class); |
|
157 | - } |
|
54 | + public function __construct() { |
|
55 | + parent::__construct('core'); |
|
56 | + |
|
57 | + $container = $this->getContainer(); |
|
58 | + |
|
59 | + $container->registerService('defaultMailAddress', function () { |
|
60 | + return Util::getDefaultEmailAddress('lostpassword-noreply'); |
|
61 | + }); |
|
62 | + |
|
63 | + $server = $container->getServer(); |
|
64 | + /** @var IEventDispatcher $eventDispatcher */ |
|
65 | + $eventDispatcher = $server->query(IEventDispatcher::class); |
|
66 | + |
|
67 | + $notificationManager = $server->getNotificationManager(); |
|
68 | + $notificationManager->registerNotifierService(RemoveLinkSharesNotifier::class); |
|
69 | + $notificationManager->registerNotifierService(AuthenticationNotifier::class); |
|
70 | + |
|
71 | + $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT, |
|
72 | + function (GenericEvent $event) use ($container) { |
|
73 | + /** @var MissingIndexInformation $subject */ |
|
74 | + $subject = $event->getSubject(); |
|
75 | + |
|
76 | + $schema = new SchemaWrapper($container->query(IDBConnection::class)); |
|
77 | + |
|
78 | + if ($schema->hasTable('share')) { |
|
79 | + $table = $schema->getTable('share'); |
|
80 | + |
|
81 | + if (!$table->hasIndex('share_with_index')) { |
|
82 | + $subject->addHintForMissingSubject($table->getName(), 'share_with_index'); |
|
83 | + } |
|
84 | + if (!$table->hasIndex('parent_index')) { |
|
85 | + $subject->addHintForMissingSubject($table->getName(), 'parent_index'); |
|
86 | + } |
|
87 | + if (!$table->hasIndex('owner_index')) { |
|
88 | + $subject->addHintForMissingSubject($table->getName(), 'owner_index'); |
|
89 | + } |
|
90 | + if (!$table->hasIndex('initiator_index')) { |
|
91 | + $subject->addHintForMissingSubject($table->getName(), 'initiator_index'); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + if ($schema->hasTable('filecache')) { |
|
96 | + $table = $schema->getTable('filecache'); |
|
97 | + |
|
98 | + if (!$table->hasIndex('fs_mtime')) { |
|
99 | + $subject->addHintForMissingSubject($table->getName(), 'fs_mtime'); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + if ($schema->hasTable('twofactor_providers')) { |
|
104 | + $table = $schema->getTable('twofactor_providers'); |
|
105 | + |
|
106 | + if (!$table->hasIndex('twofactor_providers_uid')) { |
|
107 | + $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid'); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + if ($schema->hasTable('login_flow_v2')) { |
|
112 | + $table = $schema->getTable('login_flow_v2'); |
|
113 | + |
|
114 | + if (!$table->hasIndex('poll_token')) { |
|
115 | + $subject->addHintForMissingSubject($table->getName(), 'poll_token'); |
|
116 | + } |
|
117 | + if (!$table->hasIndex('login_token')) { |
|
118 | + $subject->addHintForMissingSubject($table->getName(), 'login_token'); |
|
119 | + } |
|
120 | + if (!$table->hasIndex('timestamp')) { |
|
121 | + $subject->addHintForMissingSubject($table->getName(), 'timestamp'); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + if ($schema->hasTable('whats_new')) { |
|
126 | + $table = $schema->getTable('whats_new'); |
|
127 | + |
|
128 | + if (!$table->hasIndex('version')) { |
|
129 | + $subject->addHintForMissingSubject($table->getName(), 'version'); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + if ($schema->hasTable('cards')) { |
|
134 | + $table = $schema->getTable('cards'); |
|
135 | + |
|
136 | + if (!$table->hasIndex('cards_abid')) { |
|
137 | + $subject->addHintForMissingSubject($table->getName(), 'cards_abid'); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + if ($schema->hasTable('cards_properties')) { |
|
142 | + $table = $schema->getTable('cards_properties'); |
|
143 | + |
|
144 | + if (!$table->hasIndex('cards_prop_abid')) { |
|
145 | + $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid'); |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + ); |
|
150 | + |
|
151 | + $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class); |
|
152 | + $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class); |
|
153 | + $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class); |
|
154 | + $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class); |
|
155 | + $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class); |
|
156 | + $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class); |
|
157 | + } |
|
158 | 158 | |
159 | 159 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | $container = $this->getContainer(); |
58 | 58 | |
59 | - $container->registerService('defaultMailAddress', function () { |
|
59 | + $container->registerService('defaultMailAddress', function() { |
|
60 | 60 | return Util::getDefaultEmailAddress('lostpassword-noreply'); |
61 | 61 | }); |
62 | 62 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $notificationManager->registerNotifierService(AuthenticationNotifier::class); |
70 | 70 | |
71 | 71 | $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT, |
72 | - function (GenericEvent $event) use ($container) { |
|
72 | + function(GenericEvent $event) use ($container) { |
|
73 | 73 | /** @var MissingIndexInformation $subject */ |
74 | 74 | $subject = $event->getSubject(); |
75 | 75 |
@@ -29,46 +29,46 @@ |
||
29 | 29 | use OCP\Notification\INotifier; |
30 | 30 | |
31 | 31 | class RemoveLinkSharesNotifier implements INotifier { |
32 | - /** @var IFactory */ |
|
33 | - private $l10nFactory; |
|
32 | + /** @var IFactory */ |
|
33 | + private $l10nFactory; |
|
34 | 34 | |
35 | - public function __construct(IFactory $factory) { |
|
36 | - $this->l10nFactory = $factory; |
|
37 | - } |
|
35 | + public function __construct(IFactory $factory) { |
|
36 | + $this->l10nFactory = $factory; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Identifier of the notifier, only use [a-z0-9_] |
|
41 | - * |
|
42 | - * @return string |
|
43 | - * @since 17.0.0 |
|
44 | - */ |
|
45 | - public function getID(): string { |
|
46 | - return 'core'; |
|
47 | - } |
|
39 | + /** |
|
40 | + * Identifier of the notifier, only use [a-z0-9_] |
|
41 | + * |
|
42 | + * @return string |
|
43 | + * @since 17.0.0 |
|
44 | + */ |
|
45 | + public function getID(): string { |
|
46 | + return 'core'; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Human readable name describing the notifier |
|
51 | - * |
|
52 | - * @return string |
|
53 | - * @since 17.0.0 |
|
54 | - */ |
|
55 | - public function getName(): string { |
|
56 | - return $this->l10nFactory->get('core')->t('Nextcloud Server'); |
|
57 | - } |
|
49 | + /** |
|
50 | + * Human readable name describing the notifier |
|
51 | + * |
|
52 | + * @return string |
|
53 | + * @since 17.0.0 |
|
54 | + */ |
|
55 | + public function getName(): string { |
|
56 | + return $this->l10nFactory->get('core')->t('Nextcloud Server'); |
|
57 | + } |
|
58 | 58 | |
59 | - public function prepare(INotification $notification, string $languageCode): INotification { |
|
60 | - if($notification->getApp() !== 'core') { |
|
61 | - throw new \InvalidArgumentException(); |
|
62 | - } |
|
63 | - $l = $this->l10nFactory->get('core', $languageCode); |
|
59 | + public function prepare(INotification $notification, string $languageCode): INotification { |
|
60 | + if($notification->getApp() !== 'core') { |
|
61 | + throw new \InvalidArgumentException(); |
|
62 | + } |
|
63 | + $l = $this->l10nFactory->get('core', $languageCode); |
|
64 | 64 | |
65 | - if ($notification->getSubject() === 'repair_exposing_links') { |
|
66 | - $notification->setParsedSubject($l->t('Some of your link shares have been removed')); |
|
67 | - $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.')); |
|
68 | - $notification->setLink('https://nextcloud.com/security/advisory/?id=NC-SA-2019-003'); |
|
69 | - return $notification; |
|
70 | - } |
|
65 | + if ($notification->getSubject() === 'repair_exposing_links') { |
|
66 | + $notification->setParsedSubject($l->t('Some of your link shares have been removed')); |
|
67 | + $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.')); |
|
68 | + $notification->setLink('https://nextcloud.com/security/advisory/?id=NC-SA-2019-003'); |
|
69 | + return $notification; |
|
70 | + } |
|
71 | 71 | |
72 | - throw new \InvalidArgumentException('Invalid subject'); |
|
73 | - } |
|
72 | + throw new \InvalidArgumentException('Invalid subject'); |
|
73 | + } |
|
74 | 74 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | public function prepare(INotification $notification, string $languageCode): INotification { |
60 | - if($notification->getApp() !== 'core') { |
|
60 | + if ($notification->getApp() !== 'core') { |
|
61 | 61 | throw new \InvalidArgumentException(); |
62 | 62 | } |
63 | 63 | $l = $this->l10nFactory->get('core', $languageCode); |
@@ -32,45 +32,45 @@ |
||
32 | 32 | use OCP\Util; |
33 | 33 | |
34 | 34 | class Application extends App { |
35 | - public function __construct() { |
|
36 | - parent::__construct('updatenotification', []); |
|
37 | - } |
|
35 | + public function __construct() { |
|
36 | + parent::__construct('updatenotification', []); |
|
37 | + } |
|
38 | 38 | |
39 | - public function register() { |
|
40 | - $server = $this->getContainer()->getServer(); |
|
39 | + public function register() { |
|
40 | + $server = $this->getContainer()->getServer(); |
|
41 | 41 | |
42 | - if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) { |
|
43 | - // Updater check is disabled |
|
44 | - return; |
|
45 | - } |
|
42 | + if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) { |
|
43 | + // Updater check is disabled |
|
44 | + return; |
|
45 | + } |
|
46 | 46 | |
47 | - // Always register the notifier, so background jobs (without a user) can send push notifications |
|
48 | - $this->registerNotifier(); |
|
47 | + // Always register the notifier, so background jobs (without a user) can send push notifications |
|
48 | + $this->registerNotifier(); |
|
49 | 49 | |
50 | - $user = $server->getUserSession()->getUser(); |
|
51 | - if (!$user instanceof IUser) { |
|
52 | - // Nothing to do for guests |
|
53 | - return; |
|
54 | - } |
|
50 | + $user = $server->getUserSession()->getUser(); |
|
51 | + if (!$user instanceof IUser) { |
|
52 | + // Nothing to do for guests |
|
53 | + return; |
|
54 | + } |
|
55 | 55 | |
56 | - if (!$server->getAppManager()->isEnabledForUser('notifications') && |
|
57 | - $server->getGroupManager()->isAdmin($user->getUID())) { |
|
58 | - try { |
|
59 | - $updateChecker = $this->getContainer()->query(UpdateChecker::class); |
|
60 | - } catch (QueryException $e) { |
|
61 | - $server->getLogger()->logException($e); |
|
62 | - return; |
|
63 | - } |
|
56 | + if (!$server->getAppManager()->isEnabledForUser('notifications') && |
|
57 | + $server->getGroupManager()->isAdmin($user->getUID())) { |
|
58 | + try { |
|
59 | + $updateChecker = $this->getContainer()->query(UpdateChecker::class); |
|
60 | + } catch (QueryException $e) { |
|
61 | + $server->getLogger()->logException($e); |
|
62 | + return; |
|
63 | + } |
|
64 | 64 | |
65 | - if ($updateChecker->getUpdateState() !== []) { |
|
66 | - Util::addScript('updatenotification', 'legacy-notification'); |
|
67 | - \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
65 | + if ($updateChecker->getUpdateState() !== []) { |
|
66 | + Util::addScript('updatenotification', 'legacy-notification'); |
|
67 | + \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - public function registerNotifier() { |
|
73 | - $notificationsManager = $this->getContainer()->getServer()->getNotificationManager(); |
|
74 | - $notificationsManager->registerNotifierService(Notifier::class); |
|
75 | - } |
|
72 | + public function registerNotifier() { |
|
73 | + $notificationsManager = $this->getContainer()->getServer()->getNotificationManager(); |
|
74 | + $notificationsManager->registerNotifierService(Notifier::class); |
|
75 | + } |
|
76 | 76 | } |
@@ -39,161 +39,161 @@ |
||
39 | 39 | |
40 | 40 | class Notifier implements INotifier { |
41 | 41 | |
42 | - /** @var IURLGenerator */ |
|
43 | - protected $url; |
|
44 | - |
|
45 | - /** @var IConfig */ |
|
46 | - protected $config; |
|
47 | - |
|
48 | - /** @var IManager */ |
|
49 | - protected $notificationManager; |
|
50 | - |
|
51 | - /** @var IFactory */ |
|
52 | - protected $l10NFactory; |
|
53 | - |
|
54 | - /** @var IUserSession */ |
|
55 | - protected $userSession; |
|
56 | - |
|
57 | - /** @var IGroupManager */ |
|
58 | - protected $groupManager; |
|
59 | - |
|
60 | - /** @var string[] */ |
|
61 | - protected $appVersions; |
|
62 | - |
|
63 | - /** |
|
64 | - * Notifier constructor. |
|
65 | - * |
|
66 | - * @param IURLGenerator $url |
|
67 | - * @param IConfig $config |
|
68 | - * @param IManager $notificationManager |
|
69 | - * @param IFactory $l10NFactory |
|
70 | - * @param IUserSession $userSession |
|
71 | - * @param IGroupManager $groupManager |
|
72 | - */ |
|
73 | - public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) { |
|
74 | - $this->url = $url; |
|
75 | - $this->notificationManager = $notificationManager; |
|
76 | - $this->config = $config; |
|
77 | - $this->l10NFactory = $l10NFactory; |
|
78 | - $this->userSession = $userSession; |
|
79 | - $this->groupManager = $groupManager; |
|
80 | - $this->appVersions = $this->getAppVersions(); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Identifier of the notifier, only use [a-z0-9_] |
|
85 | - * |
|
86 | - * @return string |
|
87 | - * @since 17.0.0 |
|
88 | - */ |
|
89 | - public function getID(): string { |
|
90 | - return 'updatenotification'; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Human readable name describing the notifier |
|
95 | - * |
|
96 | - * @return string |
|
97 | - * @since 17.0.0 |
|
98 | - */ |
|
99 | - public function getName(): string { |
|
100 | - return $this->l10NFactory->get('updatenotification')->t('Update notifications'); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param INotification $notification |
|
105 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
106 | - * @return INotification |
|
107 | - * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
108 | - * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted |
|
109 | - * @since 9.0.0 |
|
110 | - */ |
|
111 | - public function prepare(INotification $notification, string $languageCode): INotification { |
|
112 | - if ($notification->getApp() !== 'updatenotification') { |
|
113 | - throw new \InvalidArgumentException('Unknown app id'); |
|
114 | - } |
|
115 | - |
|
116 | - $l = $this->l10NFactory->get('updatenotification', $languageCode); |
|
117 | - if ($notification->getSubject() === 'connection_error') { |
|
118 | - $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
119 | - if ($errors === 0) { |
|
120 | - $this->notificationManager->markProcessed($notification); |
|
121 | - throw new \InvalidArgumentException('Update checked worked again'); |
|
122 | - } |
|
123 | - |
|
124 | - $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors])) |
|
125 | - ->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.')); |
|
126 | - } elseif ($notification->getObjectType() === 'core') { |
|
127 | - $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions()); |
|
128 | - |
|
129 | - $parameters = $notification->getSubjectParameters(); |
|
130 | - $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
|
131 | - |
|
132 | - if ($this->isAdmin()) { |
|
133 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']) . '#version'); |
|
134 | - } |
|
135 | - } else { |
|
136 | - $appInfo = $this->getAppInfo($notification->getObjectType()); |
|
137 | - $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; |
|
138 | - |
|
139 | - if (isset($this->appVersions[$notification->getObjectType()])) { |
|
140 | - $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); |
|
141 | - } |
|
142 | - |
|
143 | - $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])) |
|
144 | - ->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [ |
|
145 | - 'app' => [ |
|
146 | - 'type' => 'app', |
|
147 | - 'id' => $notification->getObjectType(), |
|
148 | - 'name' => $appName, |
|
149 | - ] |
|
150 | - ]); |
|
151 | - |
|
152 | - if ($this->isAdmin()) { |
|
153 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); |
|
158 | - |
|
159 | - return $notification; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Remove the notification and prevent rendering, when the update is installed |
|
164 | - * |
|
165 | - * @param INotification $notification |
|
166 | - * @param string $installedVersion |
|
167 | - * @throws AlreadyProcessedException When the update is already installed |
|
168 | - */ |
|
169 | - protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { |
|
170 | - if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { |
|
171 | - throw new AlreadyProcessedException(); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - protected function isAdmin(): bool { |
|
179 | - $user = $this->userSession->getUser(); |
|
180 | - |
|
181 | - if ($user instanceof IUser) { |
|
182 | - return $this->groupManager->isAdmin($user->getUID()); |
|
183 | - } |
|
184 | - |
|
185 | - return false; |
|
186 | - } |
|
187 | - |
|
188 | - protected function getCoreVersions(): string { |
|
189 | - return implode('.', Util::getVersion()); |
|
190 | - } |
|
191 | - |
|
192 | - protected function getAppVersions(): array { |
|
193 | - return \OC_App::getAppVersions(); |
|
194 | - } |
|
195 | - |
|
196 | - protected function getAppInfo($appId) { |
|
197 | - return \OC_App::getAppInfo($appId); |
|
198 | - } |
|
42 | + /** @var IURLGenerator */ |
|
43 | + protected $url; |
|
44 | + |
|
45 | + /** @var IConfig */ |
|
46 | + protected $config; |
|
47 | + |
|
48 | + /** @var IManager */ |
|
49 | + protected $notificationManager; |
|
50 | + |
|
51 | + /** @var IFactory */ |
|
52 | + protected $l10NFactory; |
|
53 | + |
|
54 | + /** @var IUserSession */ |
|
55 | + protected $userSession; |
|
56 | + |
|
57 | + /** @var IGroupManager */ |
|
58 | + protected $groupManager; |
|
59 | + |
|
60 | + /** @var string[] */ |
|
61 | + protected $appVersions; |
|
62 | + |
|
63 | + /** |
|
64 | + * Notifier constructor. |
|
65 | + * |
|
66 | + * @param IURLGenerator $url |
|
67 | + * @param IConfig $config |
|
68 | + * @param IManager $notificationManager |
|
69 | + * @param IFactory $l10NFactory |
|
70 | + * @param IUserSession $userSession |
|
71 | + * @param IGroupManager $groupManager |
|
72 | + */ |
|
73 | + public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) { |
|
74 | + $this->url = $url; |
|
75 | + $this->notificationManager = $notificationManager; |
|
76 | + $this->config = $config; |
|
77 | + $this->l10NFactory = $l10NFactory; |
|
78 | + $this->userSession = $userSession; |
|
79 | + $this->groupManager = $groupManager; |
|
80 | + $this->appVersions = $this->getAppVersions(); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Identifier of the notifier, only use [a-z0-9_] |
|
85 | + * |
|
86 | + * @return string |
|
87 | + * @since 17.0.0 |
|
88 | + */ |
|
89 | + public function getID(): string { |
|
90 | + return 'updatenotification'; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Human readable name describing the notifier |
|
95 | + * |
|
96 | + * @return string |
|
97 | + * @since 17.0.0 |
|
98 | + */ |
|
99 | + public function getName(): string { |
|
100 | + return $this->l10NFactory->get('updatenotification')->t('Update notifications'); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param INotification $notification |
|
105 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
106 | + * @return INotification |
|
107 | + * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
108 | + * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted |
|
109 | + * @since 9.0.0 |
|
110 | + */ |
|
111 | + public function prepare(INotification $notification, string $languageCode): INotification { |
|
112 | + if ($notification->getApp() !== 'updatenotification') { |
|
113 | + throw new \InvalidArgumentException('Unknown app id'); |
|
114 | + } |
|
115 | + |
|
116 | + $l = $this->l10NFactory->get('updatenotification', $languageCode); |
|
117 | + if ($notification->getSubject() === 'connection_error') { |
|
118 | + $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
119 | + if ($errors === 0) { |
|
120 | + $this->notificationManager->markProcessed($notification); |
|
121 | + throw new \InvalidArgumentException('Update checked worked again'); |
|
122 | + } |
|
123 | + |
|
124 | + $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors])) |
|
125 | + ->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.')); |
|
126 | + } elseif ($notification->getObjectType() === 'core') { |
|
127 | + $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions()); |
|
128 | + |
|
129 | + $parameters = $notification->getSubjectParameters(); |
|
130 | + $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
|
131 | + |
|
132 | + if ($this->isAdmin()) { |
|
133 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']) . '#version'); |
|
134 | + } |
|
135 | + } else { |
|
136 | + $appInfo = $this->getAppInfo($notification->getObjectType()); |
|
137 | + $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; |
|
138 | + |
|
139 | + if (isset($this->appVersions[$notification->getObjectType()])) { |
|
140 | + $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); |
|
141 | + } |
|
142 | + |
|
143 | + $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])) |
|
144 | + ->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [ |
|
145 | + 'app' => [ |
|
146 | + 'type' => 'app', |
|
147 | + 'id' => $notification->getObjectType(), |
|
148 | + 'name' => $appName, |
|
149 | + ] |
|
150 | + ]); |
|
151 | + |
|
152 | + if ($this->isAdmin()) { |
|
153 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); |
|
158 | + |
|
159 | + return $notification; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Remove the notification and prevent rendering, when the update is installed |
|
164 | + * |
|
165 | + * @param INotification $notification |
|
166 | + * @param string $installedVersion |
|
167 | + * @throws AlreadyProcessedException When the update is already installed |
|
168 | + */ |
|
169 | + protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { |
|
170 | + if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { |
|
171 | + throw new AlreadyProcessedException(); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + protected function isAdmin(): bool { |
|
179 | + $user = $this->userSession->getUser(); |
|
180 | + |
|
181 | + if ($user instanceof IUser) { |
|
182 | + return $this->groupManager->isAdmin($user->getUID()); |
|
183 | + } |
|
184 | + |
|
185 | + return false; |
|
186 | + } |
|
187 | + |
|
188 | + protected function getCoreVersions(): string { |
|
189 | + return implode('.', Util::getVersion()); |
|
190 | + } |
|
191 | + |
|
192 | + protected function getAppVersions(): array { |
|
193 | + return \OC_App::getAppVersions(); |
|
194 | + } |
|
195 | + |
|
196 | + protected function getAppInfo($appId) { |
|
197 | + return \OC_App::getAppInfo($appId); |
|
198 | + } |
|
199 | 199 | } |
@@ -35,217 +35,217 @@ |
||
35 | 35 | use OCP\Notification\INotifier; |
36 | 36 | |
37 | 37 | class Notifier implements INotifier { |
38 | - /** @var IFactory */ |
|
39 | - protected $factory; |
|
40 | - /** @var IManager */ |
|
41 | - protected $contactsManager; |
|
42 | - /** @var IURLGenerator */ |
|
43 | - protected $url; |
|
44 | - /** @var array */ |
|
45 | - protected $federatedContacts; |
|
46 | - /** @var ICloudIdManager */ |
|
47 | - protected $cloudIdManager; |
|
48 | - |
|
49 | - /** |
|
50 | - * @param IFactory $factory |
|
51 | - * @param IManager $contactsManager |
|
52 | - * @param IURLGenerator $url |
|
53 | - * @param ICloudIdManager $cloudIdManager |
|
54 | - */ |
|
55 | - public function __construct(IFactory $factory, IManager $contactsManager, IURLGenerator $url, ICloudIdManager $cloudIdManager) { |
|
56 | - $this->factory = $factory; |
|
57 | - $this->contactsManager = $contactsManager; |
|
58 | - $this->url = $url; |
|
59 | - $this->cloudIdManager = $cloudIdManager; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Identifier of the notifier, only use [a-z0-9_] |
|
64 | - * |
|
65 | - * @return string |
|
66 | - * @since 17.0.0 |
|
67 | - */ |
|
68 | - public function getID(): string { |
|
69 | - return 'federatedfilesharing'; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Human readable name describing the notifier |
|
74 | - * |
|
75 | - * @return string |
|
76 | - * @since 17.0.0 |
|
77 | - */ |
|
78 | - public function getName(): string { |
|
79 | - return $this->factory->get('federatedfilesharing')->t('Federated sharing'); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param INotification $notification |
|
84 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
85 | - * @return INotification |
|
86 | - * @throws \InvalidArgumentException |
|
87 | - */ |
|
88 | - public function prepare(INotification $notification, string $languageCode): INotification { |
|
89 | - if ($notification->getApp() !== 'files_sharing') { |
|
90 | - // Not my app => throw |
|
91 | - throw new \InvalidArgumentException(); |
|
92 | - } |
|
93 | - |
|
94 | - // Read the language from the notification |
|
95 | - $l = $this->factory->get('files_sharing', $languageCode); |
|
96 | - |
|
97 | - switch ($notification->getSubject()) { |
|
98 | - // Deal with known subjects |
|
99 | - case 'remote_share': |
|
100 | - $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
101 | - |
|
102 | - $params = $notification->getSubjectParameters(); |
|
103 | - if ($params[0] !== $params[1] && $params[1] !== null) { |
|
104 | - $notification->setParsedSubject( |
|
105 | - $l->t('You received "%3$s" as a remote share from %1$s (on behalf of %2$s)', $params) |
|
106 | - ); |
|
107 | - $notification->setRichSubject( |
|
108 | - $l->t('You received {share} as a remote share from {user} (on behalf of {behalf})'), |
|
109 | - [ |
|
110 | - 'share' => [ |
|
111 | - 'type' => 'pending-federated-share', |
|
112 | - 'id' => $notification->getObjectId(), |
|
113 | - 'name' => $params[2], |
|
114 | - ], |
|
115 | - 'user' => $this->createRemoteUser($params[0]), |
|
116 | - 'behalf' => $this->createRemoteUser($params[1]), |
|
117 | - ] |
|
118 | - ); |
|
119 | - } else { |
|
120 | - $notification->setParsedSubject( |
|
121 | - $l->t('You received "%3$s" as a remote share from %1$s', $params) |
|
122 | - ); |
|
123 | - $notification->setRichSubject( |
|
124 | - $l->t('You received {share} as a remote share from {user}'), |
|
125 | - [ |
|
126 | - 'share' => [ |
|
127 | - 'type' => 'pending-federated-share', |
|
128 | - 'id' => $notification->getObjectId(), |
|
129 | - 'name' => $params[2], |
|
130 | - ], |
|
131 | - 'user' => $this->createRemoteUser($params[0]), |
|
132 | - ] |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - // Deal with the actions for a known subject |
|
137 | - foreach ($notification->getActions() as $action) { |
|
138 | - switch ($action->getLabel()) { |
|
139 | - case 'accept': |
|
140 | - $action->setParsedLabel( |
|
141 | - (string) $l->t('Accept') |
|
142 | - ) |
|
143 | - ->setPrimary(true); |
|
144 | - break; |
|
145 | - |
|
146 | - case 'decline': |
|
147 | - $action->setParsedLabel( |
|
148 | - (string) $l->t('Decline') |
|
149 | - ); |
|
150 | - break; |
|
151 | - } |
|
152 | - |
|
153 | - $notification->addParsedAction($action); |
|
154 | - } |
|
155 | - return $notification; |
|
156 | - |
|
157 | - default: |
|
158 | - // Unknown subject => Unknown notification => throw |
|
159 | - throw new \InvalidArgumentException(); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @param string $cloudId |
|
165 | - * @return array |
|
166 | - */ |
|
167 | - protected function createRemoteUser($cloudId) { |
|
168 | - $displayName = $cloudId; |
|
169 | - try { |
|
170 | - $resolvedId = $this->cloudIdManager->resolveCloudId($cloudId); |
|
171 | - $displayName = $this->getDisplayName($resolvedId); |
|
172 | - $user = $resolvedId->getUser(); |
|
173 | - $server = $resolvedId->getRemote(); |
|
174 | - } catch (HintException $e) { |
|
175 | - $user = $cloudId; |
|
176 | - $server = ''; |
|
177 | - } |
|
178 | - |
|
179 | - return [ |
|
180 | - 'type' => 'user', |
|
181 | - 'id' => $user, |
|
182 | - 'name' => $displayName, |
|
183 | - 'server' => $server, |
|
184 | - ]; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Try to find the user in the contacts |
|
189 | - * |
|
190 | - * @param ICloudId $cloudId |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - protected function getDisplayName(ICloudId $cloudId) { |
|
194 | - $server = $cloudId->getRemote(); |
|
195 | - $user = $cloudId->getUser(); |
|
196 | - if (strpos($server, 'http://') === 0) { |
|
197 | - $server = substr($server, strlen('http://')); |
|
198 | - } else if (strpos($server, 'https://') === 0) { |
|
199 | - $server = substr($server, strlen('https://')); |
|
200 | - } |
|
201 | - |
|
202 | - try { |
|
203 | - return $this->getDisplayNameFromContact($cloudId->getId()); |
|
204 | - } catch (\OutOfBoundsException $e) { |
|
205 | - } |
|
206 | - |
|
207 | - try { |
|
208 | - $this->getDisplayNameFromContact($user . '@http://' . $server); |
|
209 | - } catch (\OutOfBoundsException $e) { |
|
210 | - } |
|
211 | - |
|
212 | - try { |
|
213 | - $this->getDisplayNameFromContact($user . '@https://' . $server); |
|
214 | - } catch (\OutOfBoundsException $e) { |
|
215 | - } |
|
216 | - |
|
217 | - return $cloudId->getId(); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Try to find the user in the contacts |
|
222 | - * |
|
223 | - * @param string $federatedCloudId |
|
224 | - * @return string |
|
225 | - * @throws \OutOfBoundsException when there is no contact for the id |
|
226 | - */ |
|
227 | - protected function getDisplayNameFromContact($federatedCloudId) { |
|
228 | - if (isset($this->federatedContacts[$federatedCloudId])) { |
|
229 | - if ($this->federatedContacts[$federatedCloudId] !== '') { |
|
230 | - return $this->federatedContacts[$federatedCloudId]; |
|
231 | - } else { |
|
232 | - throw new \OutOfBoundsException('No contact found for federated cloud id'); |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - $addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD']); |
|
237 | - foreach ($addressBookEntries as $entry) { |
|
238 | - if (isset($entry['CLOUD'])) { |
|
239 | - foreach ($entry['CLOUD'] as $cloudID) { |
|
240 | - if ($cloudID === $federatedCloudId) { |
|
241 | - $this->federatedContacts[$federatedCloudId] = $entry['FN']; |
|
242 | - return $entry['FN']; |
|
243 | - } |
|
244 | - } |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - $this->federatedContacts[$federatedCloudId] = ''; |
|
249 | - throw new \OutOfBoundsException('No contact found for federated cloud id'); |
|
250 | - } |
|
38 | + /** @var IFactory */ |
|
39 | + protected $factory; |
|
40 | + /** @var IManager */ |
|
41 | + protected $contactsManager; |
|
42 | + /** @var IURLGenerator */ |
|
43 | + protected $url; |
|
44 | + /** @var array */ |
|
45 | + protected $federatedContacts; |
|
46 | + /** @var ICloudIdManager */ |
|
47 | + protected $cloudIdManager; |
|
48 | + |
|
49 | + /** |
|
50 | + * @param IFactory $factory |
|
51 | + * @param IManager $contactsManager |
|
52 | + * @param IURLGenerator $url |
|
53 | + * @param ICloudIdManager $cloudIdManager |
|
54 | + */ |
|
55 | + public function __construct(IFactory $factory, IManager $contactsManager, IURLGenerator $url, ICloudIdManager $cloudIdManager) { |
|
56 | + $this->factory = $factory; |
|
57 | + $this->contactsManager = $contactsManager; |
|
58 | + $this->url = $url; |
|
59 | + $this->cloudIdManager = $cloudIdManager; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Identifier of the notifier, only use [a-z0-9_] |
|
64 | + * |
|
65 | + * @return string |
|
66 | + * @since 17.0.0 |
|
67 | + */ |
|
68 | + public function getID(): string { |
|
69 | + return 'federatedfilesharing'; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Human readable name describing the notifier |
|
74 | + * |
|
75 | + * @return string |
|
76 | + * @since 17.0.0 |
|
77 | + */ |
|
78 | + public function getName(): string { |
|
79 | + return $this->factory->get('federatedfilesharing')->t('Federated sharing'); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param INotification $notification |
|
84 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
85 | + * @return INotification |
|
86 | + * @throws \InvalidArgumentException |
|
87 | + */ |
|
88 | + public function prepare(INotification $notification, string $languageCode): INotification { |
|
89 | + if ($notification->getApp() !== 'files_sharing') { |
|
90 | + // Not my app => throw |
|
91 | + throw new \InvalidArgumentException(); |
|
92 | + } |
|
93 | + |
|
94 | + // Read the language from the notification |
|
95 | + $l = $this->factory->get('files_sharing', $languageCode); |
|
96 | + |
|
97 | + switch ($notification->getSubject()) { |
|
98 | + // Deal with known subjects |
|
99 | + case 'remote_share': |
|
100 | + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
101 | + |
|
102 | + $params = $notification->getSubjectParameters(); |
|
103 | + if ($params[0] !== $params[1] && $params[1] !== null) { |
|
104 | + $notification->setParsedSubject( |
|
105 | + $l->t('You received "%3$s" as a remote share from %1$s (on behalf of %2$s)', $params) |
|
106 | + ); |
|
107 | + $notification->setRichSubject( |
|
108 | + $l->t('You received {share} as a remote share from {user} (on behalf of {behalf})'), |
|
109 | + [ |
|
110 | + 'share' => [ |
|
111 | + 'type' => 'pending-federated-share', |
|
112 | + 'id' => $notification->getObjectId(), |
|
113 | + 'name' => $params[2], |
|
114 | + ], |
|
115 | + 'user' => $this->createRemoteUser($params[0]), |
|
116 | + 'behalf' => $this->createRemoteUser($params[1]), |
|
117 | + ] |
|
118 | + ); |
|
119 | + } else { |
|
120 | + $notification->setParsedSubject( |
|
121 | + $l->t('You received "%3$s" as a remote share from %1$s', $params) |
|
122 | + ); |
|
123 | + $notification->setRichSubject( |
|
124 | + $l->t('You received {share} as a remote share from {user}'), |
|
125 | + [ |
|
126 | + 'share' => [ |
|
127 | + 'type' => 'pending-federated-share', |
|
128 | + 'id' => $notification->getObjectId(), |
|
129 | + 'name' => $params[2], |
|
130 | + ], |
|
131 | + 'user' => $this->createRemoteUser($params[0]), |
|
132 | + ] |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + // Deal with the actions for a known subject |
|
137 | + foreach ($notification->getActions() as $action) { |
|
138 | + switch ($action->getLabel()) { |
|
139 | + case 'accept': |
|
140 | + $action->setParsedLabel( |
|
141 | + (string) $l->t('Accept') |
|
142 | + ) |
|
143 | + ->setPrimary(true); |
|
144 | + break; |
|
145 | + |
|
146 | + case 'decline': |
|
147 | + $action->setParsedLabel( |
|
148 | + (string) $l->t('Decline') |
|
149 | + ); |
|
150 | + break; |
|
151 | + } |
|
152 | + |
|
153 | + $notification->addParsedAction($action); |
|
154 | + } |
|
155 | + return $notification; |
|
156 | + |
|
157 | + default: |
|
158 | + // Unknown subject => Unknown notification => throw |
|
159 | + throw new \InvalidArgumentException(); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @param string $cloudId |
|
165 | + * @return array |
|
166 | + */ |
|
167 | + protected function createRemoteUser($cloudId) { |
|
168 | + $displayName = $cloudId; |
|
169 | + try { |
|
170 | + $resolvedId = $this->cloudIdManager->resolveCloudId($cloudId); |
|
171 | + $displayName = $this->getDisplayName($resolvedId); |
|
172 | + $user = $resolvedId->getUser(); |
|
173 | + $server = $resolvedId->getRemote(); |
|
174 | + } catch (HintException $e) { |
|
175 | + $user = $cloudId; |
|
176 | + $server = ''; |
|
177 | + } |
|
178 | + |
|
179 | + return [ |
|
180 | + 'type' => 'user', |
|
181 | + 'id' => $user, |
|
182 | + 'name' => $displayName, |
|
183 | + 'server' => $server, |
|
184 | + ]; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Try to find the user in the contacts |
|
189 | + * |
|
190 | + * @param ICloudId $cloudId |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + protected function getDisplayName(ICloudId $cloudId) { |
|
194 | + $server = $cloudId->getRemote(); |
|
195 | + $user = $cloudId->getUser(); |
|
196 | + if (strpos($server, 'http://') === 0) { |
|
197 | + $server = substr($server, strlen('http://')); |
|
198 | + } else if (strpos($server, 'https://') === 0) { |
|
199 | + $server = substr($server, strlen('https://')); |
|
200 | + } |
|
201 | + |
|
202 | + try { |
|
203 | + return $this->getDisplayNameFromContact($cloudId->getId()); |
|
204 | + } catch (\OutOfBoundsException $e) { |
|
205 | + } |
|
206 | + |
|
207 | + try { |
|
208 | + $this->getDisplayNameFromContact($user . '@http://' . $server); |
|
209 | + } catch (\OutOfBoundsException $e) { |
|
210 | + } |
|
211 | + |
|
212 | + try { |
|
213 | + $this->getDisplayNameFromContact($user . '@https://' . $server); |
|
214 | + } catch (\OutOfBoundsException $e) { |
|
215 | + } |
|
216 | + |
|
217 | + return $cloudId->getId(); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Try to find the user in the contacts |
|
222 | + * |
|
223 | + * @param string $federatedCloudId |
|
224 | + * @return string |
|
225 | + * @throws \OutOfBoundsException when there is no contact for the id |
|
226 | + */ |
|
227 | + protected function getDisplayNameFromContact($federatedCloudId) { |
|
228 | + if (isset($this->federatedContacts[$federatedCloudId])) { |
|
229 | + if ($this->federatedContacts[$federatedCloudId] !== '') { |
|
230 | + return $this->federatedContacts[$federatedCloudId]; |
|
231 | + } else { |
|
232 | + throw new \OutOfBoundsException('No contact found for federated cloud id'); |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + $addressBookEntries = $this->contactsManager->search($federatedCloudId, ['CLOUD']); |
|
237 | + foreach ($addressBookEntries as $entry) { |
|
238 | + if (isset($entry['CLOUD'])) { |
|
239 | + foreach ($entry['CLOUD'] as $cloudID) { |
|
240 | + if ($cloudID === $federatedCloudId) { |
|
241 | + $this->federatedContacts[$federatedCloudId] = $entry['FN']; |
|
242 | + return $entry['FN']; |
|
243 | + } |
|
244 | + } |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + $this->federatedContacts[$federatedCloudId] = ''; |
|
249 | + throw new \OutOfBoundsException('No contact found for federated cloud id'); |
|
250 | + } |
|
251 | 251 | } |
@@ -34,10 +34,10 @@ |
||
34 | 34 | $federatedShareProvider = $app->getFederatedShareProvider(); |
35 | 35 | |
36 | 36 | $eventDispatcher->addListener( |
37 | - 'OCA\Files::loadAdditionalScripts', |
|
38 | - function() use ($federatedShareProvider) { |
|
39 | - if ($federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
40 | - \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
41 | - } |
|
42 | - } |
|
37 | + 'OCA\Files::loadAdditionalScripts', |
|
38 | + function() use ($federatedShareProvider) { |
|
39 | + if ($federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
40 | + \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
41 | + } |
|
42 | + } |
|
43 | 43 | ); |
@@ -41,45 +41,45 @@ |
||
41 | 41 | use OCP\Util; |
42 | 42 | |
43 | 43 | class Application extends App { |
44 | - public function __construct() { |
|
45 | - parent::__construct('twofactor_backupcodes'); |
|
46 | - } |
|
44 | + public function __construct() { |
|
45 | + parent::__construct('twofactor_backupcodes'); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Register the different app parts |
|
50 | - */ |
|
51 | - public function register() { |
|
52 | - $this->registerHooksAndEvents(); |
|
53 | - $this->registerNotification(); |
|
54 | - } |
|
48 | + /** |
|
49 | + * Register the different app parts |
|
50 | + */ |
|
51 | + public function register() { |
|
52 | + $this->registerHooksAndEvents(); |
|
53 | + $this->registerNotification(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Register the hooks and events |
|
58 | - */ |
|
59 | - public function registerHooksAndEvents() { |
|
60 | - Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser'); |
|
56 | + /** |
|
57 | + * Register the hooks and events |
|
58 | + */ |
|
59 | + public function registerHooksAndEvents() { |
|
60 | + Util::connectHook('OC_User', 'post_deleteUser', $this, 'deleteUser'); |
|
61 | 61 | |
62 | - $container = $this->getContainer(); |
|
62 | + $container = $this->getContainer(); |
|
63 | 63 | |
64 | - /** @var IEventDispatcher $eventDispatcher */ |
|
65 | - $eventDispatcher = $container->query(IEventDispatcher::class); |
|
66 | - $eventDispatcher->addServiceListener(CodesGenerated::class, ActivityPublisher::class); |
|
67 | - $eventDispatcher->addServiceListener(CodesGenerated::class, RegistryUpdater::class); |
|
68 | - $eventDispatcher->addServiceListener(CodesGenerated::class, ClearNotifications::class); |
|
69 | - $eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class); |
|
70 | - $eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class); |
|
71 | - } |
|
64 | + /** @var IEventDispatcher $eventDispatcher */ |
|
65 | + $eventDispatcher = $container->query(IEventDispatcher::class); |
|
66 | + $eventDispatcher->addServiceListener(CodesGenerated::class, ActivityPublisher::class); |
|
67 | + $eventDispatcher->addServiceListener(CodesGenerated::class, RegistryUpdater::class); |
|
68 | + $eventDispatcher->addServiceListener(CodesGenerated::class, ClearNotifications::class); |
|
69 | + $eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_ENABLED, ProviderEnabled::class); |
|
70 | + $eventDispatcher->addServiceListener(IRegistry::EVENT_PROVIDER_DISABLED, ProviderDisabled::class); |
|
71 | + } |
|
72 | 72 | |
73 | - public function registerNotification() { |
|
74 | - $container = $this->getContainer(); |
|
75 | - /** @var IManager $manager */ |
|
76 | - $manager = $container->query(IManager::class); |
|
77 | - $manager->registerNotifierService(Notifier::class); |
|
78 | - } |
|
73 | + public function registerNotification() { |
|
74 | + $container = $this->getContainer(); |
|
75 | + /** @var IManager $manager */ |
|
76 | + $manager = $container->query(IManager::class); |
|
77 | + $manager->registerNotifierService(Notifier::class); |
|
78 | + } |
|
79 | 79 | |
80 | - public function deleteUser($params) { |
|
81 | - /** @var BackupCodeMapper $mapper */ |
|
82 | - $mapper = $this->getContainer()->query(BackupCodeMapper::class); |
|
83 | - $mapper->deleteCodesByUserId($params['uid']); |
|
84 | - } |
|
80 | + public function deleteUser($params) { |
|
81 | + /** @var BackupCodeMapper $mapper */ |
|
82 | + $mapper = $this->getContainer()->query(BackupCodeMapper::class); |
|
83 | + $mapper->deleteCodesByUserId($params['uid']); |
|
84 | + } |
|
85 | 85 | } |
@@ -31,63 +31,63 @@ |
||
31 | 31 | |
32 | 32 | class Notifier implements INotifier { |
33 | 33 | |
34 | - /** @var IFactory */ |
|
35 | - private $factory; |
|
34 | + /** @var IFactory */ |
|
35 | + private $factory; |
|
36 | 36 | |
37 | - /** @var IURLGenerator */ |
|
38 | - private $url; |
|
37 | + /** @var IURLGenerator */ |
|
38 | + private $url; |
|
39 | 39 | |
40 | - public function __construct(IFactory $factory, IURLGenerator $url) { |
|
41 | - $this->factory = $factory; |
|
42 | - $this->url = $url; |
|
43 | - } |
|
40 | + public function __construct(IFactory $factory, IURLGenerator $url) { |
|
41 | + $this->factory = $factory; |
|
42 | + $this->url = $url; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Identifier of the notifier, only use [a-z0-9_] |
|
47 | - * |
|
48 | - * @return string |
|
49 | - * @since 17.0.0 |
|
50 | - */ |
|
51 | - public function getID(): string { |
|
52 | - return 'twofactor_backupcodes'; |
|
53 | - } |
|
45 | + /** |
|
46 | + * Identifier of the notifier, only use [a-z0-9_] |
|
47 | + * |
|
48 | + * @return string |
|
49 | + * @since 17.0.0 |
|
50 | + */ |
|
51 | + public function getID(): string { |
|
52 | + return 'twofactor_backupcodes'; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Human readable name describing the notifier |
|
57 | - * |
|
58 | - * @return string |
|
59 | - * @since 17.0.0 |
|
60 | - */ |
|
61 | - public function getName(): string { |
|
62 | - return $this->factory->get('twofactor_backupcodes')->t('Second-factor backup codes'); |
|
63 | - } |
|
55 | + /** |
|
56 | + * Human readable name describing the notifier |
|
57 | + * |
|
58 | + * @return string |
|
59 | + * @since 17.0.0 |
|
60 | + */ |
|
61 | + public function getName(): string { |
|
62 | + return $this->factory->get('twofactor_backupcodes')->t('Second-factor backup codes'); |
|
63 | + } |
|
64 | 64 | |
65 | - public function prepare(INotification $notification, string $languageCode): INotification { |
|
66 | - if ($notification->getApp() !== 'twofactor_backupcodes') { |
|
67 | - // Not my app => throw |
|
68 | - throw new \InvalidArgumentException(); |
|
69 | - } |
|
65 | + public function prepare(INotification $notification, string $languageCode): INotification { |
|
66 | + if ($notification->getApp() !== 'twofactor_backupcodes') { |
|
67 | + // Not my app => throw |
|
68 | + throw new \InvalidArgumentException(); |
|
69 | + } |
|
70 | 70 | |
71 | - // Read the language from the notification |
|
72 | - $l = $this->factory->get('twofactor_backupcodes', $languageCode); |
|
71 | + // Read the language from the notification |
|
72 | + $l = $this->factory->get('twofactor_backupcodes', $languageCode); |
|
73 | 73 | |
74 | - switch ($notification->getSubject()) { |
|
75 | - case 'create_backupcodes': |
|
76 | - $notification->setParsedSubject( |
|
77 | - $l->t('Generate backup codes') |
|
78 | - )->setParsedMessage( |
|
79 | - $l->t('You enabled two-factor authentication but did not generate backup codes yet. They are needed to restore access to your account in case you lose your second factor.') |
|
80 | - ); |
|
74 | + switch ($notification->getSubject()) { |
|
75 | + case 'create_backupcodes': |
|
76 | + $notification->setParsedSubject( |
|
77 | + $l->t('Generate backup codes') |
|
78 | + )->setParsedMessage( |
|
79 | + $l->t('You enabled two-factor authentication but did not generate backup codes yet. They are needed to restore access to your account in case you lose your second factor.') |
|
80 | + ); |
|
81 | 81 | |
82 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.PersonalSettings.index', ['section' => 'security'])); |
|
82 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.PersonalSettings.index', ['section' => 'security'])); |
|
83 | 83 | |
84 | - $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/password.svg'))); |
|
84 | + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/password.svg'))); |
|
85 | 85 | |
86 | - return $notification; |
|
86 | + return $notification; |
|
87 | 87 | |
88 | - default: |
|
89 | - // Unknown subject => Unknown notification => throw |
|
90 | - throw new \InvalidArgumentException(); |
|
91 | - } |
|
92 | - } |
|
88 | + default: |
|
89 | + // Unknown subject => Unknown notification => throw |
|
90 | + throw new \InvalidArgumentException(); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | } |
@@ -35,53 +35,53 @@ |
||
35 | 35 | |
36 | 36 | class Application extends App { |
37 | 37 | |
38 | - public function __construct (array $urlParams = array()) { |
|
39 | - parent::__construct('comments', $urlParams); |
|
40 | - $container = $this->getContainer(); |
|
38 | + public function __construct (array $urlParams = array()) { |
|
39 | + parent::__construct('comments', $urlParams); |
|
40 | + $container = $this->getContainer(); |
|
41 | 41 | |
42 | - $container->registerAlias('NotificationsController', Notifications::class); |
|
42 | + $container->registerAlias('NotificationsController', Notifications::class); |
|
43 | 43 | |
44 | - $jsSettingsHelper = new JSSettingsHelper($container->getServer()); |
|
45 | - Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); |
|
46 | - } |
|
44 | + $jsSettingsHelper = new JSSettingsHelper($container->getServer()); |
|
45 | + Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend'); |
|
46 | + } |
|
47 | 47 | |
48 | - public function register() { |
|
49 | - $server = $this->getContainer()->getServer(); |
|
48 | + public function register() { |
|
49 | + $server = $this->getContainer()->getServer(); |
|
50 | 50 | |
51 | - $dispatcher = $server->getEventDispatcher(); |
|
52 | - $this->registerSidebarScripts($dispatcher); |
|
53 | - $this->registerDavEntity($dispatcher); |
|
54 | - $this->registerNotifier(); |
|
55 | - $this->registerCommentsEventHandler(); |
|
51 | + $dispatcher = $server->getEventDispatcher(); |
|
52 | + $this->registerSidebarScripts($dispatcher); |
|
53 | + $this->registerDavEntity($dispatcher); |
|
54 | + $this->registerNotifier(); |
|
55 | + $this->registerCommentsEventHandler(); |
|
56 | 56 | |
57 | - $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); |
|
58 | - } |
|
57 | + $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]); |
|
58 | + } |
|
59 | 59 | |
60 | - protected function registerSidebarScripts(EventDispatcherInterface $dispatcher) { |
|
61 | - $dispatcher->addListener( |
|
62 | - 'OCA\Files::loadAdditionalScripts', |
|
63 | - function() { |
|
64 | - Util::addScript('comments', 'comments'); |
|
65 | - } |
|
66 | - ); |
|
67 | - } |
|
60 | + protected function registerSidebarScripts(EventDispatcherInterface $dispatcher) { |
|
61 | + $dispatcher->addListener( |
|
62 | + 'OCA\Files::loadAdditionalScripts', |
|
63 | + function() { |
|
64 | + Util::addScript('comments', 'comments'); |
|
65 | + } |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function registerDavEntity(EventDispatcherInterface $dispatcher) { |
|
70 | - $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) { |
|
71 | - $event->addEntityCollection('files', function($name) { |
|
72 | - $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
73 | - return !empty($nodes); |
|
74 | - }); |
|
75 | - }); |
|
76 | - } |
|
69 | + protected function registerDavEntity(EventDispatcherInterface $dispatcher) { |
|
70 | + $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) { |
|
71 | + $event->addEntityCollection('files', function($name) { |
|
72 | + $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
73 | + return !empty($nodes); |
|
74 | + }); |
|
75 | + }); |
|
76 | + } |
|
77 | 77 | |
78 | - protected function registerNotifier() { |
|
79 | - $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class); |
|
80 | - } |
|
78 | + protected function registerNotifier() { |
|
79 | + $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class); |
|
80 | + } |
|
81 | 81 | |
82 | - protected function registerCommentsEventHandler() { |
|
83 | - $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () { |
|
84 | - return $this->getContainer()->query(EventHandler::class); |
|
85 | - }); |
|
86 | - } |
|
82 | + protected function registerCommentsEventHandler() { |
|
83 | + $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () { |
|
84 | + return $this->getContainer()->query(EventHandler::class); |
|
85 | + }); |
|
86 | + } |
|
87 | 87 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | class Application extends App { |
37 | 37 | |
38 | - public function __construct (array $urlParams = array()) { |
|
38 | + public function __construct(array $urlParams = array()) { |
|
39 | 39 | parent::__construct('comments', $urlParams); |
40 | 40 | $container = $this->getContainer(); |
41 | 41 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | protected function registerDavEntity(EventDispatcherInterface $dispatcher) { |
70 | 70 | $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) { |
71 | 71 | $event->addEntityCollection('files', function($name) { |
72 | - $nodes = \OC::$server->getUserFolder()->getById((int)$name); |
|
72 | + $nodes = \OC::$server->getUserFolder()->getById((int) $name); |
|
73 | 73 | return !empty($nodes); |
74 | 74 | }); |
75 | 75 | }); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | protected function registerCommentsEventHandler() { |
83 | - $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () { |
|
83 | + $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function() { |
|
84 | 84 | return $this->getContainer()->query(EventHandler::class); |
85 | 85 | }); |
86 | 86 | } |