Skip to content
Open
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
10 changes: 9 additions & 1 deletion core/Command/App/ListApps.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int

sort($enabledApps);
foreach ($enabledApps as $app) {
$apps['enabled'][$app] = $versions[$app] ?? true;
$groups = $this->appManager->getAppRestriction($app);
if (!empty($groups)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!empty($groups)) {
if ($groups !== []) {

$apps['enabled'][$app] = [
'version' => $versions[$app] ?? true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard fail if the version is missing, because it means something is seriously wrong.

'groups' => $groups,
];
} else {
$apps['enabled'][$app] = $versions[$app] ?? true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have the same format as above.

}
}
}

Expand Down
67 changes: 67 additions & 0 deletions tests/Core/Command/Apps/ListAppsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace Tests\Core\Command\Config;

use OC\Core\Command\App\ListApps;
use OCP\App\IAppManager;
use OCP\Server;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;

/**
* Class ListAppsTest
*/
#[\PHPUnit\Framework\Attributes\Group('DB')]
class ListAppsTest extends TestCase {
/** @var CommandTester */
private $commandTester;

/** @var IAppManager */
private $appManager;

#[\Override]
protected function setUp(): void {
parent::setUp();

$this->appManager = Server::get(IAppManager::class);
$command = new ListApps($this->appManager);
$this->commandTester = new CommandTester($command);

$this->appManager->disableApp('updatenotification');
}

#[\Override]
protected function tearDown(): void {
$this->appManager->disableApp('updatenotification');
parent::tearDown();
}

public function testEnabledAppWithoutGroupRestrictionHasNoGroupsKey(): void {
$this->appManager->enableApp('updatenotification');

$this->commandTester->execute(['--output' => 'json']);

$apps = json_decode($this->commandTester->getDisplay(), true);

$this->assertArrayHasKey('updatenotification', $apps['enabled']);
$this->assertIsNotArray($apps['enabled']['updatenotification']);
}

public function testEnabledAppWithGroupRestrictionShowsGroups(): void {
$this->appManager->enableAppForGroups('updatenotification', ['admin']);

$this->commandTester->execute(['--output' => 'json']);

$apps = json_decode($this->commandTester->getDisplay(), true);

$this->assertArrayHasKey('updatenotification', $apps['enabled']);
$this->assertIsArray($apps['enabled']['updatenotification']);
$this->assertSame(['admin'], $apps['enabled']['updatenotification']['groups']);
}
}
Loading