Browse Source
fix: Replace isInstalled calls with isEnabledForAnyone or isEnabledForUser
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/49648/head
Côme Chilliet
11 months ago
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
22 changed files with
35 additions and
39 deletions
-
apps/comments/lib/Activity/Listener.php
-
apps/comments/tests/Unit/Activity/ListenerTest.php
-
apps/dav/lib/Connector/Sabre/Directory.php
-
apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php
-
apps/files_sharing/lib/Controller/ShareAPIController.php
-
apps/settings/lib/Controller/AppSettingsController.php
-
apps/systemtags/lib/Activity/Listener.php
-
apps/webhook_listeners/lib/BackgroundJobs/WebhookCall.php
-
core/Command/App/Disable.php
-
core/Command/App/Enable.php
-
core/Command/App/Install.php
-
core/Command/App/ListApps.php
-
core/Command/App/Remove.php
-
core/Command/Db/Migrations/GenerateMetadataCommand.php
-
lib/base.php
-
lib/private/Migration/MetadataManager.php
-
lib/private/Server.php
-
lib/private/TaskProcessing/Manager.php
-
public.php
-
remote.php
-
tests/Core/Command/Apps/AppsEnableTest.php
-
tests/lib/App/AppManagerTest.php
|
|
|
@ -31,7 +31,7 @@ class Listener { |
|
|
|
public function commentEvent(CommentsEvent $event): void { |
|
|
|
if ($event->getComment()->getObjectType() !== 'files' |
|
|
|
|| $event->getEvent() !== CommentsEvent::EVENT_ADD |
|
|
|
|| !$this->appManager->isInstalled('activity')) { |
|
|
|
|| !$this->appManager->isEnabledForAnyone('activity')) { |
|
|
|
// Comment not for file, not adding a comment or no activity-app enabled (save the energy)
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
@ -67,7 +67,7 @@ class ListenerTest extends TestCase { |
|
|
|
|
|
|
|
public function testCommentEvent(): void { |
|
|
|
$this->appManager->expects($this->any()) |
|
|
|
->method('isInstalled') |
|
|
|
->method('isEnabledForAnyone') |
|
|
|
->with('activity') |
|
|
|
->willReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
@ -220,7 +220,7 @@ class Directory extends Node implements \Sabre\DAV\ICollection, \Sabre\DAV\IQuot |
|
|
|
if (!$this->info->isReadable()) { |
|
|
|
// return 403 instead of 404 because a 404 would make
|
|
|
|
// the caller believe that the collection itself does not exist
|
|
|
|
if (Server::get(IAppManager::class)->isInstalled('files_accesscontrol')) { |
|
|
|
if (Server::get(IAppManager::class)->isEnabledForAnyone('files_accesscontrol')) { |
|
|
|
throw new Forbidden('No read permissions. This might be caused by files_accesscontrol, check your configured rules'); |
|
|
|
} else { |
|
|
|
throw new Forbidden('No read permissions'); |
|
|
|
|
|
|
|
@ -746,7 +746,7 @@ class CloudFederationProviderFiles implements ISignedCloudFederationProvider { |
|
|
|
|
|
|
|
public function getUserDisplayName(string $userId): string { |
|
|
|
// check if gss is enabled and available
|
|
|
|
if (!$this->appManager->isInstalled('globalsiteselector') |
|
|
|
if (!$this->appManager->isEnabledForAnyone('globalsiteselector') |
|
|
|
|| !class_exists('\OCA\GlobalSiteSelector\Service\SlaveService')) { |
|
|
|
return ''; |
|
|
|
} |
|
|
|
|
|
|
|
@ -408,7 +408,7 @@ class ShareAPIController extends OCSController { |
|
|
|
private function retrieveFederatedDisplayName(array $userIds, bool $cacheOnly = false): array { |
|
|
|
// check if gss is enabled and available
|
|
|
|
if (count($userIds) === 0 |
|
|
|
|| !$this->appManager->isInstalled('globalsiteselector') |
|
|
|
|| !$this->appManager->isEnabledForAnyone('globalsiteselector') |
|
|
|
|| !class_exists('\OCA\GlobalSiteSelector\Service\SlaveService')) { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
@ -92,7 +92,7 @@ class AppSettingsController extends Controller { |
|
|
|
$this->initialState->provideInitialState('appstoreDeveloperDocs', $this->urlGenerator->linkToDocs('developer-manual')); |
|
|
|
$this->initialState->provideInitialState('appstoreUpdateCount', count($this->getAppsWithUpdates())); |
|
|
|
|
|
|
|
if ($this->appManager->isInstalled('app_api')) { |
|
|
|
if ($this->appManager->isEnabledForAnyone('app_api')) { |
|
|
|
try { |
|
|
|
Server::get(\OCA\AppAPI\Service\ExAppsPageService::class)->provideAppApiState($this->initialState); |
|
|
|
} catch (\Psr\Container\NotFoundExceptionInterface|\Psr\Container\ContainerExceptionInterface $e) { |
|
|
|
@ -440,7 +440,7 @@ class AppSettingsController extends Controller { |
|
|
|
} |
|
|
|
|
|
|
|
$currentVersion = ''; |
|
|
|
if ($this->appManager->isInstalled($app['id'])) { |
|
|
|
if ($this->appManager->isEnabledForAnyone($app['id'])) { |
|
|
|
$currentVersion = $this->appManager->getAppVersion($app['id']); |
|
|
|
} else { |
|
|
|
$currentVersion = $app['releases'][0]['version']; |
|
|
|
|
|
|
|
@ -109,7 +109,7 @@ class Listener { |
|
|
|
$tagIds = $event->getTags(); |
|
|
|
if ($event->getObjectType() !== 'files' || empty($tagIds) |
|
|
|
|| !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
|
|
|
|| !$this->appManager->isInstalled('activity')) { |
|
|
|
|| !$this->appManager->isEnabledForAnyone('activity')) { |
|
|
|
// System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy)
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
@ -60,7 +60,7 @@ class WebhookCall extends QueuedJob { |
|
|
|
$exAppId = $webhookListener->getAppId(); |
|
|
|
if ($exAppId !== null && str_starts_with($webhookUri, '/')) { |
|
|
|
// ExApp is awaiting a direct request to itself using AppAPI
|
|
|
|
if (!$this->appManager->isInstalled('app_api')) { |
|
|
|
if (!$this->appManager->isEnabledForAnyone('app_api')) { |
|
|
|
throw new RuntimeException('AppAPI is disabled or not installed.'); |
|
|
|
} |
|
|
|
try { |
|
|
|
|
|
|
|
@ -44,7 +44,7 @@ class Disable extends Command implements CompletionAwareInterface { |
|
|
|
} |
|
|
|
|
|
|
|
private function disableApp(string $appId, OutputInterface $output): void { |
|
|
|
if ($this->appManager->isInstalled($appId) === false) { |
|
|
|
if ($this->appManager->isEnabledForAnyone($appId) === false) { |
|
|
|
$output->writeln('No such app enabled: ' . $appId); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
@ -27,6 +27,7 @@ class Enable extends Command implements CompletionAwareInterface { |
|
|
|
public function __construct( |
|
|
|
protected IAppManager $appManager, |
|
|
|
protected IGroupManager $groupManager, |
|
|
|
private Installer $installer, |
|
|
|
) { |
|
|
|
parent::__construct(); |
|
|
|
} |
|
|
|
@ -77,20 +78,17 @@ class Enable extends Command implements CompletionAwareInterface { |
|
|
|
return $group->getDisplayName(); |
|
|
|
}, $groupIds); |
|
|
|
|
|
|
|
if ($this->appManager->isInstalled($appId) && $groupIds === []) { |
|
|
|
if ($this->appManager->isEnabledForUser($appId) && $groupIds === []) { |
|
|
|
$output->writeln($appId . ' already enabled'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
/** @var Installer $installer */ |
|
|
|
$installer = \OC::$server->query(Installer::class); |
|
|
|
|
|
|
|
if ($installer->isDownloaded($appId) === false) { |
|
|
|
$installer->downloadApp($appId); |
|
|
|
if ($this->installer->isDownloaded($appId) === false) { |
|
|
|
$this->installer->downloadApp($appId); |
|
|
|
} |
|
|
|
|
|
|
|
$installer->installApp($appId, $forceEnable); |
|
|
|
$this->installer->installApp($appId, $forceEnable); |
|
|
|
$appVersion = $this->appManager->getAppVersion($appId); |
|
|
|
|
|
|
|
if ($groupIds === []) { |
|
|
|
|
|
|
|
@ -58,7 +58,7 @@ class Install extends Command { |
|
|
|
$appId = $input->getArgument('app-id'); |
|
|
|
$forceEnable = (bool)$input->getOption('force'); |
|
|
|
|
|
|
|
if ($this->appManager->isInstalled($appId)) { |
|
|
|
if ($this->appManager->isEnabledForAnyone($appId)) { |
|
|
|
$output->writeln($appId . ' already installed'); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
@ -65,7 +65,7 @@ class ListApps extends Base { |
|
|
|
if ($shippedFilter !== null && $this->manager->isShipped($app) !== $shippedFilter) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if ($this->manager->isInstalled($app)) { |
|
|
|
if ($this->manager->isEnabledForAnyone($app)) { |
|
|
|
$enabledApps[] = $app; |
|
|
|
} else { |
|
|
|
$disabledApps[] = $app; |
|
|
|
|
|
|
|
@ -50,7 +50,7 @@ class Remove extends Command implements CompletionAwareInterface { |
|
|
|
$appId = $input->getArgument('app-id'); |
|
|
|
|
|
|
|
// Check if the app is enabled
|
|
|
|
if (!$this->manager->isInstalled($appId)) { |
|
|
|
if (!$this->manager->isEnabledForAnyone($appId)) { |
|
|
|
$output->writeln($appId . ' is not enabled'); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
@ -68,15 +68,11 @@ class GenerateMetadataCommand extends Command { |
|
|
|
$metadata = []; |
|
|
|
foreach ($allApps as $appId) { |
|
|
|
// We need to load app before being able to extract Migrations
|
|
|
|
// If app was not enabled before, we will disable it afterward.
|
|
|
|
$alreadyLoaded = $this->appManager->isInstalled($appId); |
|
|
|
$alreadyLoaded = $this->appManager->isAppLoaded($appId); |
|
|
|
if (!$alreadyLoaded) { |
|
|
|
$this->appManager->loadApp($appId); |
|
|
|
} |
|
|
|
$metadata[$appId] = $this->metadataManager->extractMigrationAttributes($appId); |
|
|
|
if (!$alreadyLoaded) { |
|
|
|
$this->appManager->disableApp($appId); |
|
|
|
} |
|
|
|
} |
|
|
|
return $metadata; |
|
|
|
} |
|
|
|
|
|
|
|
@ -255,7 +255,7 @@ class OC { |
|
|
|
$tooBig = false; |
|
|
|
if (!$disableWebUpdater) { |
|
|
|
$apps = Server::get(\OCP\App\IAppManager::class); |
|
|
|
if ($apps->isInstalled('user_ldap')) { |
|
|
|
if ($apps->isEnabledForAnyone('user_ldap')) { |
|
|
|
$qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
|
|
|
|
|
|
$result = $qb->select($qb->func()->count('*', 'user_count')) |
|
|
|
@ -266,7 +266,7 @@ class OC { |
|
|
|
|
|
|
|
$tooBig = ($row['user_count'] > 50); |
|
|
|
} |
|
|
|
if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
|
|
if (!$tooBig && $apps->isEnabledForAnyone('user_saml')) { |
|
|
|
$qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
|
|
|
|
|
|
$result = $qb->select($qb->func()->count('*', 'user_count')) |
|
|
|
@ -1130,11 +1130,11 @@ class OC { |
|
|
|
} |
|
|
|
|
|
|
|
protected static function tryAppAPILogin(OCP\IRequest $request): bool { |
|
|
|
$appManager = Server::get(OCP\App\IAppManager::class); |
|
|
|
if (!$request->getHeader('AUTHORIZATION-APP-API')) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (!$appManager->isInstalled('app_api')) { |
|
|
|
$appManager = Server::get(OCP\App\IAppManager::class); |
|
|
|
if (!$appManager->isEnabledForAnyone('app_api')) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
try { |
|
|
|
|
|
|
|
@ -73,7 +73,7 @@ class MetadataManager { |
|
|
|
): array { |
|
|
|
$appsAttributes = []; |
|
|
|
foreach (array_keys($metadata['apps']) as $appId) { |
|
|
|
if ($filterKnownMigrations && !$this->appManager->isInstalled($appId)) { |
|
|
|
if ($filterKnownMigrations && !$this->appManager->isEnabledForAnyone($appId)) { |
|
|
|
continue; // if not interested and app is not installed
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -837,7 +837,7 @@ class Server extends ServerContainer implements IServerContainer { |
|
|
|
$busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
|
|
if ($busClass) { |
|
|
|
[$app, $class] = explode('::', $busClass, 2); |
|
|
|
if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
|
|
if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
|
|
\OC_App::loadApp($app); |
|
|
|
return $c->get($class); |
|
|
|
} else { |
|
|
|
@ -1046,7 +1046,7 @@ class Server extends ServerContainer implements IServerContainer { |
|
|
|
$classExists = false; |
|
|
|
} |
|
|
|
|
|
|
|
if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
|
|
if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
|
|
$backgroundService = new BackgroundService( |
|
|
|
$c->get(IRootFolder::class), |
|
|
|
$c->getAppDataDir('theming'), |
|
|
|
|
|
|
|
@ -1396,7 +1396,7 @@ class Manager implements IManager { |
|
|
|
$this->logger->warning('Task processing AppAPI webhook failed for task ' . $task->getId() . '. Invalid method: ' . $method); |
|
|
|
} |
|
|
|
[, $exAppId, $httpMethod] = $parsedMethod; |
|
|
|
if (!$this->appManager->isInstalled('app_api')) { |
|
|
|
if (!$this->appManager->isEnabledForAnyone('app_api')) { |
|
|
|
$this->logger->warning('Task processing AppAPI webhook failed for task ' . $task->getId() . '. AppAPI is disabled or not installed.'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
@ -70,7 +70,7 @@ try { |
|
|
|
OC_App::loadApps(['filesystem', 'logging']); |
|
|
|
|
|
|
|
// Check if the app is enabled
|
|
|
|
if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
|
|
if (!\OC::$server->getAppManager()->isEnabledForUser($app)) { |
|
|
|
throw new \Exception('App not installed: ' . $app); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -134,7 +134,7 @@ try { |
|
|
|
$file = OC::$SERVERROOT . '/' . $file; |
|
|
|
break; |
|
|
|
default: |
|
|
|
if (!$appManager->isInstalled($app)) { |
|
|
|
if (!$appManager->isEnabledForUser($app)) { |
|
|
|
throw new RemoteException('App not installed: ' . $app); |
|
|
|
} |
|
|
|
$appManager->loadApp($app); |
|
|
|
|
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1); |
|
|
|
namespace Tests\Core\Command\Config; |
|
|
|
|
|
|
|
use OC\Core\Command\App\Enable; |
|
|
|
use OC\Installer; |
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
|
|
use Test\TestCase; |
|
|
|
|
|
|
|
@ -26,7 +27,8 @@ class AppsEnableTest extends TestCase { |
|
|
|
|
|
|
|
$command = new Enable( |
|
|
|
\OC::$server->getAppManager(), |
|
|
|
\OC::$server->getGroupManager() |
|
|
|
\OC::$server->getGroupManager(), |
|
|
|
\OC::$server->get(Installer::class), |
|
|
|
); |
|
|
|
|
|
|
|
$this->commandTester = new CommandTester($command); |
|
|
|
|
|
|
|
@ -426,17 +426,17 @@ class AppManagerTest extends TestCase { |
|
|
|
|
|
|
|
public function testIsInstalledEnabled(): void { |
|
|
|
$this->appConfig->setValue('test', 'enabled', 'yes'); |
|
|
|
$this->assertTrue($this->manager->isInstalled('test')); |
|
|
|
$this->assertTrue($this->manager->isEnabledForAnyone('test')); |
|
|
|
} |
|
|
|
|
|
|
|
public function testIsInstalledDisabled(): void { |
|
|
|
$this->appConfig->setValue('test', 'enabled', 'no'); |
|
|
|
$this->assertFalse($this->manager->isInstalled('test')); |
|
|
|
$this->assertFalse($this->manager->isEnabledForAnyone('test')); |
|
|
|
} |
|
|
|
|
|
|
|
public function testIsInstalledEnabledForGroups(): void { |
|
|
|
$this->appConfig->setValue('test', 'enabled', '["foo"]'); |
|
|
|
$this->assertTrue($this->manager->isInstalled('test')); |
|
|
|
$this->assertTrue($this->manager->isEnabledForAnyone('test')); |
|
|
|
} |
|
|
|
|
|
|
|
private function newUser($uid) { |
|
|
|
|