aboutsummaryrefslogtreecommitdiffstats
path: root/apps/updatenotification/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/updatenotification/lib')
-rw-r--r--apps/updatenotification/lib/AppInfo/Application.php37
-rw-r--r--apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php23
-rw-r--r--apps/updatenotification/lib/BackgroundJob/ResetToken.php23
-rw-r--r--apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php84
-rw-r--r--apps/updatenotification/lib/Command/Check.php52
-rw-r--r--apps/updatenotification/lib/Controller/APIController.php62
-rw-r--r--apps/updatenotification/lib/Controller/AdminController.php29
-rw-r--r--apps/updatenotification/lib/Controller/ChangelogController.php30
-rw-r--r--apps/updatenotification/lib/Listener/AppUpdateEventListener.php21
-rw-r--r--apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php24
-rw-r--r--apps/updatenotification/lib/Manager.php29
-rw-r--r--apps/updatenotification/lib/Migration/Version011901Date20240305120000.php73
-rw-r--r--apps/updatenotification/lib/Notification/AppUpdateNotifier.php35
-rw-r--r--apps/updatenotification/lib/Notification/Notifier.php108
-rw-r--r--apps/updatenotification/lib/ResponseDefinitions.php21
-rw-r--r--apps/updatenotification/lib/Settings/Admin.php68
-rw-r--r--apps/updatenotification/lib/UpdateChecker.php57
17 files changed, 190 insertions, 586 deletions
diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php
index b82355cf468..2a1678da5db 100644
--- a/apps/updatenotification/lib/AppInfo/Application.php
+++ b/apps/updatenotification/lib/AppInfo/Application.php
@@ -3,30 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018, Joas Schilling <coding@schilljs.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification\AppInfo;
@@ -72,7 +50,8 @@ class Application extends App implements IBootstrap {
IAppManager $appManager,
IGroupManager $groupManager,
ContainerInterface $container,
- LoggerInterface $logger) {
+ LoggerInterface $logger,
+ ): void {
if ($config->getSystemValue('updatechecker', true) !== true) {
// Updater check is disabled
return;
@@ -84,8 +63,8 @@ class Application extends App implements IBootstrap {
return;
}
- if (!$appManager->isEnabledForUser('notifications') &&
- $groupManager->isAdmin($user->getUID())) {
+ if (!$appManager->isEnabledForUser('notifications')
+ && $groupManager->isAdmin($user->getUID())) {
try {
$updateChecker = $container->get(UpdateChecker::class);
} catch (ContainerExceptionInterface $e) {
@@ -94,8 +73,8 @@ class Application extends App implements IBootstrap {
}
if ($updateChecker->getUpdateState() !== []) {
- Util::addScript('updatenotification', 'legacy-notification');
- \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables');
+ Util::addScript(self::APP_NAME, 'update-notification-legacy');
+ $updateChecker->setInitialState();
}
}
});
diff --git a/apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php b/apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php
index 11d6577e81b..049390546ed 100644
--- a/apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php
+++ b/apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php
@@ -2,25 +2,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification\BackgroundJob;
@@ -105,7 +88,7 @@ class AppUpdatedNotifications extends QueuedJob {
$isDefer = $this->notificationManager->defer();
// Notify all seen users about the app update
- $this->userManager->callForSeenUsers(function (IUser $user) use ($guestsEnabled, $appId, $notification) {
+ $this->userManager->callForSeenUsers(function (IUser $user) use ($guestsEnabled, $appId, $notification): void {
if (!$guestsEnabled && ($user->getBackendClassName() === '\OCA\Guests\UserBackend')) {
return;
}
diff --git a/apps/updatenotification/lib/BackgroundJob/ResetToken.php b/apps/updatenotification/lib/BackgroundJob/ResetToken.php
index 05f8ea639a8..35543ce5247 100644
--- a/apps/updatenotification/lib/BackgroundJob/ResetToken.php
+++ b/apps/updatenotification/lib/BackgroundJob/ResetToken.php
@@ -3,27 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification\BackgroundJob;
diff --git a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php
index f561f38fdc0..8879bb0c223 100644
--- a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php
+++ b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php
@@ -3,32 +3,14 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification\BackgroundJob;
use OC\Installer;
use OC\Updater\VersionCheck;
+use OCA\UpdateNotification\AppInfo\Application;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -37,15 +19,22 @@ use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\Notification\IManager;
+use OCP\ServerVersion;
class UpdateAvailableNotifications extends TimedJob {
- protected $connectionNotifications = [3, 7, 14, 30];
- /** @var string[] */
- protected $users;
+ /**
+ * Numbers of failed updater connection to report error as notification.
+ * @var list<int>
+ */
+ protected const CONNECTION_NOTIFICATIONS = [3, 7, 14, 30];
+
+ /** @var ?string[] */
+ protected $users = null;
public function __construct(
ITimeFactory $timeFactory,
+ protected ServerVersion $serverVersion,
protected IConfig $config,
protected IAppConfig $appConfig,
protected IManager $notificationManager,
@@ -57,6 +46,7 @@ class UpdateAvailableNotifications extends TimedJob {
parent::__construct($timeFactory);
// Run once a day
$this->setInterval(60 * 60 * 24);
+ $this->setTimeSensitivity(self::TIME_INSENSITIVE);
}
protected function run($argument) {
@@ -80,10 +70,15 @@ class UpdateAvailableNotifications extends TimedJob {
}
/**
- * Check for ownCloud update
+ * Check for Nextcloud server update
*/
- protected function checkCoreUpdate() {
- if (\in_array($this->getChannel(), ['daily', 'git'], true)) {
+ protected function checkCoreUpdate(): void {
+ if (!$this->config->getSystemValueBool('updatechecker', true)) {
+ // update checker is disabled so no core update check!
+ return;
+ }
+
+ if (\in_array($this->serverVersion->getChannel(), ['daily', 'git'], true)) {
// "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi
return;
}
@@ -93,7 +88,7 @@ class UpdateAvailableNotifications extends TimedJob {
$errors = 1 + $this->appConfig->getAppValueInt('update_check_errors', 0);
$this->appConfig->setAppValueInt('update_check_errors', $errors);
- if (\in_array($errors, $this->connectionNotifications, true)) {
+ if (\in_array($errors, self::CONNECTION_NOTIFICATIONS, true)) {
$this->sendErrorNotifications($errors);
}
} elseif (\is_array($status)) {
@@ -110,14 +105,14 @@ class UpdateAvailableNotifications extends TimedJob {
* Send a message to the admin when the update server could not be reached
* @param int $numDays
*/
- protected function sendErrorNotifications($numDays) {
+ protected function sendErrorNotifications($numDays): void {
$this->clearErrorNotifications();
$notification = $this->notificationManager->createNotification();
try {
- $notification->setApp('updatenotification')
+ $notification->setApp(Application::APP_NAME)
->setDateTime(new \DateTime())
- ->setObject('updatenotification', 'error')
+ ->setObject(Application::APP_NAME, 'error')
->setSubject('connection_error', ['days' => $numDays]);
foreach ($this->getUsersToNotify() as $uid) {
@@ -132,12 +127,12 @@ class UpdateAvailableNotifications extends TimedJob {
/**
* Remove error notifications again
*/
- protected function clearErrorNotifications() {
+ protected function clearErrorNotifications(): void {
$notification = $this->notificationManager->createNotification();
try {
- $notification->setApp('updatenotification')
+ $notification->setApp(Application::APP_NAME)
->setSubject('connection_error')
- ->setObject('updatenotification', 'error');
+ ->setObject(Application::APP_NAME, 'error');
} catch (\InvalidArgumentException $e) {
return;
}
@@ -147,8 +142,8 @@ class UpdateAvailableNotifications extends TimedJob {
/**
* Check all installed apps for updates
*/
- protected function checkAppUpdates() {
- $apps = $this->appManager->getInstalledApps();
+ protected function checkAppUpdates(): void {
+ $apps = $this->appManager->getEnabledApps();
foreach ($apps as $app) {
$update = $this->isUpdateAvailable($app);
if ($update !== false) {
@@ -164,7 +159,7 @@ class UpdateAvailableNotifications extends TimedJob {
* @param string $version
* @param string $visibleVersion
*/
- protected function createNotifications($app, $version, $visibleVersion = '') {
+ protected function createNotifications($app, $version, $visibleVersion = ''): void {
$lastNotification = $this->appConfig->getAppValueString($app, '');
if ($lastNotification === $version) {
// We already notified about this update
@@ -178,7 +173,7 @@ class UpdateAvailableNotifications extends TimedJob {
$notification = $this->notificationManager->createNotification();
try {
- $notification->setApp('updatenotification')
+ $notification->setApp(Application::APP_NAME)
->setDateTime(new \DateTime())
->setObject($app, $version);
@@ -228,25 +223,18 @@ class UpdateAvailableNotifications extends TimedJob {
* @param string $app
* @param string $version
*/
- protected function deleteOutdatedNotifications($app, $version) {
+ protected function deleteOutdatedNotifications($app, $version): void {
$notification = $this->notificationManager->createNotification();
try {
- $notification->setApp('updatenotification')
+ $notification->setApp(Application::APP_NAME)
->setObject($app, $version);
- } catch (\InvalidArgumentException $e) {
+ } catch (\InvalidArgumentException) {
return;
}
$this->notificationManager->markProcessed($notification);
}
/**
- * @return string
- */
- protected function getChannel(): string {
- return \OC_Util::getChannel();
- }
-
- /**
* @param string $app
* @return string|false
*/
diff --git a/apps/updatenotification/lib/Command/Check.php b/apps/updatenotification/lib/Command/Check.php
index 7126a6b50b0..d93e4935012 100644
--- a/apps/updatenotification/lib/Command/Check.php
+++ b/apps/updatenotification/lib/Command/Check.php
@@ -3,28 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018, Tobia De Koninck (tobia@ledfan.be)
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author J0WI <J0WI@users.noreply.github.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Tobia De Koninck <LEDfan@users.noreply.github.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification\Command;
@@ -37,26 +17,12 @@ use Symfony\Component\Console\Output\OutputInterface;
class Check extends Command {
- /**
- * @var Installer $installer
- */
- private $installer;
-
- /**
- * @var AppManager $appManager
- */
- private $appManager;
-
- /**
- * @var UpdateChecker $updateChecker
- */
- private $updateChecker;
-
- public function __construct(AppManager $appManager, UpdateChecker $updateChecker, Installer $installer) {
+ public function __construct(
+ private AppManager $appManager,
+ private UpdateChecker $updateChecker,
+ private Installer $installer,
+ ) {
parent::__construct();
- $this->installer = $installer;
- $this->appManager = $appManager;
- $this->updateChecker = $updateChecker;
}
protected function configure(): void {
@@ -72,13 +38,13 @@ class Check extends Command {
// Server
$r = $this->updateChecker->getUpdateState();
if (isset($r['updateAvailable']) && $r['updateAvailable']) {
- $output->writeln($r['updateVersionString'] . ' is available. Get more information on how to update at '. $r['updateLink'] . '.');
+ $output->writeln($r['updateVersionString'] . ' is available. Get more information on how to update at ' . $r['updateLink'] . '.');
$updatesAvailableCount += 1;
}
// Apps
- $apps = $this->appManager->getInstalledApps();
+ $apps = $this->appManager->getEnabledApps();
foreach ($apps as $app) {
$update = $this->installer->isUpdateAvailable($app);
if ($update !== false) {
diff --git a/apps/updatenotification/lib/Controller/APIController.php b/apps/updatenotification/lib/Controller/APIController.php
index e2dd3684443..4360d814dd2 100644
--- a/apps/updatenotification/lib/Controller/APIController.php
+++ b/apps/updatenotification/lib/Controller/APIController.php
@@ -3,27 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification\Controller;
@@ -45,8 +26,7 @@ use OCP\L10N\IFactory;
*/
class APIController extends OCSController {
- /** @var string */
- protected $language;
+ protected ?string $language = null;
/**
* List of apps that were in the appstore but are now shipped and don't have
@@ -58,6 +38,9 @@ class APIController extends OCSController {
'bruteforcesettings' => 25,
'suspicious_login' => 25,
'twofactor_totp' => 25,
+ 'files_downloadlimit' => 29,
+ 'twofactor_nextcloud_notification' => 30,
+ 'app_api' => 30,
];
public function __construct(
@@ -78,7 +61,7 @@ class APIController extends OCSController {
*
* @param string $newVersion Server version to check updates for
*
- * @return DataResponse<Http::STATUS_OK, array{missing: UpdateNotificationApp[], available: UpdateNotificationApp[]}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{appstore_disabled: bool, already_on_latest?: bool}, array{}>
+ * @return DataResponse<Http::STATUS_OK, array{missing: list<UpdateNotificationApp>, available: list<UpdateNotificationApp>}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{appstore_disabled: bool, already_on_latest?: bool}, array{}>
*
* 200: Apps returned
* 404: New versions not found
@@ -91,7 +74,7 @@ class APIController extends OCSController {
}
// Get list of installed custom apps
- $installedApps = $this->appManager->getInstalledApps();
+ $installedApps = $this->appManager->getEnabledApps();
$installedApps = array_filter($installedApps, function ($app) {
try {
$this->appManager->getAppPath($app);
@@ -111,7 +94,7 @@ class APIController extends OCSController {
$this->appFetcher->setVersion($newVersion, 'future-apps.json', false);
// Apps available on the app store for that version
- $availableApps = array_map(static function (array $app) {
+ $availableApps = array_map(static function (array $app): string {
return $app['id'];
}, $this->appFetcher->get());
@@ -122,8 +105,6 @@ class APIController extends OCSController {
], Http::STATUS_NOT_FOUND);
}
- $this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser());
-
// Ignore apps that are deployed from git
$installedApps = array_filter($installedApps, function (string $appId) {
try {
@@ -155,28 +136,43 @@ class APIController extends OCSController {
*/
protected function getAppDetails(string $appId): array {
$app = $this->appManager->getAppInfo($appId, false, $this->language);
- /** @var ?string $name */
- $name = $app['name'];
+ $name = $app['name'] ?? $appId;
return [
'appId' => $appId,
- 'appName' => $name ?? $appId,
+ 'appName' => $name,
];
}
+ protected function getLanguage(): string {
+ if ($this->language === null) {
+ $this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser());
+ }
+ return $this->language;
+ }
+
/**
* Get changelog entry for an app
*
* @param string $appId App to search changelog entry for
* @param string|null $version The version to search the changelog entry for (defaults to the latest installed)
*
- * @return DataResponse<Http::STATUS_OK, array{appName: string, content: string, version: string}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{}, array{}>
+ * @return DataResponse<Http::STATUS_OK, array{appName: string, content: string, version: string}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{}, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{}, array{}>
*
* 200: Changelog entry returned
+ * 400: The `version` parameter is not a valid version format
* 404: No changelog found
*/
public function getAppChangelogEntry(string $appId, ?string $version = null): DataResponse {
$version = $version ?? $this->appManager->getAppVersion($appId);
- $changes = $this->manager->getChangelog($appId, $version);
+ // handle pre-release versions
+ $matches = [];
+ $result = preg_match('/^(\d+\.\d+(\.\d+)?)/', $version, $matches);
+ if ($result === false || $result === 0) {
+ return new DataResponse([], Http::STATUS_BAD_REQUEST);
+ }
+ $shortVersion = $matches[0];
+
+ $changes = $this->manager->getChangelog($appId, $shortVersion);
if ($changes === null) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php
index ae5893a00ab..26745948890 100644
--- a/apps/updatenotification/lib/Controller/AdminController.php
+++ b/apps/updatenotification/lib/Controller/AdminController.php
@@ -3,28 +3,9 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Vincent Petry <vincent@nextcloud.com>
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification\Controller;
@@ -56,8 +37,8 @@ class AdminController extends Controller {
parent::__construct($appName, $request);
}
- private function isUpdaterEnabled() {
- return !$this->config->getSystemValue('upgrade.disable-web', false);
+ private function isUpdaterEnabled(): bool {
+ return !$this->config->getSystemValueBool('upgrade.disable-web');
}
/**
diff --git a/apps/updatenotification/lib/Controller/ChangelogController.php b/apps/updatenotification/lib/Controller/ChangelogController.php
index b9ac61353fa..a274ed3d2b2 100644
--- a/apps/updatenotification/lib/Controller/ChangelogController.php
+++ b/apps/updatenotification/lib/Controller/ChangelogController.php
@@ -3,35 +3,21 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification\Controller;
use OCA\UpdateNotification\Manager;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\Attribute\NoAdminRequired;
+use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IRequest;
+use OCP\Util;
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
class ChangelogController extends Controller {
@@ -50,9 +36,9 @@ class ChangelogController extends Controller {
* This page is only used for clients not support showing the app changelog feature in-app and thus need to show it on a dedicated page.
* @param string $app App to show the changelog for
* @param string|null $version Version entry to show (defaults to latest installed)
- * @NoCSRFRequired
- * @NoAdminRequired
*/
+ #[NoAdminRequired]
+ #[NoCSRFRequired]
public function showChangelog(string $app, ?string $version = null): TemplateResponse {
$version = $version ?? $this->appManager->getAppVersion($app);
$appInfo = $this->appManager->getAppInfo($app) ?? [];
@@ -70,7 +56,7 @@ class ChangelogController extends Controller {
'text' => $changes,
]);
- \OCP\Util::addScript($this->appName, 'view-changelog-page');
+ Util::addScript($this->appName, 'view-changelog-page');
return new TemplateResponse($this->appName, 'empty');
}
}
diff --git a/apps/updatenotification/lib/Listener/AppUpdateEventListener.php b/apps/updatenotification/lib/Listener/AppUpdateEventListener.php
index 5ca801cc39a..49a2506d913 100644
--- a/apps/updatenotification/lib/Listener/AppUpdateEventListener.php
+++ b/apps/updatenotification/lib/Listener/AppUpdateEventListener.php
@@ -2,25 +2,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification\Listener;
diff --git a/apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php b/apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php
index 0691719040f..974734a76f4 100644
--- a/apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php
+++ b/apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php
@@ -2,25 +2,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification\Listener;
@@ -31,6 +14,7 @@ use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IAppConfig;
+use OCP\Util;
use Psr\Log\LoggerInterface;
/** @template-implements IEventListener<BeforeTemplateRenderedEvent> */
@@ -65,6 +49,6 @@ class BeforeTemplateRenderedEventListener implements IEventListener {
return;
}
- \OCP\Util::addInitScript(Application::APP_NAME, 'init');
+ Util::addInitScript(Application::APP_NAME, 'init');
}
}
diff --git a/apps/updatenotification/lib/Manager.php b/apps/updatenotification/lib/Manager.php
index c8038a0b995..ebc1c83a9b4 100644
--- a/apps/updatenotification/lib/Manager.php
+++ b/apps/updatenotification/lib/Manager.php
@@ -2,25 +2,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification;
@@ -51,7 +34,7 @@ class Manager {
* @param ?string $languageCode The language in which to query the changelog (defaults to current user language and fallsback to English)
* @return string|null Either the changelog entry or null if no changelog is found
*/
- public function getChangelog(string $appId, string $version, ?string $languageCode = null): string|null {
+ public function getChangelog(string $appId, string $version, ?string $languageCode = null): ?string {
if ($languageCode === null) {
$languageCode = $this->l10NFactory->getUserLanguage($this->currentUser);
}
@@ -72,7 +55,7 @@ class Manager {
* @param string $languageCode The language code to search
* @return string|null Either the file path or null if not found
*/
- public function getChangelogFile(string $appId, string $languageCode): string|null {
+ public function getChangelogFile(string $appId, string $languageCode): ?string {
try {
$appPath = $this->appManager->getAppPath($appId);
$files = ["CHANGELOG.$languageCode.md", 'CHANGELOG.en.md'];
@@ -90,10 +73,10 @@ class Manager {
/**
* Retrieve a log entry from the changelog
- * @param string $path The path to the changlog file
+ * @param string $path The path to the changelog file
* @param string $version The version to query (make sure to only pass in "{major}.{minor}(.{patch}" format)
*/
- protected function retrieveChangelogEntry(string $path, string $version): string|null {
+ protected function retrieveChangelogEntry(string $path, string $version): ?string {
$matches = [];
$content = file_get_contents($path);
if ($content === false) {
diff --git a/apps/updatenotification/lib/Migration/Version011901Date20240305120000.php b/apps/updatenotification/lib/Migration/Version011901Date20240305120000.php
deleted file mode 100644
index 283228fcb76..00000000000
--- a/apps/updatenotification/lib/Migration/Version011901Date20240305120000.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\UpdateNotification\Migration;
-
-use OCA\UpdateNotification\BackgroundJob\ResetToken;
-use OCP\BackgroundJob\IJobList;
-use OCP\Migration\IOutput;
-use OCP\Migration\SimpleMigrationStep;
-
-/**
- * Drop this with Nextcloud 30
- */
-class Version011901Date20240305120000 extends SimpleMigrationStep {
-
- public function __construct(
- private IJobList $joblist,
- ) {
- }
-
- public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {
- /**
- * Remove and replace the reset-updater-token background job
- * This class was renamed so it is now unknow but we still need to remove it
- * @psalm-suppress UndefinedClass, InvalidArgument
- */
- $hasOldResetToken = $this->joblist->has(\OCA\UpdateNotification\ResetTokenBackgroundJob::class, null);
- $hasNewResetToken = $this->joblist->has(ResetToken::class, null);
- if ($hasOldResetToken) {
- /**
- * @psalm-suppress UndefinedClass, InvalidArgument
- */
- $this->joblist->remove(\OCA\UpdateNotification\ResetTokenBackgroundJob::class);
- if (!$hasNewResetToken) {
- $this->joblist->add(ResetToken::class);
- }
- }
-
- /**
- * Remove the "has updates" background job, the new one is automatically started from the info.xml
- * @psalm-suppress UndefinedClass, InvalidArgument
- */
- if ($this->joblist->has(\OCA\UpdateNotification\Notification\BackgroundJob::class, null)) {
- /**
- * @psalm-suppress UndefinedClass, InvalidArgument
- */
- $this->joblist->remove(\OCA\UpdateNotification\Notification\BackgroundJob::class);
- }
- }
-}
diff --git a/apps/updatenotification/lib/Notification/AppUpdateNotifier.php b/apps/updatenotification/lib/Notification/AppUpdateNotifier.php
index 8fb8047aac7..353ca883aba 100644
--- a/apps/updatenotification/lib/Notification/AppUpdateNotifier.php
+++ b/apps/updatenotification/lib/Notification/AppUpdateNotifier.php
@@ -2,26 +2,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
- *
- * @author Ferdinand Thiessen <opensource@fthiessen.de>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification\Notification;
@@ -31,10 +13,12 @@ use OCP\App\IAppManager;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\L10N\IFactory;
+use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\IAction;
use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
+use OCP\Notification\UnknownNotificationException;
use Psr\Log\LoggerInterface;
class AppUpdateNotifier implements INotifier {
@@ -64,26 +48,27 @@ class AppUpdateNotifier implements INotifier {
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
- * @throws \InvalidArgumentException When the notification was not prepared by a notifier
+ * @throws UnknownNotificationException When the notification was not prepared by a notifier
+ * @throws AlreadyProcessedException When the app is no longer known
*/
public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== Application::APP_NAME) {
- throw new \InvalidArgumentException('Unknown app');
+ throw new UnknownNotificationException('Unknown app');
}
if ($notification->getSubject() !== 'app_updated') {
- throw new \InvalidArgumentException('Unknown subject');
+ throw new UnknownNotificationException('Unknown subject');
}
$appId = $notification->getSubjectParameters()[0];
$appInfo = $this->appManager->getAppInfo($appId, lang:$languageCode);
if ($appInfo === null) {
- throw new \InvalidArgumentException('App info not found');
+ throw new AlreadyProcessedException();
}
// Prepare translation factory for requested language
$l = $this->l10nFactory->get(Application::APP_NAME, $languageCode);
-
+
$icon = $this->appManager->getAppIcon($appId, true);
if ($icon === null) {
$icon = $this->urlGenerator->imagePath('core', 'actions/change.svg');
diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php
index e53ae542607..787675bd98d 100644
--- a/apps/updatenotification/lib/Notification/Notifier.php
+++ b/apps/updatenotification/lib/Notification/Notifier.php
@@ -3,31 +3,14 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification\Notification;
+use OCA\UpdateNotification\AppInfo\Application;
use OCP\App\IAppManager;
-use OCP\IConfig;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\IUser;
@@ -37,48 +20,27 @@ use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
-use OCP\Util;
+use OCP\Notification\UnknownNotificationException;
+use OCP\ServerVersion;
class Notifier implements INotifier {
- /** @var IURLGenerator */
- protected $url;
-
- /** @var IConfig */
- protected $config;
-
- /** @var IManager */
- protected $notificationManager;
-
- /** @var IFactory */
- protected $l10NFactory;
-
- /** @var IUserSession */
- protected $userSession;
-
- /** @var IGroupManager */
- protected $groupManager;
-
/** @var string[] */
protected $appVersions;
/**
* Notifier constructor.
- *
- * @param IURLGenerator $url
- * @param IConfig $config
- * @param IManager $notificationManager
- * @param IFactory $l10NFactory
- * @param IUserSession $userSession
- * @param IGroupManager $groupManager
*/
- public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) {
- $this->url = $url;
- $this->notificationManager = $notificationManager;
- $this->config = $config;
- $this->l10NFactory = $l10NFactory;
- $this->userSession = $userSession;
- $this->groupManager = $groupManager;
- $this->appVersions = $this->getAppVersions();
+ public function __construct(
+ protected IURLGenerator $url,
+ protected IAppConfig $appConfig,
+ protected IManager $notificationManager,
+ protected IFactory $l10NFactory,
+ protected IUserSession $userSession,
+ protected IGroupManager $groupManager,
+ protected IAppManager $appManager,
+ protected ServerVersion $serverVersion,
+ ) {
+ $this->appVersions = $this->appManager->getAppInstalledVersions();
}
/**
@@ -88,7 +50,7 @@ class Notifier implements INotifier {
* @since 17.0.0
*/
public function getID(): string {
- return 'updatenotification';
+ return Application::APP_NAME;
}
/**
@@ -98,32 +60,31 @@ class Notifier implements INotifier {
* @since 17.0.0
*/
public function getName(): string {
- return $this->l10NFactory->get('updatenotification')->t('Update notifications');
+ return $this->l10NFactory->get(Application::APP_NAME)->t('Update notifications');
}
/**
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
- * @throws \InvalidArgumentException When the notification was not prepared by a notifier
+ * @throws UnknownNotificationException When the notification was not prepared by a notifier
* @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
* @since 9.0.0
*/
public function prepare(INotification $notification, string $languageCode): INotification {
- if ($notification->getApp() !== 'updatenotification') {
- throw new \InvalidArgumentException('Unknown app id');
+ if ($notification->getApp() !== Application::APP_NAME) {
+ throw new UnknownNotificationException('Unknown app id');
}
if ($notification->getSubject() !== 'update_available' && $notification->getSubject() !== 'connection_error') {
- throw new \InvalidArgumentException('Unknown subject');
+ throw new UnknownNotificationException('Unknown subject');
}
- $l = $this->l10NFactory->get('updatenotification', $languageCode);
+ $l = $this->l10NFactory->get(Application::APP_NAME, $languageCode);
if ($notification->getSubject() === 'connection_error') {
- $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', '0');
+ $errors = $this->appConfig->getAppValueInt('update_check_errors', 0);
if ($errors === 0) {
- $this->notificationManager->markProcessed($notification);
- throw new \InvalidArgumentException('Update checked worked again');
+ throw new AlreadyProcessedException();
}
$notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors]))
@@ -166,7 +127,7 @@ class Notifier implements INotifier {
}
}
- $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg')));
+ $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_NAME, 'notification.svg')));
return $notification;
}
@@ -178,15 +139,12 @@ class Notifier implements INotifier {
* @param string $installedVersion
* @throws AlreadyProcessedException When the update is already installed
*/
- protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) {
+ protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion): void {
if (version_compare($notification->getObjectId(), $installedVersion, '<=')) {
throw new AlreadyProcessedException();
}
}
- /**
- * @return bool
- */
protected function isAdmin(): bool {
$user = $this->userSession->getUser();
@@ -198,14 +156,10 @@ class Notifier implements INotifier {
}
protected function getCoreVersions(): string {
- return implode('.', Util::getVersion());
- }
-
- protected function getAppVersions(): array {
- return \OC_App::getAppVersions();
+ return implode('.', $this->serverVersion->getVersion());
}
- protected function getAppInfo($appId, $languageCode) {
- return \OCP\Server::get(IAppManager::class)->getAppInfo($appId, false, $languageCode);
+ protected function getAppInfo(string $appId, ?string $languageCode): ?array {
+ return $this->appManager->getAppInfo($appId, false, $languageCode);
}
}
diff --git a/apps/updatenotification/lib/ResponseDefinitions.php b/apps/updatenotification/lib/ResponseDefinitions.php
index 24f0df8ae8d..754787ea2a7 100644
--- a/apps/updatenotification/lib/ResponseDefinitions.php
+++ b/apps/updatenotification/lib/ResponseDefinitions.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2023 Kate Döen <kate.doeen@nextcloud.com>
- *
- * @author Kate Döen <kate.doeen@nextcloud.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UpdateNotification;
diff --git a/apps/updatenotification/lib/Settings/Admin.php b/apps/updatenotification/lib/Settings/Admin.php
index b95f3dec196..22228f1bccc 100644
--- a/apps/updatenotification/lib/Settings/Admin.php
+++ b/apps/updatenotification/lib/Settings/Admin.php
@@ -3,33 +3,12 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification\Settings;
-use OC\User\Backend;
+use OCA\UpdateNotification\AppInfo\Application;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
@@ -39,10 +18,9 @@ use OCP\IDateTimeFormatter;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\L10N\IFactory;
+use OCP\ServerVersion;
use OCP\Settings\ISettings;
use OCP\Support\Subscription\IRegistry;
-use OCP\User\Backend\ICountUsersBackend;
-use OCP\Util;
use Psr\Log\LoggerInterface;
class Admin implements ISettings {
@@ -56,7 +34,8 @@ class Admin implements ISettings {
private IRegistry $subscriptionRegistry,
private IUserManager $userManager,
private LoggerInterface $logger,
- private IInitialState $initialState
+ private IInitialState $initialState,
+ private ServerVersion $serverVersion,
) {
}
@@ -70,14 +49,14 @@ class Admin implements ISettings {
'stable',
'production',
];
- $currentChannel = Util::getChannel();
+ $currentChannel = $this->serverVersion->getChannel();
if ($currentChannel === 'git') {
$channels[] = 'git';
}
$updateState = $this->updateChecker->getUpdateState();
- $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
+ $notifyGroups = $this->appConfig->getValueArray(Application::APP_NAME, 'notify_groups', ['admin']);
$defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';
$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
@@ -135,7 +114,7 @@ class Admin implements ISettings {
}
/**
- * @param list<string> $groupIds
+ * @param string[] $groupIds
* @return list<array{id: string, displayname: string}>
*/
protected function getSelectedGroups(array $groupIds): array {
@@ -153,7 +132,12 @@ class Admin implements ISettings {
return $result;
}
- public function getSection(): string {
+ public function getSection(): ?string {
+ if (!$this->config->getSystemValueBool('updatechecker', true)) {
+ // update checker is disabled so we do not show the section at all
+ return null;
+ }
+
return 'overview';
}
@@ -162,26 +146,6 @@ class Admin implements ISettings {
}
private function isWebUpdaterRecommended(): bool {
- return $this->getUserCount() < 100;
- }
-
- /**
- * @see https://github.com/nextcloud/server/blob/39494fbf794d982f6f6551c984e6ca4c4e947d01/lib/private/Support/Subscription/Registry.php#L188-L216 implementation reference
- */
- private function getUserCount(): int {
- $userCount = 0;
- $backends = $this->userManager->getBackends();
- foreach ($backends as $backend) {
- // TODO: change below to 'if ($backend instanceof ICountUsersBackend) {'
- if ($backend->implementsActions(Backend::COUNT_USERS)) {
- /** @var ICountUsersBackend $backend */
- $backendUsers = $backend->countUsers();
- if ($backendUsers !== false) {
- $userCount += $backendUsers;
- }
- }
- }
-
- return $userCount;
+ return (int)$this->userManager->countUsersTotal(100) < 100;
}
}
diff --git a/apps/updatenotification/lib/UpdateChecker.php b/apps/updatenotification/lib/UpdateChecker.php
index 40bf784e605..b206ba4a3e4 100644
--- a/apps/updatenotification/lib/UpdateChecker.php
+++ b/apps/updatenotification/lib/UpdateChecker.php
@@ -3,46 +3,23 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification;
use OC\Updater\ChangesCheck;
use OC\Updater\VersionCheck;
+use OCP\AppFramework\Services\IInitialState;
class UpdateChecker {
- /** @var VersionCheck */
- private $updater;
- /** @var ChangesCheck */
- private $changesCheck;
- /**
- * @param VersionCheck $updater
- */
- public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) {
- $this->updater = $updater;
- $this->changesCheck = $changesCheck;
+ public function __construct(
+ private VersionCheck $updater,
+ private ChangesCheck $changesCheck,
+ private IInitialState $initialState,
+ ) {
}
/**
@@ -79,13 +56,17 @@ class UpdateChecker {
}
/**
- * @param array $data
+ * Provide update information as initial state
*/
- public function populateJavaScriptVariables(array $data) {
- $data['array']['oc_updateState'] = json_encode([
- 'updateAvailable' => true,
- 'updateVersion' => $this->getUpdateState()['updateVersionString'],
- 'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
+ public function setInitialState(): void {
+ $updateState = $this->getUpdateState();
+ if (empty($updateState)) {
+ return;
+ }
+
+ $this->initialState->provideInitialState('updateState', [
+ 'updateVersion' => $updateState['updateVersionString'],
+ 'updateLink' => $updateState['updateLink'] ?? '',
]);
}
}