From f7a2959da1c9d9c3ea12c141fe86a47331d65f48 Mon Sep 17 00:00:00 2001 From: Nextcloud bot Date: Sat, 16 Nov 2024 01:18:49 +0000 Subject: [PATCH] chore: migrate some routes to the new format Signed-off-by: Sean Molenaar --- CHANGELOG.md | 1 + appinfo/routes.php | 38 ------------------------- l10n/sk.js | 4 +++ l10n/sk.json | 4 +++ lib/Controller/ApiController.php | 1 + lib/Controller/Controller.php | 2 +- lib/Controller/ExportController.php | 4 ++- lib/Controller/FeedController.php | 10 +++++++ lib/Controller/FolderController.php | 8 ++++++ lib/Controller/ItemController.php | 8 ++++++ lib/Controller/PageController.php | 5 ++++ lib/Controller/UtilityApiController.php | 1 + 12 files changed, 46 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 456ef245dc..a9e369cd48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the ## [25.x.x] ### Changed - If title of feed is empty during creation set hostname of feed as title (#2872) +- Migrate routes to new location in the controllers ### Fixed - Feed without Title returned by DB causes exception (#2872) diff --git a/appinfo/routes.php b/appinfo/routes.php index 3f5b8eb23f..999ab20ebf 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -15,52 +15,14 @@ return ['routes' => [ // page -['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], -['name' => 'page#settings', 'url' => '/settings', 'verb' => 'GET'], -['name' => 'page#update_settings', 'url' => '/settings', 'verb' => 'PUT'], ['name' => 'page#manifest', 'url' => '/manifest.webapp', 'verb' => 'GET'], -['name' => 'page#explore', 'url' => '/explore/feeds.{lang}.json', 'verb' => 'GET'], // admin ['name' => 'admin#update', 'url' => '/admin', 'verb' => 'PUT'], ['name' => 'admin#migrate', 'url' => '/admin/migrate', 'verb' => 'POST'], -// folders -['name' => 'folder#index', 'url' => '/folders', 'verb' => 'GET'], -['name' => 'folder#create', 'url' => '/folders', 'verb' => 'POST'], -['name' => 'folder#delete', 'url' => '/folders/{folderId}', 'verb' => 'DELETE'], -['name' => 'folder#restore', 'url' => '/folders/{folderId}/restore', 'verb' => 'POST'], -['name' => 'folder#rename', 'url' => '/folders/{folderId}/rename', 'verb' => 'POST'], -['name' => 'folder#read', 'url' => '/folders/{folderId}/read', 'verb' => 'POST'], -['name' => 'folder#open', 'url' => '/folders/{folderId}/open', 'verb' => 'POST'], - -// feeds -['name' => 'feed#index', 'url' => '/feeds', 'verb' => 'GET'], -['name' => 'feed#create', 'url' => '/feeds', 'verb' => 'POST'], -['name' => 'feed#delete', 'url' => '/feeds/{feedId}', 'verb' => 'DELETE'], -['name' => 'feed#restore', 'url' => '/feeds/{feedId}/restore', 'verb' => 'POST'], -['name' => 'feed#read', 'url' => '/feeds/{feedId}/read', 'verb' => 'POST'], -['name' => 'feed#update', 'url' => '/feeds/{feedId}/update', 'verb' => 'POST'], -['name' => 'feed#active', 'url' => '/feeds/active', 'verb' => 'GET'], -['name' => 'feed#import', 'url' => '/feeds/import/articles', 'verb' => 'POST'], -['name' => 'feed#patch', 'url' => '/feeds/{feedId}', 'verb' => 'PATCH'], - -// items -['name' => 'item#index', 'url' => '/items', 'verb' => 'GET'], -['name' => 'item#new_items', 'url' => '/items/new', 'verb' => 'GET'], -['name' => 'item#readAll', 'url' => '/items/read', 'verb' => 'POST'], -['name' => 'item#read', 'url' => '/items/{itemId}/read', 'verb' => 'POST'], -['name' => 'item#read_multiple', 'url' => '/items/read/multiple', 'verb' => 'POST'], -['name' => 'item#star', 'url' => '/items/{feedId}/{guidHash}/star', 'verb' => 'POST'], -['name' => 'item#share', 'url' => '/items/{itemId}/share/{shareRecipientId}', 'verb' => 'POST'], - -// export -['name' => 'export#opml', 'url' => '/export/opml', 'verb' => 'GET'], -['name' => 'export#articles', 'url' => '/export/articles', 'verb' => 'GET'], - // general API ['name' => 'api#index', 'url' => '/api', 'verb' => 'GET'], - ['name' => 'utility_api#preflighted_cors', 'url' => '/api/{apiVersion}/{path}', 'verb' => 'OPTIONS', 'requirements' => ['apiVersion' => 'v(1-[23]|2)', 'path' => '.+']], ['name' => 'utility_api#version', 'url' => '/api/{apiVersion}/version', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v(1-[23]|2)']], diff --git a/l10n/sk.js b/l10n/sk.js index 798380eaa4..02e7d6782d 100644 --- a/l10n/sk.js +++ b/l10n/sk.js @@ -48,6 +48,7 @@ OC.L10N.register( "Interval in seconds in which the feeds will be updated." : "Interval v sekundách, počas ktorého sa kanály aktualizujú.", "No article selected" : "Žiadny článok nebol vybraný.", "Please select an article from the list..." : "Vyberte prosím článok zo zoznamu...", + "Move feed to folder" : "Presunúť kanál do priečinka", "Move" : "Presunúť", "User Name" : "Úžívateľské meno", "Share" : "Zdieľať", @@ -56,12 +57,14 @@ OC.L10N.register( "Mark read" : "Označ ako prečítané", "All articles" : "Všetky články", "Starred" : "S hviezdičkou", + "Has feeds with errors!" : "Má kanály s chybami!", "Explore" : "Preskúmať", "Settings" : "Nastavenia", "Keyboard shortcuts" : "Klávesové skratky", "Disable mark read through scrolling" : "Vypnúť označovanie ako prečítané pri posune", "Show all articles" : "Zobraziť všetky články", "Reverse ordering (oldest on top)" : "Opačné zoradenie (od najstarších)", + "Disable automatic refresh" : "Zakázať automatické obnovenie", "Are you sure you want to mark all read?" : "Ste si istý, že chcete označiť všetko ako prečítané?", "Rename Folder" : "Premenovať Priečinok", "Are you sure you want to delete?" : "Naozaj chcete vymazať?", @@ -111,6 +114,7 @@ OC.L10N.register( "Load next folder" : "Načítať ďalší priečinok", "Scroll to active navigation entry" : "Posunte na aktiváciu položky menu", "Shift" : "Shift", + "Mark current articles feed/folder as read" : "Označiť aktuálny kanál/priečinok s článkami ako prečítaný", "All Articles" : "Všetky články", "No feeds found to add" : "Žiadne kanály na pridanie neboli nájdené.", "Subscribe to" : "Odobrať z", diff --git a/l10n/sk.json b/l10n/sk.json index 8ad4d4bb3d..b9c10d8a66 100644 --- a/l10n/sk.json +++ b/l10n/sk.json @@ -46,6 +46,7 @@ "Interval in seconds in which the feeds will be updated." : "Interval v sekundách, počas ktorého sa kanály aktualizujú.", "No article selected" : "Žiadny článok nebol vybraný.", "Please select an article from the list..." : "Vyberte prosím článok zo zoznamu...", + "Move feed to folder" : "Presunúť kanál do priečinka", "Move" : "Presunúť", "User Name" : "Úžívateľské meno", "Share" : "Zdieľať", @@ -54,12 +55,14 @@ "Mark read" : "Označ ako prečítané", "All articles" : "Všetky články", "Starred" : "S hviezdičkou", + "Has feeds with errors!" : "Má kanály s chybami!", "Explore" : "Preskúmať", "Settings" : "Nastavenia", "Keyboard shortcuts" : "Klávesové skratky", "Disable mark read through scrolling" : "Vypnúť označovanie ako prečítané pri posune", "Show all articles" : "Zobraziť všetky články", "Reverse ordering (oldest on top)" : "Opačné zoradenie (od najstarších)", + "Disable automatic refresh" : "Zakázať automatické obnovenie", "Are you sure you want to mark all read?" : "Ste si istý, že chcete označiť všetko ako prečítané?", "Rename Folder" : "Premenovať Priečinok", "Are you sure you want to delete?" : "Naozaj chcete vymazať?", @@ -109,6 +112,7 @@ "Load next folder" : "Načítať ďalší priečinok", "Scroll to active navigation entry" : "Posunte na aktiváciu položky menu", "Shift" : "Shift", + "Mark current articles feed/folder as read" : "Označiť aktuálny kanál/priečinok s článkami ako prečítaný", "All Articles" : "Všetky články", "No feeds found to add" : "Žiadne kanály na pridanie neboli nájdené.", "Subscribe to" : "Odobrať z", diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index a7f5de78b3..1bff5e5e4f 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -26,6 +26,7 @@ use OCP\AppFramework\Http\Attribute\CORS; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\Attribute\PublicPage; +use OCP\AppFramework\Http\Attribute\ApiRoute; /** * Class ApiController diff --git a/lib/Controller/Controller.php b/lib/Controller/Controller.php index 2249578aa6..267317979f 100644 --- a/lib/Controller/Controller.php +++ b/lib/Controller/Controller.php @@ -56,7 +56,7 @@ protected function getUser(): ?IUser /** * @return string */ - protected function getUserId() + protected function getUserId(): string { return $this->getUser()->getUID(); } diff --git a/lib/Controller/ExportController.php b/lib/Controller/ExportController.php index ad5e3f4f27..cfb62287e9 100644 --- a/lib/Controller/ExportController.php +++ b/lib/Controller/ExportController.php @@ -23,7 +23,7 @@ use OCP\IUserSession; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; -use OCP\AppFramework\Http\Attribute\CORS; +use OCP\AppFramework\Http\Attribute\FrontpageRoute; /** * Class ExportController @@ -47,6 +47,7 @@ public function __construct( #[NoCSRFRequired] #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/export/opml')] public function opml(): DataDownloadResponse { $date = date('Y-m-d'); @@ -61,6 +62,7 @@ public function opml(): DataDownloadResponse #[NoCSRFRequired] #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/export/articles')] public function articles(): JSONResponse { $feeds = $this->feedService->findAllForUser($this->getUserId()); diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index e08ae9eac5..27b7c48ece 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -24,6 +24,7 @@ use OCP\IConfig; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\NoAdminRequired; +use OCP\AppFramework\Http\Attribute\FrontpageRoute; use OCA\News\Db\ListType; use OCP\IUserSession; @@ -46,6 +47,7 @@ public function __construct( #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/feeds')] public function index(): array { @@ -72,6 +74,7 @@ public function index(): array #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/feeds/active')] public function active(): array { $feedId = (int) $this->settings->getUserValue( @@ -126,6 +129,7 @@ public function active(): array * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/feeds')] public function create( string $url, ?int $parentFolderId, @@ -180,6 +184,7 @@ public function create( * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'DELETE', url: '/feeds/{feedId}')] public function delete(int $feedId) { try { @@ -200,6 +205,7 @@ public function delete(int $feedId) * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/feeds/{feedId}/update')] public function update(int $feedId) { try { @@ -227,6 +233,7 @@ public function update(int $feedId) * @return array */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/feeds/import/articles')] public function import(array $json): array { $feed = $this->importService->importArticles($this->getUserId(), $json); @@ -249,6 +256,7 @@ public function import(array $json): array * @return array */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/feeds/{feedId}/read')] public function read(int $feedId, int $highestItemId): array { $this->feedService->read($this->getUserId(), $feedId, $highestItemId); @@ -270,6 +278,7 @@ public function read(int $feedId, int $highestItemId): array * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/feeds/{feedId}/restore')] public function restore(int $feedId) { try { @@ -295,6 +304,7 @@ public function restore(int $feedId) * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'PATCH', url: '/feeds/{feedId}')] public function patch( int $feedId, ?bool $pinned = null, diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index dac8aa54bd..928a074ce7 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -18,6 +18,7 @@ use \OCP\IRequest; use \OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\NoAdminRequired; +use OCP\AppFramework\Http\Attribute\FrontpageRoute; use \OCA\News\Service\FolderServiceV2; use \OCA\News\Service\Exceptions\ServiceNotFoundException; @@ -43,6 +44,7 @@ public function __construct( * @psalm-return array{folders: array} */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/folders')] public function index(): array { $folders = $this->folderService->findAllForUser($this->getUserId()); @@ -57,6 +59,7 @@ public function index(): array * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/open')] public function open(?int $folderId, bool $open) { $folderId = $folderId === 0 ? null : $folderId; @@ -78,6 +81,7 @@ public function open(?int $folderId, bool $open) * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/folders')] public function create(string $folderName, ?int $parent = null) { $this->folderService->purgeDeleted($this->getUserId(), time() - 600); @@ -93,6 +97,7 @@ public function create(string $folderName, ?int $parent = null) * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'DELETE', url: '/folders/{folderId}')] public function delete(?int $folderId) { if (is_null($folderId)) { @@ -117,6 +122,7 @@ public function delete(?int $folderId) * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/rename')] public function rename(?int $folderId, string $folderName) { if (is_null($folderId)) { @@ -143,6 +149,7 @@ public function rename(?int $folderId, string $folderName) * @throws ServiceNotFoundException */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/read')] public function read(?int $folderId, int $maxItemId): void { $folderId = $folderId === 0 ? null : $folderId; @@ -157,6 +164,7 @@ public function read(?int $folderId, int $maxItemId): void * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/folders/{folderId}/restore')] public function restore(?int $folderId) { $folderId = $folderId === 0 ? null : $folderId; diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php index e87ffaf5b9..03cdc9e947 100644 --- a/lib/Controller/ItemController.php +++ b/lib/Controller/ItemController.php @@ -21,6 +21,7 @@ use \OCP\IConfig; use \OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\NoAdminRequired; +use OCP\AppFramework\Http\Attribute\FrontpageRoute; use \OCA\News\Service\Exceptions\ServiceException; use \OCA\News\Service\Exceptions\ServiceNotFoundException; @@ -64,6 +65,7 @@ public function __construct( * @return array */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/items')] public function index( int $type = 3, int $id = 0, @@ -184,6 +186,7 @@ public function index( * @return array */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/items/new')] public function newItems(int $type, int $id, $lastModified = 0): array { $showAll = $this->settings->getUserValue( @@ -245,6 +248,7 @@ public function newItems(int $type, int $id, $lastModified = 0): array * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/items/{feedId}/{guidHash}/star')] public function star(int $feedId, string $guidHash, bool $isStarred) { try { @@ -269,6 +273,7 @@ public function star(int $feedId, string $guidHash, bool $isStarred) * @return array|JSONResponse */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/items/{itemId}/read')] public function read(int $itemId, $isRead = true) { try { @@ -287,6 +292,7 @@ public function read(int $itemId, $isRead = true) * @return array */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/items/read')] public function readAll(int $highestItemId): array { $this->itemService->readAll($this->getUserId(), $highestItemId); @@ -300,6 +306,7 @@ public function readAll(int $highestItemId): array * @return void */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/items/read/multiple')] public function readMultiple(array $itemIds): void { foreach ($itemIds as $id) { @@ -317,6 +324,7 @@ public function readMultiple(array $itemIds): void * @param string $shareRecipientId User to share the item with */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'POST', url: '/items/{itemId}/share/{shareRecipientId}')] public function share(int $itemId, string $shareRecipientId) { try { diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 8462d3ba51..f8a42e1730 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -27,6 +27,7 @@ use OCP\AppFramework\Services\IInitialState; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; +use OCP\AppFramework\Http\Attribute\FrontpageRoute; use OCA\News\Service\StatusService; use OCA\News\Explore\RecommendedSites; @@ -53,6 +54,7 @@ public function __construct( #[NoCSRFRequired] #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/')] public function index(): TemplateResponse { $status = $this->statusService->getStatus(); @@ -110,6 +112,7 @@ public function index(): TemplateResponse } #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/settings')] public function settings(): array { $settings = [ @@ -159,6 +162,7 @@ public function settings(): array * @param bool $disableRefresh */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'PUT', url: '/settings')] public function updateSettings( bool $showAll, bool $compact, @@ -193,6 +197,7 @@ public function updateSettings( * @return Http\JSONResponse|array */ #[NoAdminRequired] + #[FrontpageRoute(verb: 'GET', url: '/explore/feeds.{lang}.json')] public function explore(string $lang) { $this->config->setUserValue( diff --git a/lib/Controller/UtilityApiController.php b/lib/Controller/UtilityApiController.php index 48fe2daabd..62bf93b5eb 100644 --- a/lib/Controller/UtilityApiController.php +++ b/lib/Controller/UtilityApiController.php @@ -22,6 +22,7 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\Attribute\CORS; +use OCP\AppFramework\Http\Attribute\ApiRoute; use \OCA\News\Service\StatusService;