Add public capabilities API
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
2afb4857cc
commit
51a0741005
|
@ -80,7 +80,8 @@ class OCSController extends \OCP\AppFramework\OCSController {
|
|||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function getCapabilities() {
|
||||
|
@ -94,7 +95,11 @@ class OCSController extends \OCP\AppFramework\OCSController {
|
|||
'edition' => '',
|
||||
);
|
||||
|
||||
$result['capabilities'] = $this->capabilitiesManager->getCapabilities();
|
||||
if($this->userSession->isLoggedIn()) {
|
||||
$result['capabilities'] = $this->capabilitiesManager->getCapabilities();
|
||||
} else {
|
||||
$result['capabilities'] = $this->capabilitiesManager->getCapabilities(true);
|
||||
}
|
||||
|
||||
return new DataResponse($result);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace OC;
|
|||
|
||||
use OCP\AppFramework\QueryException;
|
||||
use OCP\Capabilities\ICapability;
|
||||
use OCP\Capabilities\IPublicCapability;
|
||||
use OCP\ILogger;
|
||||
|
||||
class CapabilitiesManager {
|
||||
|
@ -41,10 +42,11 @@ class CapabilitiesManager {
|
|||
/**
|
||||
* Get an array of al the capabilities that are registered at this manager
|
||||
*
|
||||
* @param bool $public get public capabilities only
|
||||
* @throws \InvalidArgumentException
|
||||
* @return array
|
||||
*/
|
||||
public function getCapabilities() {
|
||||
public function getCapabilities($public = false) {
|
||||
$capabilities = [];
|
||||
foreach($this->capabilities as $capability) {
|
||||
try {
|
||||
|
@ -55,7 +57,9 @@ class CapabilitiesManager {
|
|||
}
|
||||
|
||||
if ($c instanceof ICapability) {
|
||||
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
|
||||
if(!$public || ($public && $c instanceof IPublicCapability)) {
|
||||
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
|
||||
}
|
||||
} else {
|
||||
throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCP\Capabilities;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since 13.0.0
|
||||
*/
|
||||
interface IPublicCapability extends ICapability {}
|
||||
|
Loading…
Reference in New Issue