diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1b3c247dc..31b6b1645 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -29,7 +29,6 @@ namespace OCA\Circles\AppInfo; -use OC; use OCA\Circles\Api\v1\Circles; use OCA\Circles\Notification\Notifier; use OCA\Circles\Service\ConfigService; @@ -39,6 +38,7 @@ use OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; use OCP\AppFramework\QueryException; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Util; require_once __DIR__ . '/../../appinfo/autoload.php'; @@ -56,22 +56,35 @@ class Application extends App { /** @var IAppContainer */ private $container; + /** @var \OC\ServerServer */ + private $server; + + /** @var IEventDispatcher */ + private $dispatcher; + /** * @param array $params */ public function __construct(array $params = array()) { parent::__construct(self::APP_NAME, $params); + } + public function register() + { $this->container = $this->getContainer(); + $this->server = $this->container->getServer(); + $this->dispatcher = $this->server->query(IEventDispatcher::class); - $manager = OC::$server->getNotificationManager(); + $manager = $this->server->getNotificationManager(); $manager->registerNotifierService(Notifier::class); + $this->registerNavigation(); + $this->registerFilesNavigation(); + $this->registerFilesPlugin(); $this->registerHooks(); $this->registerDavHooks(); } - /** * Register Hooks */ @@ -91,7 +104,7 @@ public function registerHooks() { public function registerNavigation() { /** @var ConfigService $configService */ try { - $configService = OC::$server->query(ConfigService::class); + $configService = $this->server->query(ConfigService::class); } catch (QueryException $e) { return; } @@ -104,8 +117,8 @@ public function registerNavigation() { ->getNavigationManager(); $appManager->add( function() { - $urlGen = OC::$server->getURLGenerator(); - $navName = OC::$server->getL10N(self::APP_NAME) + $urlGen = $this->server->getURLGenerator(); + $navName = $this->server->getL10N(self::APP_NAME) ->t('Circles'); return [ @@ -121,8 +134,17 @@ function() { } public function registerFilesPlugin() { - $eventDispatcher = OC::$server->getEventDispatcher(); - $eventDispatcher->addListener( + try { + /** @var ConfigService $configService */ + $configService = $this->server->query(ConfigService::class); + if (!$configService->isFilesFilteredCirclesAllowed()) { + return; + } + } catch (QueryException $e) { + return; + } + + $this->dispatcher->addListener( 'OCA\Files::loadAdditionalScripts', function() { Circles::addJavascriptAPI(); @@ -140,10 +162,20 @@ function() { * */ public function registerFilesNavigation() { + try { + /** @var ConfigService $configService */ + $configService = $this->server->query(ConfigService::class); + if (!$configService->isFilesFilteredCirclesAllowed()) { + return; + } + } catch (QueryException $e) { + return; + } + $appManager = FilesApp::getNavigationManager(); $appManager->add( function() { - $l = OC::$server->getL10N('circles'); + $l = $this->server->getL10N('circles'); return [ 'id' => 'circlesfilter', @@ -160,24 +192,22 @@ function() { public function registerDavHooks() { try { /** @var ConfigService $configService */ - $configService = OC::$server->query(ConfigService::class); + $configService = $this->server->query(ConfigService::class); if (!$configService->isContactsBackend()) { return; } /** @var DavService $davService */ - $davService = OC::$server->query(DavService::class); + $davService = $this->server->query(DavService::class); } catch (QueryException $e) { return; } - $event = OC::$server->getEventDispatcher(); + $this->dispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, [$davService, 'onAppEnabled']); + $this->dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', [$davService, 'onCreateCard']); + $this->dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', [$davService, 'onUpdateCard']); + $this->dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', [$davService, 'onDeleteCard']); - $event->addListener(ManagerEvent::EVENT_APP_ENABLE, [$davService, 'onAppEnabled']); - $event->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', [$davService, 'onCreateCard']); - $event->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', [$davService, 'onUpdateCard']); - $event->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', [$davService, 'onDeleteCard']); } } - diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index c1497c7ac..e476b5ed3 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -41,6 +41,7 @@ class ConfigService { const CIRCLES_ALLOW_FEDERATED_CIRCLES = 'allow_federated'; const CIRCLES_MEMBERS_LIMIT = 'members_limit'; const CIRCLES_ACCOUNTS_ONLY = 'accounts_only'; + const CIRCLES_ALLOW_FILES_CIRCLES_FILTER = 'allow_files_filtered_by_circles'; const CIRCLES_ALLOW_LINKED_GROUPS = 'allow_linked_groups'; const CIRCLES_ALLOW_NON_SSL_LINKS = 'allow_non_ssl_links'; const CIRCLES_NON_SSL_LOCAL = 'local_is_non_ssl'; @@ -66,6 +67,7 @@ class ConfigService { self::CIRCLES_NON_SSL_LOCAL => '0', self::CIRCLES_ACTIVITY_ON_CREATION => '1', self::CIRCLES_SKIP_INVITATION_STEP => '0' + self::CIRCLES_ALLOW_FILES_CIRCLES_FILTER => '1', ]; /** @var string */ @@ -86,6 +88,9 @@ class ConfigService { /** @var int */ private $allowedCircle = -1; + /** @var int */ + private $allowFilesFilteredByCircles = -1; + /** @var int */ private $allowedLinkedGroups = -1; @@ -139,6 +144,20 @@ public function isCircleAllowed($type) { return ((int)$type & (int)$this->allowedCircle); } + /** + * returns if the files list could be filtered by circles + * + * @return bool + */ + public function isFilesFilteredCirclesAllowed() { + if ($this->allowFilesFilteredByCircles === -1) { + $this->allowFilesFilteredByCircles = + (int)$this->getAppValue(self::CIRCLES_ALLOW_FILES_CIRCLES_FILTER); + } + + return ($this->allowFilesFilteredByCircles === 1); + } + /** * @return bool