aboutsummaryrefslogtreecommitdiffstats
path: root/apps/updatenotification/lib/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'apps/updatenotification/lib/Controller')
-rw-r--r--apps/updatenotification/lib/Controller/APIController.php39
-rw-r--r--apps/updatenotification/lib/Controller/AdminController.php5
-rw-r--r--apps/updatenotification/lib/Controller/ChangelogController.php9
3 files changed, 36 insertions, 17 deletions
diff --git a/apps/updatenotification/lib/Controller/APIController.php b/apps/updatenotification/lib/Controller/APIController.php
index 6a91b90139b..4360d814dd2 100644
--- a/apps/updatenotification/lib/Controller/APIController.php
+++ b/apps/updatenotification/lib/Controller/APIController.php
@@ -26,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
@@ -39,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(
@@ -59,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
@@ -72,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);
@@ -92,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());
@@ -103,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 {
@@ -136,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 6e7f9935d93..26745948890 100644
--- a/apps/updatenotification/lib/Controller/AdminController.php
+++ b/apps/updatenotification/lib/Controller/AdminController.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\UpdateNotification\Controller;
@@ -36,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 b3ce77b11d9..a274ed3d2b2 100644
--- a/apps/updatenotification/lib/Controller/ChangelogController.php
+++ b/apps/updatenotification/lib/Controller/ChangelogController.php
@@ -11,10 +11,13 @@ 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 {
@@ -33,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) ?? [];
@@ -53,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');
}
}