Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allow_files_filtered_by_circles option #400

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
64 changes: 47 additions & 17 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
Expand All @@ -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
*/
Expand All @@ -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;
}
Expand All @@ -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 [
Expand All @@ -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();
Expand All @@ -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',
Expand All @@ -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']);
}

}

19 changes: 19 additions & 0 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 */
Expand All @@ -86,6 +88,9 @@ class ConfigService {
/** @var int */
private $allowedCircle = -1;

/** @var int */
private $allowFilesFilteredByCircles = -1;

/** @var int */
private $allowedLinkedGroups = -1;

Expand Down Expand Up @@ -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
Expand Down