diff options
Diffstat (limited to 'apps/updatenotification/lib/Controller')
3 files changed, 42 insertions, 79 deletions
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'); } } |