Skip to content

Commit c2856c0

Browse files
committed
Merge pull request #15093 from rullzer/capabilities_manager
Capabilities manager
2 parents 6e4a79f + f0b617b commit c2856c0

File tree

25 files changed

+542
-92
lines changed

25 files changed

+542
-92
lines changed

apps/files/appinfo/application.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
* @author Morris Jobke <[email protected]>
43
* @author Roeland Jago Douma <[email protected]>
54
* @author Tobias Kaminsky <[email protected]>
65
* @author Vincent Petry <[email protected]>
@@ -21,8 +20,7 @@
2120
* along with this program. If not, see <http://www.gnu.org/licenses/>
2221
*
2322
*/
24-
25-
namespace OCA\Files\Appinfo;
23+
namespace OCA\Files\AppInfo;
2624

2725
use OCA\Files\Controller\ApiController;
2826
use OCP\AppFramework\App;
@@ -68,5 +66,10 @@ public function __construct(array $urlParams=array()) {
6866
$homeFolder
6967
);
7068
});
69+
70+
/*
71+
* Register capabilities
72+
*/
73+
$container->registerCapability('OCA\Files\Capabilities');
7174
}
7275
}

apps/files/appinfo/routes.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
/**
33
* @author Bart Visscher <[email protected]>
4-
* @author Joas Schilling <[email protected]>
54
* @author Lukas Reschke <[email protected]>
65
* @author Morris Jobke <[email protected]>
6+
* @author Roeland Jago Douma <[email protected]>
77
* @author Tobias Kaminsky <[email protected]>
88
* @author Tom Needham <[email protected]>
99
* @author Vincent Petry <[email protected]>
@@ -24,8 +24,7 @@
2424
* along with this program. If not, see <http://www.gnu.org/licenses/>
2525
*
2626
*/
27-
28-
namespace OCA\Files\Appinfo;
27+
namespace OCA\Files\AppInfo;
2928

