Merge pull request #15093 from rullzer/capabilities_manager
Capabilities manager
This commit is contained in:
commit
c2856c05aa
25 changed files with 542 additions and 92 deletions
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
* @author Tobias Kaminsky <tobias@kaminsky.me>
|
||||
* @author Vincent Petry <pvince81@owncloud.com>
|
||||
|
@ -21,8 +20,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files\Appinfo;
|
||||
namespace OCA\Files\AppInfo;
|
||||
|
||||
use OCA\Files\Controller\ApiController;
|
||||
use OCP\AppFramework\App;
|
||||
|
@ -68,5 +66,10 @@ class Application extends App {
|
|||
$homeFolder
|
||||
);
|
||||
});
|
||||
|
||||
/*
|
||||
* Register capabilities
|
||||
*/
|
||||
$container->registerCapability('OCA\Files\Capabilities');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Bart Visscher <bartv@thisnet.nl>
|
||||
* @author Joas Schilling <nickvergessen@owncloud.com>
|
||||
* @author Lukas Reschke <lukas@owncloud.com>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
* @author Tobias Kaminsky <tobias@kaminsky.me>
|
||||
* @author Tom Needham <tom@owncloud.com>
|
||||
* @author Vincent Petry <pvince81@owncloud.com>
|
||||
|
@ -24,8 +24,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files\Appinfo;
|
||||
namespace OCA\Files\AppInfo;
|
||||
|
||||
$application = new Application();
|
||||
$application->registerRoutes(
|
||||
|
@ -82,6 +81,4 @@ $this->create('files_ajax_upload', 'ajax/upload.php')
|
|||
$this->create('download', 'download{file}')
|
||||
->requirements(array('file' => '.*'))
|
||||
->actionInclude('files/download.php');
|
||||
|
||||
// Register with the capabilities API
|
||||
\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files\Capabilities', 'getCapabilities'), 'files', \OCP\API::USER_AUTH);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Christopher Schäpers <kondou@ts.unde.re>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
* @author Tom Needham <tom@owncloud.com>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
|
@ -20,19 +20,28 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files;
|
||||
|
||||
class Capabilities {
|
||||
|
||||
public static function getCapabilities() {
|
||||
return new \OC_OCS_Result(array(
|
||||
'capabilities' => array(
|
||||
'files' => array(
|
||||
'bigfilechunking' => true,
|
||||
),
|
||||
),
|
||||
));
|
||||
namespace OCA\Files;
|
||||
|
||||
use OCP\Capabilities\ICapability;
|
||||
|
||||
/**
|
||||
* Class Capabilities
|
||||
*
|
||||
* @package OCA\Files
|
||||
*/
|
||||
class Capabilities implements ICapability {
|
||||
|
||||
/**
|
||||
* Return this classes capabilities
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCapabilities() {
|
||||
return [
|
||||
'files' => [
|
||||
'bigfilechunking' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Appinfo;
|
||||
namespace OCA\Files_External\AppInfo;
|
||||
|
||||
use \OCA\Files_External\Controller\AjaxController;
|
||||
use \OCP\AppFramework\App;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Appinfo;
|
||||
namespace OCA\Files_External\AppInfo;
|
||||
|
||||
/**
|
||||
* @var $this \OC\Route\Router
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/**
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Robin Appelman <icewind@owncloud.com>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
|
@ -20,7 +21,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Sharing\Appinfo;
|
||||
namespace OCA\Files_Sharing\AppInfo;
|
||||
|
||||
use OCA\Files_Sharing\Helper;
|
||||
use OCA\Files_Sharing\MountProvider;
|
||||
|
@ -31,6 +32,7 @@ use OCA\Files_Sharing\Controllers\ExternalSharesController;
|
|||
use OCA\Files_Sharing\Controllers\ShareController;
|
||||
use OCA\Files_Sharing\Middleware\SharingCheckMiddleware;
|
||||
use \OCP\IContainer;
|
||||
use OCA\Files_Sharing\Capabilities;
|
||||
|
||||
class Application extends App {
|
||||
public function __construct(array $urlParams = array()) {
|
||||
|
@ -122,6 +124,11 @@ class Application extends App {
|
|||
$server->getConfig()
|
||||
);
|
||||
});
|
||||
|
||||
/*
|
||||
* Register capabilities
|
||||
*/
|
||||
$container->registerCapability('OCA\Files_Sharing\Capabilities');
|
||||
}
|
||||
|
||||
public function registerMountProviders() {
|
||||
|
|
|
@ -97,8 +97,3 @@ API::register('delete',
|
|||
array('\OCA\Files_Sharing\API\Remote', 'declineShare'),
|
||||
'files_sharing');
|
||||
|
||||
// Register with the capabilities API
|
||||
API::register('get',
|
||||
'/cloud/capabilities',
|
||||
array('OCA\Files_Sharing\Capabilities', 'getCapabilities'),
|
||||
'files_sharing', API::USER_AUTH);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
namespace OCA\Files_Sharing;
|
||||
|
||||
use OCP\Capabilities\ICapability;
|
||||
use \OCP\IConfig;
|
||||
|
||||
/**
|
||||
|
@ -27,32 +28,21 @@ use \OCP\IConfig;
|
|||
*
|
||||
* @package OCA\Files_Sharing
|
||||
*/
|
||||
class Capabilities {
|
||||
class Capabilities implements ICapability {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \OC_OCS_Result
|
||||
* Return this classes capabilities
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCapabilities() {
|
||||
$config = \OC::$server->getConfig();
|
||||
$cap = new Capabilities($config);
|
||||
return $cap->getCaps();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \OC_OCS_Result
|
||||
*/
|
||||
public function getCaps() {
|
||||
public function getCapabilities() {
|
||||
$res = [];
|
||||
|
||||
$public = [];
|
||||
|
@ -76,12 +66,8 @@ class Capabilities {
|
|||
|
||||
$res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
|
||||
|
||||
|
||||
return new \OC_OCS_Result([
|
||||
'capabilities' => [
|
||||
'files_sharing' => $res
|
||||
],
|
||||
]);
|
||||
return [
|
||||
'files_sharing' => $res,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,9 +36,8 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase {
|
|||
* @return string[]
|
||||
*/
|
||||
private function getFilesSharingPart(array $data) {
|
||||
$this->assertArrayHasKey('capabilities', $data);
|
||||
$this->assertArrayHasKey('files_sharing', $data['capabilities']);
|
||||
return $data['capabilities']['files_sharing'];
|
||||
$this->assertArrayHasKey('files_sharing', $data);
|
||||
return $data['files_sharing'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +52,7 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase {
|
|||
$stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock();
|
||||
$stub->method('getAppValue')->will($this->returnValueMap($map));
|
||||
$cap = new Capabilities($stub);
|
||||
$result = $this->getFilesSharingPart($cap->getCaps()->getData());
|
||||
$result = $this->getFilesSharingPart($cap->getCapabilities());
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
37
apps/files_trashbin/appinfo/application.php
Normal file
37
apps/files_trashbin/appinfo/application.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Trashbin\AppInfo;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
|
||||
class Application extends App {
|
||||
public function __construct(array $urlParams = array()) {
|
||||
parent::__construct('files_trashbin', $urlParams);
|
||||
|
||||
$container = $this->getContainer();
|
||||
|
||||
/*
|
||||
* Register capabilities
|
||||
*/
|
||||
$container->registerCapability('OCA\Files_Trashbin\Capabilities');
|
||||
}
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Georg Ehrke <georg@owncloud.com>
|
||||
* @author Joas Schilling <nickvergessen@owncloud.com>
|
||||
* @author Lukas Reschke <lukas@owncloud.com>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
* @author Vincent Petry <pvince81@owncloud.com>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
|
@ -22,6 +21,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Trashbin\AppInfo;
|
||||
|
||||
$application = new Application();
|
||||
|
||||
$this->create('core_ajax_trashbin_preview', 'ajax/preview.php')
|
||||
->actionInclude('files_trashbin/ajax/preview.php');
|
||||
$this->create('files_trashbin_ajax_delete', 'ajax/delete.php')
|
||||
|
@ -33,6 +37,3 @@ $this->create('files_trashbin_ajax_list', 'ajax/list.php')
|
|||
$this->create('files_trashbin_ajax_undelete', 'ajax/undelete.php')
|
||||
->actionInclude('files_trashbin/ajax/undelete.php');
|
||||
|
||||
|
||||
// Register with the capabilities API
|
||||
\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files_Trashbin\Capabilities', 'getCapabilities'), 'files_trashbin', \OCP\API::USER_AUTH);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/**
|
||||
* @author Lukas Reschke <lukas@owncloud.com>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
|
@ -22,25 +23,26 @@
|
|||
|
||||
namespace OCA\Files_Trashbin;
|
||||
|
||||
use OCP\Capabilities\ICapability;
|
||||
|
||||
/**
|
||||
* Class Capabilities
|
||||
*
|
||||
* @package OCA\Files_Trashbin
|
||||
*/
|
||||
class Capabilities {
|
||||
class Capabilities implements ICapability {
|
||||
|
||||
/**
|
||||
* @return \OC_OCS_Result
|
||||
* Return this classes capabilities
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCapabilities() {
|
||||
return new \OC_OCS_Result(array(
|
||||
'capabilities' => array(
|
||||
'files' => array(
|
||||
'undelete' => true,
|
||||
),
|
||||
),
|
||||
));
|
||||
public function getCapabilities() {
|
||||
return [
|
||||
'files' => [
|
||||
'undelete' => true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
37
apps/files_versions/appinfo/application.php
Normal file
37
apps/files_versions/appinfo/application.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Versions\AppInfo;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
|
||||
class Application extends App {
|
||||
public function __construct(array $urlParams = array()) {
|
||||
parent::__construct('files_versions', $urlParams);
|
||||
|
||||
$container = $this->getContainer();
|
||||
|
||||
/*
|
||||
* Register capabilities
|
||||
*/
|
||||
$container->registerCapability('OCA\Files_Versions\Capabilities');
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Björn Schießle <schiessle@owncloud.com>
|
||||
* @author Joas Schilling <nickvergessen@owncloud.com>
|
||||
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
||||
* @author Lukas Reschke <lukas@owncloud.com>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
* @author Tom Needham <tom@owncloud.com>
|
||||
*
|
||||
|
@ -25,6 +25,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Versions\AppInfo;
|
||||
|
||||
$application = new Application();
|
||||
|
||||
/** @var $this \OCP\Route\IRouter */
|
||||
$this->create('core_ajax_versions_preview', '/preview')->action(
|
||||
function() {
|
||||
|
@ -38,5 +42,3 @@ $this->create('files_versions_ajax_getVersions', 'ajax/getVersions.php')
|
|||
$this->create('files_versions_ajax_rollbackVersion', 'ajax/rollbackVersion.php')
|
||||
->actionInclude('files_versions/ajax/rollbackVersion.php');
|
||||
|
||||
// Register with the capabilities API
|
||||
\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files_Versions\Capabilities', 'getCapabilities'), 'files_versions', \OCP\API::USER_AUTH);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/**
|
||||
* @author Christopher Schäpers <kondou@ts.unde.re>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
* @author Tom Needham <tom@owncloud.com>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
|
@ -23,16 +24,20 @@
|
|||
|
||||
namespace OCA\Files_Versions;
|
||||
|
||||
class Capabilities {
|
||||
use OCP\Capabilities\ICapability;
|
||||
|
||||
class Capabilities implements ICapability {
|
||||
|
||||
public static function getCapabilities() {
|
||||
return new \OC_OCS_Result(array(
|
||||
'capabilities' => array(
|
||||
'files' => array(
|
||||
'versioning' => true,
|
||||
),
|
||||
),
|
||||
));
|
||||
/**
|
||||
* Return this classes capabilities
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCapabilities() {
|
||||
return [
|
||||
'files' => [
|
||||
'versioning' => true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -96,6 +96,10 @@ class DIContainer extends SimpleContainer implements IAppContainer {
|
|||
return $this->getServer()->getMemCacheFactory();
|
||||
});
|
||||
|
||||
$this->registerService('OC\\CapabilitiesManager', function($c) {
|
||||
return $this->getServer()->getCapabilitiesManager();
|
||||
});
|
||||
|
||||
$this->registerService('OCP\\IConfig', function($c) {
|
||||
return $this->getServer()->getConfig();
|
||||
});
|
||||
|
@ -390,5 +394,15 @@ class DIContainer extends SimpleContainer implements IAppContainer {
|
|||
\OCP\Util::writeLog($this->getAppName(), $message, $level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a capability
|
||||
*
|
||||
* @param string $serviceName e.g. 'OCA\Files\Capabilities'
|
||||
*/
|
||||
public function registerCapability($serviceName) {
|
||||
$this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
|
||||
return $this->query($serviceName);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
64
lib/private/capabilitiesmanager.php
Normal file
64
lib/private/capabilitiesmanager.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
namespace OC;
|
||||
|
||||
|
||||
use OCP\Capabilities\ICapability;
|
||||
|
||||
class CapabilitiesManager {
|
||||
|
||||
/**
|
||||
* @var \Closure[]
|
||||
*/
|
||||
private $capabilities = array();
|
||||
|
||||
/**
|
||||
* Get an array of al the capabilities that are registered at this manager
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return array
|
||||
*/
|
||||
public function getCapabilities() {
|
||||
$capabilities = [];
|
||||
foreach($this->capabilities as $capability) {
|
||||
$c = $capability();
|
||||
if ($c instanceof ICapability) {
|
||||
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
|
||||
} else {
|
||||
throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface');
|
||||
}
|
||||
}
|
||||
|
||||
return $capabilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* In order to improve lazy loading a closure can be registered which will be called in case
|
||||
* capabilities are actually requested
|
||||
*
|
||||
* $callable has to return an instance of OCP\Capabilities\ICapability
|
||||
*
|
||||
* @param \Closure $callable
|
||||
*/
|
||||
public function registerCapability(\Closure $callable) {
|
||||
array_push($this->capabilities, $callable);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
* @author Bart Visscher <bartv@thisnet.nl>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
* @author Tom Needham <tom@owncloud.com>
|
||||
*
|
||||
|
@ -36,12 +37,8 @@ class OC_OCS_Cloud {
|
|||
'edition' => OC_Util::getEditionString(),
|
||||
);
|
||||
|
||||
$result['capabilities'] = array(
|
||||
'core' => array(
|
||||
'pollinterval' => OC_Config::getValue('pollinterval', 60),
|
||||
),
|
||||
);
|
||||
|
||||
$result['capabilities'] = \OC::$server->getCapabilitiesManager()->getCapabilities();
|
||||
|
||||
return new OC_OCS_Result($result);
|
||||
}
|
||||
|
||||
|
|
56
lib/private/ocs/corecapabilities.php
Normal file
56
lib/private/ocs/corecapabilities.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\OCS;
|
||||
|
||||
use OCP\Capabilities\ICapability;
|
||||
use OCP\IConfig;
|
||||
|
||||
/**
|
||||
* Class Capabilities
|
||||
*
|
||||
* @package OC\OCS
|
||||
*/
|
||||
class CoreCapabilities implements ICapability {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this classes capabilities
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCapabilities() {
|
||||
return [
|
||||
'core' => [
|
||||
'pollinterval' => $this->config->getSystemValue('pollinterval', 60)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
|
@ -449,6 +449,14 @@ class Server extends SimpleContainer implements IServerContainer {
|
|||
$c->getURLGenerator(),
|
||||
\OC::$configDir);
|
||||
});
|
||||
$this->registerService('CapabilitiesManager', function (Server $c) {
|
||||
$manager = new \OC\CapabilitiesManager();
|
||||
$manager->registerCapability(function() use ($c) {
|
||||
return new \OC\OCS\CoreCapabilities($c->getConfig());
|
||||
});
|
||||
return $manager;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -945,4 +953,13 @@ class Server extends SimpleContainer implements IServerContainer {
|
|||
public function getMimeTypeDetector() {
|
||||
return $this->query('MimeTypeDetector');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the manager of all the capabilities
|
||||
*
|
||||
* @return \OC\CapabilitiesManager
|
||||
*/
|
||||
public function getCapabilitiesManager() {
|
||||
return $this->query('CapabilitiesManager');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,4 +86,11 @@ interface IAppContainer extends IContainer {
|
|||
*/
|
||||
function log($message, $level);
|
||||
|
||||
/**
|
||||
* Register a capability
|
||||
*
|
||||
* @param string $serviceName e.g. 'OCA\Files\Capabilities'
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function registerCapability($serviceName);
|
||||
}
|
||||
|
|
46
lib/public/capabilities/icapability.php
Normal file
46
lib/public/capabilities/icapability.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCP\Capabilities;
|
||||
|
||||
/**
|
||||
* Minimal interface that has to be implemented for a class to be considered
|
||||
* a capability.
|
||||
*
|
||||
* In an application use:
|
||||
* $this->getContainer()->registerCapability('OCA\MY_APP\Capabilities');
|
||||
* To register capabilities.
|
||||
*
|
||||
* The class 'OCA\MY_APP\Capabilities' must then implement ICapability
|
||||
*
|
||||
* @since 8.2.0
|
||||
*/
|
||||
interface ICapability {
|
||||
|
||||
/**
|
||||
* Function an app uses to return the capabilities
|
||||
*
|
||||
* @return array Array containing the apps capabilities
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function getCapabilities();
|
||||
}
|
||||
|
|
@ -438,4 +438,5 @@ interface IServerContainer {
|
|||
* @since 8.2.0
|
||||
*/
|
||||
public function getMimeTypeDetector();
|
||||
|
||||
}
|
||||
|
|
164
tests/lib/capabilitiesmanager.php
Normal file
164
tests/lib/capabilitiesmanager.php
Normal file
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Test;
|
||||
|
||||
use OC\CapabilitiesManager;
|
||||
|
||||
class CapabilitiesManagerTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test no capabilities
|
||||
*/
|
||||
public function testNoCapabilities() {
|
||||
$manager = new \OC\CapabilitiesManager();
|
||||
$res = $manager->getCapabilities();
|
||||
$this->assertEmpty($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a valid capabilitie
|
||||
*/
|
||||
public function testValidCapability() {
|
||||
$manager = new \OC\CapabilitiesManager();
|
||||
|
||||
$manager->registerCapability(function() {
|
||||
return new SimpleCapability();
|
||||
});
|
||||
|
||||
$res = $manager->getCapabilities();
|
||||
$this->assertEquals(['foo' => 1], $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we need something that implents ICapability
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The given Capability (Test\NoCapability) does not implement the ICapability interface
|
||||
*/
|
||||
public function testNoICapability() {
|
||||
$manager = new \OC\CapabilitiesManager();
|
||||
|
||||
$manager->registerCapability(function() {
|
||||
return new NoCapability();
|
||||
});
|
||||
|
||||
$res = $manager->getCapabilities();
|
||||
$this->assertEquals([], $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a bunch of merged Capabilities
|
||||
*/
|
||||
public function testMergedCapabilities() {
|
||||
$manager = new \OC\CapabilitiesManager();
|
||||
|
||||
$manager->registerCapability(function() {
|
||||
return new SimpleCapability();
|
||||
});
|
||||
$manager->registerCapability(function() {
|
||||
return new SimpleCapability2();
|
||||
});
|
||||
$manager->registerCapability(function() {
|
||||
return new SimpleCapability3();
|
||||
});
|
||||
|
||||
$res = $manager->getCapabilities();
|
||||
$expected = [
|
||||
'foo' => 1,
|
||||
'bar' => [
|
||||
'x' => 1,
|
||||
'y' => 2
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test deep identical capabilities
|
||||
*/
|
||||
public function testDeepIdenticalCapabilities() {
|
||||
$manager = new \OC\CapabilitiesManager();
|
||||
|
||||
$manager->registerCapability(function() {
|
||||
return new DeepCapability();
|
||||
});
|
||||
$manager->registerCapability(function() {
|
||||
return new DeepCapability();
|
||||
});
|
||||
|
||||
$res = $manager->getCapabilities();
|
||||
$expected = [
|
||||
'foo' => [
|
||||
'bar' => [
|
||||
'baz' => true
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $res);
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleCapability implements \OCP\Capabilities\ICapability {
|
||||
public function getCapabilities() {
|
||||
return [
|
||||
'foo' => 1
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleCapability2 implements \OCP\Capabilities\ICapability {
|
||||
public function getCapabilities() {
|
||||
return [
|
||||
'bar' => ['x' => 1]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleCapability3 implements \OCP\Capabilities\ICapability {
|
||||
public function getCapabilities() {
|
||||
return [
|
||||
'bar' => ['y' => 2]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class NoCapability {
|
||||
public function getCapabilities() {
|
||||
return [
|
||||
'baz' => 'z'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class DeepCapability implements \OCP\Capabilities\ICapability {
|
||||
public function getCapabilities() {
|
||||
return [
|
||||
'foo' => [
|
||||
'bar' => [
|
||||
'baz' => true
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Joas Schilling <nickvergessen@owncloud.com>
|
||||
* @author Lukas Reschke <lukas@owncloud.com>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
|
@ -48,6 +51,7 @@ class Server extends \Test\TestCase {
|
|||
['AvatarManager', '\OC\AvatarManager'],
|
||||
['AvatarManager', '\OCP\IAvatarManager'],
|
||||
|
||||
['CapabilitiesManager', '\OC\CapabilitiesManager'],
|
||||
['ContactsManager', '\OC\ContactsManager'],
|
||||
['ContactsManager', '\OCP\Contacts\IManager'],
|
||||
['Crypto', '\OC\Security\Crypto'],
|
||||
|
|
Loading…
Reference in a new issue