diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-03-02 21:33:02 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2024-03-07 22:40:30 +0100 |
commit | fa14daf9680bc0697376d966af4c4c79fa294934 (patch) | |
tree | 8a9d340ca9ef1c0e74edea4f414b3dec269df85a /apps/updatenotification/lib/Controller | |
parent | d9d3448e237abbf6ba676cacb985ef43cf6d4b41 (diff) | |
download | nextcloud-server-fa14daf9680bc0697376d966af4c4c79fa294934.tar.gz nextcloud-server-fa14daf9680bc0697376d966af4c4c79fa294934.zip |
feat(updatenotification): Add notification for users when apps are updated
* Open app changelog dialog when available (webui)
* Fallback to open changelog page for mobile clients
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/updatenotification/lib/Controller')
-rw-r--r-- | apps/updatenotification/lib/Controller/APIController.php | 74 | ||||
-rw-r--r-- | apps/updatenotification/lib/Controller/ChangelogController.php | 76 |
2 files changed, 123 insertions, 27 deletions
diff --git a/apps/updatenotification/lib/Controller/APIController.php b/apps/updatenotification/lib/Controller/APIController.php index d684b69024f..e2dd3684443 100644 --- a/apps/updatenotification/lib/Controller/APIController.php +++ b/apps/updatenotification/lib/Controller/APIController.php @@ -7,6 +7,7 @@ declare(strict_types=1); * * @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 * @@ -27,6 +28,7 @@ declare(strict_types=1); namespace OCA\UpdateNotification\Controller; use OC\App\AppStore\Fetcher\AppFetcher; +use OCA\UpdateNotification\Manager; use OCA\UpdateNotification\ResponseDefinitions; use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; @@ -43,21 +45,6 @@ use OCP\L10N\IFactory; */ class APIController extends OCSController { - /** @var IConfig */ - protected $config; - - /** @var IAppManager */ - protected $appManager; - - /** @var AppFetcher */ - protected $appFetcher; - - /** @var IFactory */ - protected $l10nFactory; - - /** @var IUserSession */ - protected $userSession; - /** @var string */ protected $language; @@ -73,20 +60,17 @@ class APIController extends OCSController { 'twofactor_totp' => 25, ]; - public function __construct(string $appName, + public function __construct( + string $appName, IRequest $request, - IConfig $config, - IAppManager $appManager, - AppFetcher $appFetcher, - IFactory $l10nFactory, - IUserSession $userSession) { + protected IConfig $config, + protected IAppManager $appManager, + protected AppFetcher $appFetcher, + protected IFactory $l10nFactory, + protected IUserSession $userSession, + protected Manager $manager, + ) { parent::__construct($appName, $request); - - $this->config = $config; - $this->appManager = $appManager; - $this->appFetcher = $appFetcher; - $this->l10nFactory = $l10nFactory; - $this->userSession = $userSession; } /** @@ -178,4 +162,40 @@ class APIController extends OCSController { 'appName' => $name ?? $appId, ]; } + + /** + * 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{}> + * + * 200: Changelog entry returned + * 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); + + if ($changes === null) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + + // Remove version headline + /** @var string[] */ + $changes = explode("\n", $changes, 2); + $changes = trim(end($changes)); + + // Get app info for localized app name + $info = $this->appManager->getAppInfo($appId) ?? []; + /** @var string */ + $appName = $info['name'] ?? $appId; + + return new DataResponse([ + 'appName' => $appName, + 'content' => $changes, + 'version' => $version, + ]); + } } diff --git a/apps/updatenotification/lib/Controller/ChangelogController.php b/apps/updatenotification/lib/Controller/ChangelogController.php new file mode 100644 index 00000000000..b9ac61353fa --- /dev/null +++ b/apps/updatenotification/lib/Controller/ChangelogController.php @@ -0,0 +1,76 @@ +<?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\Controller; + +use OCA\UpdateNotification\Manager; +use OCP\App\IAppManager; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\Attribute\OpenAPI; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\Services\IInitialState; +use OCP\IRequest; + +#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] +class ChangelogController extends Controller { + + public function __construct( + string $appName, + IRequest $request, + private Manager $manager, + private IAppManager $appManager, + private IInitialState $initialState, + ) { + parent::__construct($appName, $request); + } + + /** + * 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 + */ + public function showChangelog(string $app, ?string $version = null): TemplateResponse { + $version = $version ?? $this->appManager->getAppVersion($app); + $appInfo = $this->appManager->getAppInfo($app) ?? []; + $appName = $appInfo['name'] ?? $app; + + $changes = $this->manager->getChangelog($app, $version) ?? ''; + // Remove version headline + /** @var string[] */ + $changes = explode("\n", $changes, 2); + $changes = trim(end($changes)); + + $this->initialState->provideInitialState('changelog', [ + 'appName' => $appName, + 'appVersion' => $version, + 'text' => $changes, + ]); + + \OCP\Util::addScript($this->appName, 'view-changelog-page'); + return new TemplateResponse($this->appName, 'empty'); + } +} |