3029
$application = new Application();
3130
$application->registerRoutes(
@@ -82,6 +81,4 @@
8281
$this->create('download', 'download{file}')
8382
->requirements(array('file' => '.*'))
8483
->actionInclude('files/download.php');
85-
86-
// Register with the capabilities API
87-
\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files\Capabilities', 'getCapabilities'), 'files', \OCP\API::USER_AUTH);
84+

apps/files/lib/capabilities.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @author Christopher Schäpers <[email protected]>
4-
* @author Morris Jobke <[email protected]>
4+
* @author Roeland Jago Douma <[email protected]>
55
* @author Tom Needham <[email protected]>
66
*
77
* @copyright Copyright (c) 2015, ownCloud, Inc.
@@ -20,19 +20,28 @@
2020
* along with this program. If not, see <http://www.gnu.org/licenses/>
2121
*
2222
*/
23-
24-
namespace OCA\Files;
2523

26-
class Capabilities {
27-
28-
public static function getCapabilities() {
29-
return new \OC_OCS_Result(array(
30-
'capabilities' => array(
31-
'files' => array(
32-
'bigfilechunking' => true,
33-
),
34-
),
35-
));
24+
namespace OCA\Files;
25+
26+
use OCP\Capabilities\ICapability;
27+
28+
/**
29+
* Class Capabilities
30+
*
31+
* @package OCA\Files
32+
*/
33+
class Capabilities implements ICapability {
34+
35+
/**
36+
* Return this classes capabilities
37+
*
38+
* @return array
39+
*/
40+
public function getCapabilities() {
41+
return [
42+
'files' => [
43+
'bigfilechunking' => true,
44+
],
45+
];
3646
}
37-
3847
}

apps/files_external/appinfo/application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*/
2323

24-
namespace OCA\Files_External\Appinfo;
24+
namespace OCA\Files_External\AppInfo;
2525

2626
use \OCA\Files_External\Controller\AjaxController;
2727
use \OCP\AppFramework\App;

apps/files_external/appinfo/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
*/
2525

26-
namespace OCA\Files_External\Appinfo;
26+
namespace OCA\Files_External\AppInfo;
2727

2828
/**
2929
* @var $this \OC\Route\Router

apps/files_sharing/appinfo/application.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/**
33
* @author Morris Jobke <[email protected]>
44
* @author Robin Appelman <[email protected]>
5+
* @author Roeland Jago Douma <[email protected]>
56
*
67
* @copyright Copyright (c) 2015, ownCloud, Inc.
78
* @license AGPL-3.0
@@ -20,7 +21,7 @@
2021
*
2122
*/
2223

23-
namespace OCA\Files_Sharing\Appinfo;
24+
namespace OCA\Files_Sharing\AppInfo;
2425

2526
use OCA\Files_Sharing\Helper;
2627
use OCA\Files_Sharing\MountProvider;
@@ -31,6 +32,7 @@
3132
use OCA\Files_Sharing\Controllers\ShareController;
3233
use OCA\Files_Sharing\Middleware\SharingCheckMiddleware;
3334
use \OCP\IContainer;
35+
use OCA\Files_Sharing\Capabilities;
3436

3537
class Application extends App {
3638
public function __construct(array $urlParams = array()) {
@@ -122,6 +124,11 @@ public function __construct(array $urlParams = array()) {
122124
$server->getConfig()
123125
);
124126
});
127+
128+
/*
129+
* Register capabilities
130+
*/
131+
$container->registerCapability('OCA\Files_Sharing\Capabilities');
125132
}
126133

127134
public function registerMountProviders() {

apps/files_sharing/appinfo/routes.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,3 @@ function() {
9797
array('\OCA\Files_Sharing\API\Remote', 'declineShare'),
9898
'files_sharing');
9999

100-
// Register with the capabilities API
101-
API::register('get',
102-
'/cloud/capabilities',
103-
array('OCA\Files_Sharing\Capabilities', 'getCapabilities'),
104-
'files_sharing', API::USER_AUTH);

apps/files_sharing/lib/capabilities.php

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,29 @@
2020
*/
2121
namespace OCA\Files_Sharing;
2222

23+
use OCP\Capabilities\ICapability;
2324
use \OCP\IConfig;
2425

2526
/**
2627
* Class Capabilities
2728
*
2829
* @package OCA\Files_Sharing
2930
*/
30-
class Capabilities {
31+
class Capabilities implements ICapability {
3132

3233
/** @var IConfig */
3334
private $config;
3435

35-
/**
36-
* @param IConfig $config
37-
*/
3836
public function __construct(IConfig $config) {
3937
$this->config = $config;
4038
}
4139

4240
/**
43-
* @return \OC_OCS_Result
44-
*/
45-
public static function getCapabilities() {
46-
$config = \OC::$server->getConfig();
47-
$cap = new Capabilities($config);
48-
return $cap->getCaps();
49-
}
50-
51-
52-
/**
53-
* @return \OC_OCS_Result
41+
* Return this classes capabilities
42+
*
43+
* @return array
5444
*/
55-
public function getCaps() {
45+
public function getCapabilities() {
5646
$res = [];
5747

5848
$public = [];
@@ -76,12 +66,8 @@ public function getCaps() {
7666

7767
$res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
7868

79-
80-
return new \OC_OCS_Result([
81-
'capabilities' => [
82-
'files_sharing' => $res
83-
],
84-
]);
69+
return [
70+
'files_sharing' => $res,
71+
];
8572
}
86-
8773
}

apps/files_sharing/tests/capabilities.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ class FilesSharingCapabilitiesTest extends \Test\TestCase {
3636
* @return string[]
3737
*/
3838
private function getFilesSharingPart(array $data) {
39-
$this->assertArrayHasKey('capabilities', $data);
40-
$this->assertArrayHasKey('files_sharing', $data['capabilities']);
41-
return $data['capabilities']['files_sharing'];
39+
$this->assertArrayHasKey('files_sharing', $data);
40+
return $data['files_sharing'];
4241
}
4342

4443
/**
@@ -53,7 +52,7 @@ private function getResults(array $map) {
5352
$stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock();
5453
$stub->method('getAppValue')->will($this->returnValueMap($map));
5554
$cap = new Capabilities($stub);
56-
$result = $this->getFilesSharingPart($cap->getCaps()->getData());
55+
$result = $this->getFilesSharingPart($cap->getCapabilities());
5756
return $result;
5857
}
5958

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* @author Roeland Jago Douma <[email protected]>
4+
*
5+
* @copyright Copyright (c) 2015, ownCloud, Inc.
6+
* @license AGPL-3.0
7+
*
8+
* This code is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License, version 3,
10+
* as published by the Free Software Foundation.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License, version 3,
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>
19+
*
20+
*/
21+
22+
namespace OCA\Files_Trashbin\AppInfo;
23+
24+
use OCP\AppFramework\App;
25+
26+
class Application extends App {
27+
public function __construct(array $urlParams = array()) {
28+
parent::__construct('files_trashbin', $urlParams);
29+
30+
$container = $this->getContainer();
31+
32+
/*
33+
* Register capabilities
34+
*/
35+
$container->registerCapability('OCA\Files_Trashbin\Capabilities');
36+
}
37+
}

apps/files_trashbin/appinfo/routes.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
33
* @author Georg Ehrke <[email protected]>
4-
* @author Joas Schilling <[email protected]>
54
* @author Lukas Reschke <[email protected]>
6-
* @author Morris Jobke <[email protected]>
5+
* @author Roeland Jago Douma <[email protected]>
76
* @author Vincent Petry <[email protected]>
87
*
98
* @copyright Copyright (c) 2015, ownCloud, Inc.
@@ -22,6 +21,11 @@
2221
* along with this program. If not, see <http://www.gnu.org/licenses/>
2322
*
2423
*/
24+
25+
namespace OCA\Files_Trashbin\AppInfo;
26+
27+
$application = new Application();
28+
2529
$this->create('core_ajax_trashbin_preview', 'ajax/preview.php')
2630
->actionInclude('files_trashbin/ajax/preview.php');
2731
$this->create('files_trashbin_ajax_delete', 'ajax/delete.php')
@@ -33,6 +37,3 @@
3337
$this->create('files_trashbin_ajax_undelete', 'ajax/undelete.php')
3438
->actionInclude('files_trashbin/ajax/undelete.php');
3539

36-
37-
// Register with the capabilities API
38-
\OCP\API::register('get', '/cloud/capabilities', array('OCA\Files_Trashbin\Capabilities', 'getCapabilities'), 'files_trashbin', \OCP\API::USER_AUTH);

apps/files_trashbin/lib/capabilities.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/**
33
* @author Lukas Reschke <[email protected]>
44
* @author Morris Jobke <[email protected]>
5+
* @author Roeland Jago Douma <[email protected]>
56
*
67
* @copyright Copyright (c) 2015, ownCloud, Inc.
78
* @license AGPL-3.0
@@ -22,25 +23,26 @@
2223

2324
namespace OCA\Files_Trashbin;
2425

26+
use OCP\Capabilities\ICapability;
2527

2628
/**
2729
* Class Capabilities
2830
*
2931
* @package OCA\Files_Trashbin
3032
*/
31-
class Capabilities {
33+
class Capabilities implements ICapability {
3234

3335
/**
34-
* @return \OC_OCS_Result
36+
* Return this classes capabilities
37+
*
38+
* @return array
3539
*/
36-
public static function getCapabilities() {
37-
return new \OC_OCS_Result(array(
38-
'capabilities' => array(
39-
'files' => array(
40-
'undelete' => true,
41-
),
42-
),
43-
));
40+
public function getCapabilities() {
41+
return [
42+
'files' => [
43+
'undelete' => true
44+
]
45+
];
4446
}
4547

4648
}

0 commit comments

Comments
 (0)