Skip to content

Commit 4954c9f

Browse files
authored
Merge pull request #39574 from nextcloud/fix/noid/ocm-controller
OCM Services
2 parents dead436 + b5dcd04 commit 4954c9f

26 files changed

Lines changed: 1237 additions & 254 deletions

apps/cloud_federation_api/appinfo/routes.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
77
*
88
* @author Joas Schilling <coding@schilljs.com>
9+
* @author Maxence Lange <maxence@artificial-owl.com>
910
*
1011
* @license GNU AGPL version 3 or any later version
1112
*
@@ -27,15 +28,21 @@
2728
'routes' => [
2829
[
2930
'name' => 'RequestHandler#addShare',
30-
'url' => '/ocm/shares',
31+
'url' => '/shares',
3132
'verb' => 'POST',
32-
'root' => '',
33+
'root' => '/ocm',
3334
],
3435
[
3536
'name' => 'RequestHandler#receiveNotification',
36-
'url' => '/ocm/notifications',
37+
'url' => '/notifications',
3738
'verb' => 'POST',
38-
'root' => '',
39+
'root' => '/ocm',
3940
],
41+
// [
42+
// 'name' => 'RequestHandler#inviteAccepted',
43+
// 'url' => '/invite-accepted',
44+
// 'verb' => 'POST',
45+
// 'root' => '/ocm',
46+
// ]
4047
],
4148
];
Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
47
*
58
* @author Bjoern Schiessle <bjoern@schiessle.org>
69
* @author Kate Döen <kate.doeen@nextcloud.com>
10+
* @author Maxence Lange <maxence@artificial-owl.com>
711
*
812
* @license GNU AGPL version 3 or any later version
913
*
@@ -21,18 +25,22 @@
2125
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2226
*
2327
*/
28+
2429
namespace OCA\CloudFederationAPI;
2530

31+
use OC\OCM\Model\OCMProvider;
32+
use OC\OCM\Model\OCMResource;
2633
use OCP\Capabilities\ICapability;
2734
use OCP\IURLGenerator;
35+
use OCP\OCM\Exceptions\OCMArgumentException;
2836

