Skip to content

Commit

Permalink
Merge pull request #5617 from nextcloud/backport-5615-fix-navigation-…
Browse files Browse the repository at this point in the history
…entries-for-group-restricted-apps

[stable12] Don't load navigation entries of restricted apps
  • Loading branch information
MorrisJobke committed Jul 7, 2017
2 parents a1f3f17 + 33252cd commit 36e3f3c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 13 deletions.
13 changes: 12 additions & 1 deletion lib/private/NavigationManager.php
Expand Up @@ -228,7 +228,18 @@ private function init() {
if ($this->appManager === 'null') {
return;
}
foreach ($this->appManager->getInstalledApps() as $app) {

if ($this->userSession->isLoggedIn()) {
$apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
} else {
$apps = $this->appManager->getInstalledApps();
}

foreach ($apps as $app) {
if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
continue;
}

// load plugins and collections from info.xml
$info = $this->appManager->getAppInfo($app);
if (empty($info['navigations'])) {
Expand Down
75 changes: 63 additions & 12 deletions tests/lib/NavigationManagerTest.php
Expand Up @@ -13,7 +13,9 @@
namespace Test;

use OC\App\AppManager;
use OC\Group\Manager;
use OC\NavigationManager;
use OC\SubAdmin;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
Expand Down Expand Up @@ -46,7 +48,7 @@ protected function setUp() {
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10nFac = $this->createMock(IFactory::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->groupManager = $this->createMock(Manager::class);
$this->config = $this->createMock(IConfig::class);
$this->navigationManager = new NavigationManager(
$this->appManager,
Expand Down Expand Up @@ -207,56 +209,105 @@ public function testWithAppManager($expected, $navigation, $isAdmin = false) {
return vsprintf($text, $parameters);
});

$this->appManager->expects($this->once())->method('getInstalledApps')->willReturn(['test']);
$this->appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($navigation);
$this->l10nFac->expects($this->exactly(count($expected) + 1))->method('get')->willReturn($l);
$this->l10nFac->expects($this->any())->method('get')->willReturn($l);
$this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function($appName, $file) {
return "/apps/$appName/img/$file";
});
$this->urlGenerator->expects($this->exactly(count($expected)))->method('linkToRoute')->willReturnCallback(function() {
$this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function() {
return "/apps/test/";
});
$user = $this->createMock(IUser::class);
$user->expects($this->any())->method('getUID')->willReturn('user001');
$this->userSession->expects($this->any())->method('getUser')->willReturn($user);
$this->userSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
$this->appManager->expects($this->once())
->method('getEnabledAppsForUser')
->with($user)
->willReturn(['test']);
$this->groupManager->expects($this->any())->method('isAdmin')->willReturn($isAdmin);
$subadmin = $this->createMock(SubAdmin::class);
$subadmin->expects($this->any())->method('isSubAdmin')->with($user)->willReturn(false);
$this->groupManager->expects($this->any())->method('getSubAdmin')->willReturn($subadmin);

$this->navigationManager->clear();
$entries = $this->navigationManager->getAll('all');
$this->assertEquals($expected, $entries);
}

public function providesNavigationConfig() {
$apps = [
[
'id' => 'core_apps',
'order' => 3,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/apps.svg',
'name' => 'Apps',
'active' => false,
'type' => 'settings',
]
];
$admin = [
[
'id' => 'admin',
'order' => 2,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/admin.svg',
'name' => 'Admin',
'active' => false,
'type' => 'settings',
]
];
$defaults = [
[
'id' => 'personal',
'order' => 1,
'href' => '/apps/test/',
'icon' => '/apps/settings/img/personal.svg',
'name' => 'Personal',
'active' => false,
'type' => 'settings',
],
[
'id' => 'logout',
'order' => 99999,
'href' => null,
'icon' => '/apps/core/img/actions/logout.svg',
'name' => 'Log out',
'active' => false,
'type' => 'settings',
],
];
return [
'minimalistic' => [[[
'minimalistic' => [array_merge($defaults, [[
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
]], ['navigations' => [['route' => 'test.page.index', 'name' => 'Test']]]],
'minimalistic-settings' => [[[
]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test']]]],
'minimalistic-settings' => [array_merge($defaults, [[
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'settings',
]], ['navigations' => [['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings']]]],
'no admin' => [[[
]]), ['navigations' => [['route' => 'test.page.index', 'name' => 'Test', 'type' => 'settings']]]],
'admin' => [array_merge($apps, $defaults, $admin, [[
'id' => 'test',
'order' => 100,
'href' => '/apps/test/',
'icon' => '/apps/test/img/app.svg',
'name' => 'Test',
'active' => false,
'type' => 'link',
]], ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]], true],
'no name' => [[], ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']]], true],
'admin' => [[], ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]]]
]]), ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]], true],
'no name' => [array_merge($apps, $defaults, $admin), ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index']]], true],
'no admin' => [$defaults, ['navigations' => [['@attributes' => ['role' => 'admin'], 'route' => 'test.page.index', 'name' => 'Test']]]]
];
}
}

0 comments on commit 36e3f3c

Please sign in to comment.