diff --git a/changelog/unreleased/36399 b/changelog/unreleased/36399 new file mode 100644 index 000000000000..e53bdaa7f2d0 --- /dev/null +++ b/changelog/unreleased/36399 @@ -0,0 +1,10 @@ +Bugfix: Inform the admin if they enable an enterprise app without valid key + +Previously no message was displayed but the app was not enabled. + +Now, when the admin tries to enable an enterprise app when the enterprise key +is invalid, the message "cannot be enabled because of invalid enterprise key" +is displayed. + +https://github.com/owncloud/core/issues/36351 +https://github.com/owncloud/core/pull/36399 diff --git a/core/Command/App/Enable.php b/core/Command/App/Enable.php index dc396329bcda..e1d9ecdc6fcb 100644 --- a/core/Command/App/Enable.php +++ b/core/Command/App/Enable.php @@ -24,6 +24,7 @@ namespace OC\Core\Command\App; +use OCP\IConfig; use OCP\App\IAppManager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -36,12 +37,17 @@ class Enable extends Command { /** @var IAppManager */ protected $manager; + /** @var IConfig */ + protected $config; + /** * @param IAppManager $manager + * @param IConfig $config */ - public function __construct(IAppManager $manager) { + public function __construct(IAppManager $manager, IConfig $config) { parent::__construct(); $this->manager = $manager; + $this->config = $config; } protected function configure() { @@ -70,6 +76,16 @@ protected function execute(InputInterface $input, OutputInterface $output) { return 1; } + if (\OC_App::isEnabled('enterprise_key')) { + /* @phan-suppress-next-line PhanUndeclaredClassMethod */ + $key = new \OCA\Enterprise_Key\EnterpriseKey(false, $this->config); + /* @phan-suppress-next-line PhanUndeclaredClassMethod */ + if ($key && !$key->isValid()) { + $output->writeln($appId . ' cannot be enabled because of invalid enterprise key'); + return 1; + } + } + $groups = $input->getOption('groups'); if (empty($groups)) { \OC_App::enable($appId); diff --git a/core/register_command.php b/core/register_command.php index 132c039c654f..c7006bb50897 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -59,7 +59,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); - $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager())); + $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getConfig())); $application->add(new OC\Core\Command\App\GetPath()); $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); diff --git a/phpstan.neon b/phpstan.neon index f5f9a0c06276..2b5b5b37ed3e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -34,6 +34,9 @@ parameters: - '#Undefined variable: \$vendor#' - '#Undefined variable: \$baseuri#' - '#Instantiated class OC_Theme not found.#' + - + message: '#Instantiated class OCA\\Enterprise_Key\\EnterpriseKey not found.#' + path: core/Command/App/Enable.php # errors below are to be addressed by own pull requests - non trivial changes required - '#OCA\\DAV\\Connector\\Sabre\\ObjectTree::__construct\(\) does not call parent constructor from Sabre\\DAV\\Tree.#' - '#OC\\Files\\ObjectStore\\NoopScanner::__construct\(\) does not call parent constructor from OC\\Files\\Cache\\Scanner.#' diff --git a/tests/Core/Command/Apps/AppsEnableTest.php b/tests/Core/Command/Apps/AppsEnableTest.php index ca24d07d90cb..681a5256a695 100644 --- a/tests/Core/Command/Apps/AppsEnableTest.php +++ b/tests/Core/Command/Apps/AppsEnableTest.php @@ -38,7 +38,10 @@ class AppsEnableTest extends TestCase { public function setUp(): void { parent::setUp(); - $command = new Enable(\OC::$server->getAppManager()); + $command = new Enable( + \OC::$server->getAppManager(), + \OC::$server->getConfig() + ); $this->commandTester = new CommandTester($command); }