2937
class Capabilities implements ICapability {
3038

31-
/** @var IURLGenerator */
32-
private $urlGenerator;
39+
public const API_VERSION = '1.0-proposal1';
3340

34-
public function __construct(IURLGenerator $urlGenerator) {
35-
$this->urlGenerator = $urlGenerator;
41+
public function __construct(
42+
private IURLGenerator $urlGenerator,
43+
) {
3644
}
3745

3846
/**
@@ -46,32 +54,33 @@ public function __construct(IURLGenerator $urlGenerator) {
4654
* resourceTypes: array{
4755
* name: string,
4856
* shareTypes: string[],
49-
* protocols: array{
50-
* webdav: string,
51-
* },
52-
* }[],
53-
* },
57+
* protocols: array<string, string>
58+
* }[],
59+
* },
5460
* }
61+
* @throws OCMArgumentException
5562
*/
5663
public function getCapabilities() {
5764
$url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
58-
$capabilities = ['ocm' =>
59-
[
60-
'enabled' => true,
61-
'apiVersion' => '1.0-proposal1',
62-
'endPoint' => substr($url, 0, strrpos($url, '/')),
63-
'resourceTypes' => [
64-
[
65-
'name' => 'file',
66-
'shareTypes' => ['user', 'group'],
67-
'protocols' => [
68-
'webdav' => '/public.php/webdav/',
69-
]
70-
],
71-
]
72-
]
73-
];
7465

75-
return $capabilities;
66+
$provider = new OCMProvider();
67+
$provider->setEnabled(true);
68+
$provider->setApiVersion(self::API_VERSION);
69+
70+
$pos = strrpos($url, '/');
71+
if (false === $pos) {
72+
throw new OCMArgumentException('generated route should contains a slash character');
73+
}
74+
75+
$provider->setEndPoint(substr($url, 0, $pos));
76+
77+
$resource = new OCMResource();
78+
$resource->setName('file')
79+
->setShareTypes(['user', 'group'])
80+
->setProtocols(['webdav' => '/public.php/webdav/']);
81+
82+
$provider->setResourceTypes([$resource]);
83+
84+
return ['ocm' => $provider->jsonSerialize()];
7685
}
7786
}

apps/cloud_federation_api/lib/Controller/RequestHandlerController.php

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* @author Bjoern Schiessle <bjoern@schiessle.org>
66
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
7+
* @author Maxence Lange <maxence@artificial-owl.com>
78
* @author Roeland Jago Douma <roeland@famdouma.nl>
89
* @author Kate Döen <kate.doeen@nextcloud.com>
910
*
@@ -55,52 +56,19 @@
5556
* @psalm-import-type CloudFederationApiError from ResponseDefinitions
5657
*/
5758
class RequestHandlerController extends Controller {
58-
59-
/** @var LoggerInterface */
60-
private $logger;
61-
62-
/** @var IUserManager */
63-
private $userManager;
64-
65-
/** @var IGroupManager */
66-
private $groupManager;
67-
68-
/** @var IURLGenerator */
69-
private $urlGenerator;
70-
71-
/** @var ICloudFederationProviderManager */
72-
private $cloudFederationProviderManager;
73-
74-
/** @var Config */
75-
private $config;
76-
77-
/** @var ICloudFederationFactory */
78-
private $factory;
79-
80-
/** @var ICloudIdManager */
81-
private $cloudIdManager;
82-
83-
public function __construct($appName,
84-
IRequest $request,
85-
LoggerInterface $logger,
86-
IUserManager $userManager,
87-
IGroupManager $groupManager,
88-
IURLGenerator $urlGenerator,
89-
ICloudFederationProviderManager $cloudFederationProviderManager,
90-
Config $config,
91-
ICloudFederationFactory $factory,
92-
ICloudIdManager $cloudIdManager
59+
public function __construct(
60+
string $appName,
61+
IRequest $request,
62+
private LoggerInterface $logger,
63+
private IUserManager $userManager,
64+
private IGroupManager $groupManager,
65+
private IURLGenerator $urlGenerator,
66+
private ICloudFederationProviderManager $cloudFederationProviderManager,
67+
private Config $config,
68+
private ICloudFederationFactory $factory,
69+
private ICloudIdManager $cloudIdManager
9370
) {
9471
parent::__construct($appName, $request);
95-
96-
$this->logger = $logger;
97-
$this->userManager = $userManager;
98-
$this->groupManager = $groupManager;
99-
$this->urlGenerator = $urlGenerator;
100-
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
101-
$this->config = $config;
102-
$this->factory = $factory;
103-
$this->cloudIdManager = $cloudIdManager;
10472
}
10573

10674
/**
@@ -128,7 +96,6 @@ public function __construct($appName,
12896
* 501: Share type or the resource type is not supported
12997
*/
13098
public function addShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $protocol, $shareType, $resourceType) {
131-
13299
// check if all required parameters are set
133100
if ($shareWith === null ||
134101
$name === null ||
@@ -253,7 +220,6 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $
253220
* 501: The resource type is not supported
254221
*/
255222
public function receiveNotification($notificationType, $resourceType, $providerId, ?array $notification) {
256-
257223
// check if all required parameters are set
258224
if ($notificationType === null ||
259225
$resourceType === null ||
@@ -311,7 +277,7 @@ public function receiveNotification($notificationType, $resourceType, $providerI
311277
);
312278
}
313279

314-
return new JSONResponse($result,Http::STATUS_CREATED);
280+
return new JSONResponse($result, Http::STATUS_CREATED);
315281
}
316282

317283
/**

apps/cloud_federation_api/openapi.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,8 @@
7676
},
7777
"protocols": {
7878
"type": "object",
79-
"required": [
80-
"webdav"
81-
],
82-
"properties": {
83-
"webdav": {
84-
"type": "string"
85-
}
79+
"additionalProperties": {
80+
"type": "string"
8681
}
8782
}
8883
}

apps/files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
77
*
88
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
9+
* @author Maxence Lange <maxence@artificial-owl.com>
910
* @author Roeland Jago Douma <roeland@famdouma.nl>
1011
*
1112
* @license GNU AGPL version 3 or any later version
@@ -29,21 +30,21 @@
2930
use OCP\AppFramework\Utility\ITimeFactory;
3031
use OCP\BackgroundJob\TimedJob;
3132
use OCP\IDBConnection;
33+
use OCP\OCM\Exceptions\OCMProviderException;
34+
use OCP\OCM\IOCMDiscoveryService;
3235
use OCP\OCS\IDiscoveryService;
36+
use Psr\Log\LoggerInterface;
3337

3438
class FederatedSharesDiscoverJob extends TimedJob {
35-
/** @var IDBConnection */
36-
private $connection;
37-
/** @var IDiscoveryService */
38-
private $discoveryService;
39-
40-
public function __construct(ITimeFactory $time,
41-
IDBConnection $connection,
42-
IDiscoveryService $discoveryService) {
43-
parent::__construct($time);
44-
$this->connection = $connection;
45-
$this->discoveryService = $discoveryService;
4639

40+
public function __construct(
41+
ITimeFactory $time,
42+
private IDBConnection $connection,
43+
private IDiscoveryService $discoveryService,
44+
private IOCMDiscoveryService $ocmDiscoveryService,
45+
private LoggerInterface $logger,
46+
) {
47+
parent::__construct($time);
4748
$this->setInterval(86400);
4849
}
4950

@@ -56,6 +57,11 @@ public function run($argument) {
5657
$result = $qb->execute();
5758
while ($row = $result->fetch()) {
5859
$this->discoveryService->discover($row['remote'], 'FEDERATED_SHARING', true);
60+
try {
61+
$this->ocmDiscoveryService->discover($row['remote'], true);
62+
} catch (OCMProviderException $e) {
63+
$this->logger->info('exception while running files_sharing/lib/BackgroundJob/FederatedSharesDiscoverJob', ['exception' => $e]);
64+
}
5965
}
6066
$result->closeCursor();
6167
}

apps/files_sharing/lib/Controller/ExternalSharesController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ public function testRemote($remote) {
134134
}
135135

136136
if (
137-
$this->testUrl('https://' . $remote . '/ocs-provider/') ||
138-
$this->testUrl('https://' . $remote . '/ocs-provider/index.php') ||
137+
$this->testUrl('https://' . $remote . '/ocm-provider/') ||
138+
$this->testUrl('https://' . $remote . '/ocm-provider/index.php') ||
139139
$this->testUrl('https://' . $remote . '/status.php', true)
140140
) {
141141
return new DataResponse('https');
142142
} elseif (
143-
$this->testUrl('http://' . $remote . '/ocs-provider/') ||
144-
$this->testUrl('http://' . $remote . '/ocs-provider/index.php') ||
143+
$this->testUrl('http://' . $remote . '/ocm-provider/') ||
144+
$this->testUrl('http://' . $remote . '/ocm-provider/index.php') ||
145145
$this->testUrl('http://' . $remote . '/status.php', true)
146146
) {
147147
return new DataResponse('http');

0 commit comments

Comments
 (0)