From 36c51bc4f160d8b18de64739e9ffccccee8a5b25 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Fri, 22 Feb 2019 15:45:55 +0100 Subject: [PATCH 1/3] Parse multiple navigation items Signed-off-by: Daniel Kesselberg --- lib/private/App/InfoParser.php | 16 ++++- lib/private/NavigationManager.php | 4 +- tests/data/app/navigation-one-item.json | 85 +++++++++++++++++++++++ tests/data/app/navigation-one-item.xml | 74 ++++++++++++++++++++ tests/data/app/navigation-two-item.json | 91 +++++++++++++++++++++++++ tests/data/app/navigation-two-item.xml | 80 ++++++++++++++++++++++ tests/lib/App/InfoParserTest.php | 16 +++-- tests/lib/NavigationManagerTest.php | 20 ++++-- 8 files changed, 369 insertions(+), 17 deletions(-) create mode 100644 tests/data/app/navigation-one-item.json create mode 100644 tests/data/app/navigation-one-item.xml create mode 100644 tests/data/app/navigation-two-item.json create mode 100644 tests/data/app/navigation-two-item.xml diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php index e0ed63fc784ad..ef96156dfed27 100644 --- a/lib/private/App/InfoParser.php +++ b/lib/private/App/InfoParser.php @@ -52,7 +52,7 @@ public function parse($file) { return null; } - if(!is_null($this->cache)) { + if ($this->cache !== null) { $fileCacheKey = $file . filemtime($file); if ($cachedValue = $this->cache->get($fileCacheKey)) { return json_decode($cachedValue, true); @@ -205,12 +205,24 @@ public function parse($file) { $array['settings']['personal-section'] = [$array['settings']['personal-section']]; } - if(!is_null($this->cache)) { + if (isset($array['navigations']['navigation']) && $this->isNavigationItem($array['navigations']['navigation'])) { + $array['navigations']['navigation'] = [$array['navigations']['navigation']]; + } + + if ($this->cache !== null) { $this->cache->set($fileCacheKey, json_encode($array)); } return $array; } + /** + * @param $data + * @return bool + */ + private function isNavigationItem($data): bool { + return isset($data['name'], $data['route']); + } + /** * @param \SimpleXMLElement $xml * @return array diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index 1874cd0e4ff96..a1d3d252af106 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -271,10 +271,10 @@ private function init() { // load plugins and collections from info.xml $info = $this->appManager->getAppInfo($app); - if (empty($info['navigations'])) { + if (!isset($info['navigations']['navigation'])) { continue; } - foreach ($info['navigations'] as $nav) { + foreach ($info['navigations']['navigation'] as $nav) { if (!isset($nav['name'])) { continue; } diff --git a/tests/data/app/navigation-one-item.json b/tests/data/app/navigation-one-item.json new file mode 100644 index 0000000000000..c9002da6b0dba --- /dev/null +++ b/tests/data/app/navigation-one-item.json @@ -0,0 +1,85 @@ +{ + "id": "activity", + "name": "Activity", + "summary": "This application enables users to view actions related to their files in Nextcloud.", + "description": "\n\t\tThis application enables users to view actions related to their files in Nextcloud.\n\t\tOnce enabled, users will see a new icon \u201cActivity\u201d in their apps menu.\n\t\tWhen clicked, a new page appears for users to track the activity related to files \u2013 from new files, to deleted files, move, rename, updates and shared activity.\n\t\tThe user can configure their individual activity settings in their personal menu.\n\t\tThis sets the type of activity to record, as well as whether to the user sees their own activities,\n\t\twhether these are only available online, and whether they get an email digest on a regular basis.\n\t\tMore information is available in the Activity documentation.\n\t", + "version": "2.9.0", + "licence": "agpl", + "author": [ + "Frank Karlitschek", + "Joas Schilling" + ], + "default_enable": "", + "types": [ + "filesystem" + ], + "documentation": { + "admin": "https:\/\/docs.nextcloud.org\/server\/14\/admin_manual\/configuration_server\/activity_configuration.html" + }, + "category": [ + "monitoring", + "social" + ], + "website": "https:\/\/github.com\/nextcloud\/activity\/", + "bugs": "https:\/\/github.com\/nextcloud\/activity\/issues", + "repository": "https:\/\/github.com\/nextcloud\/activity.git", + "dependencies": { + "nextcloud": { + "@attributes": { + "min-version": "16", + "max-version": "16" + } + } + }, + "background-jobs": [ + "OCA\\Activity\\BackgroundJob\\EmailNotification", + "OCA\\Activity\\BackgroundJob\\ExpireActivities" + ], + "commands": { + "command": "OCA\\Activity\\Command\\SendEmails" + }, + "settings": { + "admin": [ + "OCA\\Activity\\Settings\\Admin" + ], + "admin-section": [ + "OCA\\Activity\\Settings\\AdminSection" + ], + "personal": [ + "OCA\\Activity\\Settings\\Personal" + ], + "personal-section": [ + "OCA\\Activity\\Settings\\PersonalSection" + ] + }, + "activity": { + "filters": [ + "OCA\\Activity\\Filter\\AllFilter", + "OCA\\Activity\\Filter\\SelfFilter", + "OCA\\Activity\\Filter\\ByFilter" + ], + "settings": [], + "providers": [] + }, + "navigations": { + "navigation": [ + { + "name": "Activity", + "route": "activity.Activities.showList", + "icon": "activity.svg", + "order": "1" + } + ] + }, + "info": [], + "remote": [], + "public": [], + "repair-steps": { + "install": [], + "pre-migration": [], + "post-migration": [], + "live-migration": [], + "uninstall": [] + }, + "two-factor-providers": [] +} \ No newline at end of file diff --git a/tests/data/app/navigation-one-item.xml b/tests/data/app/navigation-one-item.xml new file mode 100644 index 0000000000000..a03e5c8ffbf11 --- /dev/null +++ b/tests/data/app/navigation-one-item.xml @@ -0,0 +1,74 @@ + + + activity + Activity + This application enables users to view actions related to their files in Nextcloud. + + This application enables users to view actions related to their files in Nextcloud. + Once enabled, users will see a new icon “Activity” in their apps menu. + When clicked, a new page appears for users to track the activity related to files – from new files, to deleted files, move, rename, updates and shared activity. + The user can configure their individual activity settings in their personal menu. + This sets the type of activity to record, as well as whether to the user sees their own activities, + whether these are only available online, and whether they get an email digest on a regular basis. + More information is available in the Activity documentation. + + + 2.9.0 + agpl + Frank Karlitschek + Joas Schilling + + + + + + + + https://docs.nextcloud.org/server/14/admin_manual/configuration_server/activity_configuration.html + + + monitoring + social + + https://github.com/nextcloud/activity/ + https://github.com/nextcloud/activity/issues + https://github.com/nextcloud/activity.git + + + + + + + OCA\Activity\BackgroundJob\EmailNotification + OCA\Activity\BackgroundJob\ExpireActivities + + + + OCA\Activity\Command\SendEmails + + + + OCA\Activity\Settings\Admin + OCA\Activity\Settings\AdminSection + OCA\Activity\Settings\Personal + OCA\Activity\Settings\PersonalSection + + + + + OCA\Activity\Filter\AllFilter + OCA\Activity\Filter\SelfFilter + OCA\Activity\Filter\ByFilter + + + + + + Activity + activity.Activities.showList + activity.svg + 1 + + + diff --git a/tests/data/app/navigation-two-item.json b/tests/data/app/navigation-two-item.json new file mode 100644 index 0000000000000..a7579217238fd --- /dev/null +++ b/tests/data/app/navigation-two-item.json @@ -0,0 +1,91 @@ +{ + "id": "activity", + "name": "Activity", + "summary": "This application enables users to view actions related to their files in Nextcloud.", + "description": "\n\t\tThis application enables users to view actions related to their files in Nextcloud.\n\t\tOnce enabled, users will see a new icon \u201cActivity\u201d in their apps menu.\n\t\tWhen clicked, a new page appears for users to track the activity related to files \u2013 from new files, to deleted files, move, rename, updates and shared activity.\n\t\tThe user can configure their individual activity settings in their personal menu.\n\t\tThis sets the type of activity to record, as well as whether to the user sees their own activities,\n\t\twhether these are only available online, and whether they get an email digest on a regular basis.\n\t\tMore information is available in the Activity documentation.\n\t", + "version": "2.9.0", + "licence": "agpl", + "author": [ + "Frank Karlitschek", + "Joas Schilling" + ], + "default_enable": "", + "types": [ + "filesystem" + ], + "documentation": { + "admin": "https:\/\/docs.nextcloud.org\/server\/14\/admin_manual\/configuration_server\/activity_configuration.html" + }, + "category": [ + "monitoring", + "social" + ], + "website": "https:\/\/github.com\/nextcloud\/activity\/", + "bugs": "https:\/\/github.com\/nextcloud\/activity\/issues", + "repository": "https:\/\/github.com\/nextcloud\/activity.git", + "dependencies": { + "nextcloud": { + "@attributes": { + "min-version": "16", + "max-version": "16" + } + } + }, + "background-jobs": [ + "OCA\\Activity\\BackgroundJob\\EmailNotification", + "OCA\\Activity\\BackgroundJob\\ExpireActivities" + ], + "commands": { + "command": "OCA\\Activity\\Command\\SendEmails" + }, + "settings": { + "admin": [ + "OCA\\Activity\\Settings\\Admin" + ], + "admin-section": [ + "OCA\\Activity\\Settings\\AdminSection" + ], + "personal": [ + "OCA\\Activity\\Settings\\Personal" + ], + "personal-section": [ + "OCA\\Activity\\Settings\\PersonalSection" + ] + }, + "activity": { + "filters": [ + "OCA\\Activity\\Filter\\AllFilter", + "OCA\\Activity\\Filter\\SelfFilter", + "OCA\\Activity\\Filter\\ByFilter" + ], + "settings": [], + "providers": [] + }, + "navigations": { + "navigation": [ + { + "name": "Activity", + "route": "activity.Activities.showList", + "icon": "activity.svg", + "order": "1" + }, + { + "name": "Activity-Test", + "route": "activity.Activities.showList", + "icon": "activity.svg", + "order": "2" + } + ] + }, + "info": [], + "remote": [], + "public": [], + "repair-steps": { + "install": [], + "pre-migration": [], + "post-migration": [], + "live-migration": [], + "uninstall": [] + }, + "two-factor-providers": [] +} \ No newline at end of file diff --git a/tests/data/app/navigation-two-item.xml b/tests/data/app/navigation-two-item.xml new file mode 100644 index 0000000000000..fba60a2871d8f --- /dev/null +++ b/tests/data/app/navigation-two-item.xml @@ -0,0 +1,80 @@ + + + activity + Activity + This application enables users to view actions related to their files in Nextcloud. + + This application enables users to view actions related to their files in Nextcloud. + Once enabled, users will see a new icon “Activity” in their apps menu. + When clicked, a new page appears for users to track the activity related to files – from new files, to deleted files, move, rename, updates and shared activity. + The user can configure their individual activity settings in their personal menu. + This sets the type of activity to record, as well as whether to the user sees their own activities, + whether these are only available online, and whether they get an email digest on a regular basis. + More information is available in the Activity documentation. + + + 2.9.0 + agpl + Frank Karlitschek + Joas Schilling + + + + + + + + https://docs.nextcloud.org/server/14/admin_manual/configuration_server/activity_configuration.html + + + monitoring + social + + https://github.com/nextcloud/activity/ + https://github.com/nextcloud/activity/issues + https://github.com/nextcloud/activity.git + + + + + + + OCA\Activity\BackgroundJob\EmailNotification + OCA\Activity\BackgroundJob\ExpireActivities + + + + OCA\Activity\Command\SendEmails + + + + OCA\Activity\Settings\Admin + OCA\Activity\Settings\AdminSection + OCA\Activity\Settings\Personal + OCA\Activity\Settings\PersonalSection + + + + + OCA\Activity\Filter\AllFilter + OCA\Activity\Filter\SelfFilter + OCA\Activity\Filter\ByFilter + + + + + + Activity + activity.Activities.showList + activity.svg + 1 + + + Activity-Test + activity.Activities.showList + activity.svg + 2 + + + diff --git a/tests/lib/App/InfoParserTest.php b/tests/lib/App/InfoParserTest.php index 5a3847a71e8e6..4fa8b2a06a5f7 100644 --- a/tests/lib/App/InfoParserTest.php +++ b/tests/lib/App/InfoParserTest.php @@ -47,12 +47,14 @@ public function testParsingValidXmlWithCache($expectedJson, $xmlFile) { $this->parserTest($expectedJson, $xmlFile, self::$cache); } - function providesInfoXml() { - return array( - array('expected-info.json', 'valid-info.xml'), - array(null, 'invalid-info.xml'), - array('expected-info.json', 'valid-info.xml'), - array(null, 'invalid-info.xml'), - ); + public function providesInfoXml(): array { + return [ + ['expected-info.json', 'valid-info.xml'], + [null, 'invalid-info.xml'], + ['expected-info.json', 'valid-info.xml'], + [null, 'invalid-info.xml'], + ['navigation-one-item.json', 'navigation-one-item.xml'], + ['navigation-two-item.json', 'navigation-two-item.xml'], + ]; } } diff --git a/tests/lib/NavigationManagerTest.php b/tests/lib/NavigationManagerTest.php index f552bd2eeed06..31efbce929c52 100644 --- a/tests/lib/NavigationManagerTest.php +++ b/tests/lib/NavigationManagerTest.php @@ -296,7 +296,9 @@ public function providesNavigationConfig() { ['logout' => $defaults['logout']] ), ['navigations' => [ - ['route' => 'test.page.index', 'name' => 'Test'] + 'navigation' => [ + ['route' => 'test.page.index', 'name' => 'Test'] + ] ]] ], 'minimalistic-settings' => [ @@ -315,9 +317,11 @@ public function providesNavigationConfig() { ['logout' => $defaults['logout']] ), ['navigations' => [ - ['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings'] - ] - ]], + 'navigation' => [ + ['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings'] + ], + ]] + ], 'admin' => [ array_merge( ['settings' => $defaults['settings']], @@ -335,7 +339,9 @@ public function providesNavigationConfig() { ['logout' => $defaults['logout']] ), ['navigations' => [ - ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test'] + 'navigation' => [ + ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test'] + ], ]], true ], @@ -346,7 +352,9 @@ public function providesNavigationConfig() { ['logout' => $defaults['logout']] ), ['navigations' => [ - ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index'] + 'navigation' => [ + ['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index'] + ], ]], true ], From b578fd855e6b3e7b4b2d1b02357605d65fa0c32b Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Mon, 25 Feb 2019 14:49:51 +0100 Subject: [PATCH 2/3] Generate id for navigation item Signed-off-by: Daniel Kesselberg --- lib/private/NavigationManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index a1d3d252af106..2c41fbd88c28b 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -274,7 +274,7 @@ private function init() { if (!isset($info['navigations']['navigation'])) { continue; } - foreach ($info['navigations']['navigation'] as $nav) { + foreach ($info['navigations']['navigation'] as $key => $nav) { if (!isset($nav['name'])) { continue; } @@ -286,7 +286,7 @@ private function init() { continue; } $l = $this->l10nFac->get($app); - $id = isset($nav['id']) ? $nav['id'] : $app; + $id = $nav['id'] ?? $app . ($key === 0 ? '' : $key); $order = isset($nav['order']) ? $nav['order'] : 100; $type = isset($nav['type']) ? $nav['type'] : 'link'; $route = $nav['route'] !== '' ? $this->urlGenerator->linkToRoute($nav['route']) : ''; From df3d5e85095620f84e3146ae6ce558e68d0b137e Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Mon, 25 Feb 2019 14:52:14 +0100 Subject: [PATCH 3/3] two item => two items Signed-off-by: Daniel Kesselberg --- .../app/{navigation-two-item.json => navigation-two-items.json} | 0 .../app/{navigation-two-item.xml => navigation-two-items.xml} | 0 tests/lib/App/InfoParserTest.php | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename tests/data/app/{navigation-two-item.json => navigation-two-items.json} (100%) rename tests/data/app/{navigation-two-item.xml => navigation-two-items.xml} (100%) diff --git a/tests/data/app/navigation-two-item.json b/tests/data/app/navigation-two-items.json similarity index 100% rename from tests/data/app/navigation-two-item.json rename to tests/data/app/navigation-two-items.json diff --git a/tests/data/app/navigation-two-item.xml b/tests/data/app/navigation-two-items.xml similarity index 100% rename from tests/data/app/navigation-two-item.xml rename to tests/data/app/navigation-two-items.xml diff --git a/tests/lib/App/InfoParserTest.php b/tests/lib/App/InfoParserTest.php index 4fa8b2a06a5f7..b72a869e02c63 100644 --- a/tests/lib/App/InfoParserTest.php +++ b/tests/lib/App/InfoParserTest.php @@ -54,7 +54,7 @@ public function providesInfoXml(): array { ['expected-info.json', 'valid-info.xml'], [null, 'invalid-info.xml'], ['navigation-one-item.json', 'navigation-one-item.xml'], - ['navigation-two-item.json', 'navigation-two-item.xml'], + ['navigation-two-items.json', 'navigation-two-items.xml'], ]; } }