Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable15] Parse multiple navigation items #14416

Merged
merged 3 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/private/App/InfoParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/private/NavigationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 $key => $nav) {
if (!isset($nav['name'])) {
continue;
}
Expand All @@ -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']) : '';
Expand Down
85 changes: 85 additions & 0 deletions tests/data/app/navigation-one-item.json
Original file line number Diff line number Diff line change
@@ -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": []
}
74 changes: 74 additions & 0 deletions tests/data/app/navigation-one-item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>activity</id>
<name>Activity</name>
<summary>This application enables users to view actions related to their files in Nextcloud.</summary>
<description>
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.
</description>

<version>2.9.0</version>
<licence>agpl</licence>
<author>Frank Karlitschek</author>
<author>Joas Schilling</author>

<default_enable/>
<types>
<filesystem/>
</types>

<documentation>
<admin>https://docs.nextcloud.org/server/14/admin_manual/configuration_server/activity_configuration.html</admin>
</documentation>

<category>monitoring</category>
<category>social</category>

<website>https://github.com/nextcloud/activity/</website>
<bugs>https://github.com/nextcloud/activity/issues</bugs>
<repository>https://github.com/nextcloud/activity.git</repository>

<dependencies>
<nextcloud min-version="16" max-version="16"/>
</dependencies>

<background-jobs>
<job>OCA\Activity\BackgroundJob\EmailNotification</job>
<job>OCA\Activity\BackgroundJob\ExpireActivities</job>
</background-jobs>

<commands>
<command>OCA\Activity\Command\SendEmails</command>
</commands>

<settings>
<admin>OCA\Activity\Settings\Admin</admin>
<admin-section>OCA\Activity\Settings\AdminSection</admin-section>
<personal>OCA\Activity\Settings\Personal</personal>
<personal-section>OCA\Activity\Settings\PersonalSection</personal-section>
</settings>

<activity>
<filters>
<filter>OCA\Activity\Filter\AllFilter</filter>
<filter>OCA\Activity\Filter\SelfFilter</filter>
<filter>OCA\Activity\Filter\ByFilter</filter>
</filters>
</activity>

<navigations>
<navigation>
<name>Activity</name>
<route>activity.Activities.showList</route>
<icon>activity.svg</icon>
<order>1</order>
</navigation>
</navigations>
</info>
91 changes: 91 additions & 0 deletions tests/data/app/navigation-two-items.json
Original file line number Diff line number Diff line change
@@ -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": []
}
80 changes: 80 additions & 0 deletions tests/data/app/navigation-two-items.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>activity</id>
<name>Activity</name>
<summary>This application enables users to view actions related to their files in Nextcloud.</summary>
<description>
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.
</description>

<version>2.9.0</version>
<licence>agpl</licence>
<author>Frank Karlitschek</author>
<author>Joas Schilling</author>

<default_enable/>
<types>
<filesystem/>
</types>

<documentation>
<admin>https://docs.nextcloud.org/server/14/admin_manual/configuration_server/activity_configuration.html</admin>
</documentation>

<category>monitoring</category>
<category>social</category>

<website>https://github.com/nextcloud/activity/</website>
<bugs>https://github.com/nextcloud/activity/issues</bugs>
<repository>https://github.com/nextcloud/activity.git</repository>

<dependencies>
<nextcloud min-version="16" max-version="16"/>
</dependencies>

<background-jobs>
<job>OCA\Activity\BackgroundJob\EmailNotification</job>
<job>OCA\Activity\BackgroundJob\ExpireActivities</job>
</background-jobs>

<commands>
<command>OCA\Activity\Command\SendEmails</command>
</commands>

<settings>
<admin>OCA\Activity\Settings\Admin</admin>
<admin-section>OCA\Activity\Settings\AdminSection</admin-section>
<personal>OCA\Activity\Settings\Personal</personal>
<personal-section>OCA\Activity\Settings\PersonalSection</personal-section>
</settings>

<activity>
<filters>
<filter>OCA\Activity\Filter\AllFilter</filter>
<filter>OCA\Activity\Filter\SelfFilter</filter>
<filter>OCA\Activity\Filter\ByFilter</filter>
</filters>
</activity>

<navigations>
<navigation>
<name>Activity</name>
<route>activity.Activities.showList</route>
<icon>activity.svg</icon>
<order>1</order>
</navigation>
<navigation>
<name>Activity-Test</name>
<route>activity.Activities.showList</route>
<icon>activity.svg</icon>
<order>2</order>
</navigation>
</navigations>
</info>
Loading