Skip to content

Commit ddfe68d

Browse files
committed
fix(ocm): Move out of server invite-accepted capability and implementation.
Signed-off-by: antoonp <[email protected]>
1 parent 3a80443 commit ddfe68d

12 files changed

Lines changed: 55 additions & 380 deletions

File tree

apps/cloud_federation_api/appinfo/routes.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
'verb' => 'POST',
2121
'root' => '/ocm',
2222
],
23-
[
24-
'name' => 'RequestHandler#inviteAccepted',
25-
'url' => '/invite-accepted',
26-
'verb' => 'POST',
27-
'root' => '/ocm',
28-
],
2923

3024
// needs to be kept at the bottom of the list
3125
[

apps/cloud_federation_api/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
'OCA\\CloudFederationAPI\\Config' => $baseDir . '/../lib/Config.php',
1313
'OCA\\CloudFederationAPI\\Controller\\OCMRequestController' => $baseDir . '/../lib/Controller/OCMRequestController.php',
1414
'OCA\\CloudFederationAPI\\Controller\\RequestHandlerController' => $baseDir . '/../lib/Controller/RequestHandlerController.php',
15-
'OCA\\CloudFederationAPI\\Db\\FederatedInvite' => $baseDir . '/../lib/Db/FederatedInvite.php',
16-
'OCA\\CloudFederationAPI\\Db\\FederatedInviteMapper' => $baseDir . '/../lib/Db/FederatedInviteMapper.php',
17-
'OCA\\CloudFederationAPI\\Events\\FederatedInviteAcceptedEvent' => $baseDir . '/../lib/Events/FederatedInviteAcceptedEvent.php',
1815
'OCA\\CloudFederationAPI\\Migration\\Version1016Date202502262004' => $baseDir . '/../lib/Migration/Version1016Date202502262004.php',
16+
'OCA\\CloudFederationAPI\\Migration\\Version1018Date20260202110547' => $baseDir . '/../lib/Migration/Version1018Date20260202110547.php',
1917
'OCA\\CloudFederationAPI\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php',
2018
);

apps/cloud_federation_api/composer/composer/autoload_static.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
class ComposerStaticInitCloudFederationAPI
88
{
99
public static $prefixLengthsPsr4 = array (
10-
'O' =>
10+
'O' =>
1111
array (
1212
'OCA\\CloudFederationAPI\\' => 23,
1313
),
1414
);
1515

1616
public static $prefixDirsPsr4 = array (
17-
'OCA\\CloudFederationAPI\\' =>
17+
'OCA\\CloudFederationAPI\\' =>
1818
array (
1919
0 => __DIR__ . '/..' . '/../lib',
2020
),
@@ -27,10 +27,8 @@ class ComposerStaticInitCloudFederationAPI
2727
'OCA\\CloudFederationAPI\\Config' => __DIR__ . '/..' . '/../lib/Config.php',
2828
'OCA\\CloudFederationAPI\\Controller\\OCMRequestController' => __DIR__ . '/..' . '/../lib/Controller/OCMRequestController.php',
2929
'OCA\\CloudFederationAPI\\Controller\\RequestHandlerController' => __DIR__ . '/..' . '/../lib/Controller/RequestHandlerController.php',
30-
'OCA\\CloudFederationAPI\\Db\\FederatedInvite' => __DIR__ . '/..' . '/../lib/Db/FederatedInvite.php',
31-
'OCA\\CloudFederationAPI\\Db\\FederatedInviteMapper' => __DIR__ . '/..' . '/../lib/Db/FederatedInviteMapper.php',
32-
'OCA\\CloudFederationAPI\\Events\\FederatedInviteAcceptedEvent' => __DIR__ . '/..' . '/../lib/Events/FederatedInviteAcceptedEvent.php',
3330
'OCA\\CloudFederationAPI\\Migration\\Version1016Date202502262004' => __DIR__ . '/..' . '/../lib/Migration/Version1016Date202502262004.php',
31+
'OCA\\CloudFederationAPI\\Migration\\Version1018Date20260202110547' => __DIR__ . '/..' . '/../lib/Migration/Version1018Date20260202110547.php',
3432
'OCA\\CloudFederationAPI\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php',
3533
);
3634

apps/cloud_federation_api/lib/AppInfo/Application.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99
namespace OCA\CloudFederationAPI\AppInfo;
1010

11-
use OCA\CloudFederationAPI\Capabilities;
1211
use OCP\AppFramework\App;
1312
use OCP\AppFramework\Bootstrap\IBootContext;
1413
use OCP\AppFramework\Bootstrap\IBootstrap;
@@ -22,7 +21,6 @@ public function __construct() {
2221
}
2322

2423
public function register(IRegistrationContext $context): void {
25-
$context->registerCapability(Capabilities::class);
2624
}
2725

2826
public function boot(IBootContext $context): void {

apps/cloud_federation_api/lib/Controller/RequestHandlerController.php

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99

1010
use OC\OCM\OCMSignatoryManager;
1111
use OCA\CloudFederationAPI\Config;
12-
use OCA\CloudFederationAPI\Db\FederatedInviteMapper;
13-
use OCA\CloudFederationAPI\Events\FederatedInviteAcceptedEvent;
1412
use OCA\CloudFederationAPI\ResponseDefinitions;
1513
use OCA\FederatedFileSharing\AddressHandler;
1614
use OCP\AppFramework\Controller;
17-
use OCP\AppFramework\Db\DoesNotExistException;
1815
use OCP\AppFramework\Http;
1916
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
2017
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
2118
use OCP\AppFramework\Http\Attribute\OpenAPI;
2219
use OCP\AppFramework\Http\Attribute\PublicPage;
2320
use OCP\AppFramework\Http\JSONResponse;
2421
use OCP\AppFramework\Utility\ITimeFactory;
25-
use OCP\EventDispatcher\IEventDispatcher;
2622
use OCP\Federation\Exceptions\ActionNotSupportedException;
2723
use OCP\Federation\Exceptions\AuthenticationFailedException;
2824
use OCP\Federation\Exceptions\BadRequestException;
@@ -67,8 +63,6 @@ public function __construct(
6763
private IURLGenerator $urlGenerator,
6864
private ICloudFederationProviderManager $cloudFederationProviderManager,
6965
private Config $config,
70-
private IEventDispatcher $dispatcher,
71-
private FederatedInviteMapper $federatedInviteMapper,
7266
private readonly AddressHandler $addressHandler,
7367
private readonly IAppConfig $appConfig,
7468
private ICloudFederationFactory $factory,
@@ -225,101 +219,6 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $
225219
return new JSONResponse($responseData, Http::STATUS_CREATED);
226220
}
227221

228-
/**
229-
* Inform the sender that an invitation was accepted to start sharing
230-
*
231-
* Inform about an accepted invitation so the user on the sender provider's side
232-
* can initiate the OCM share creation. To protect the identity of the parties,
233-
* for shares created following an OCM invitation, the user id MAY be hashed,
234-
* and recipients implementing the OCM invitation workflow MAY refuse to process
235-
* shares coming from unknown parties.
236-
* @link https://cs3org.github.io/OCM-API/docs.html?branch=v1.1.0&repo=OCM-API&user=cs3org#/paths/~1invite-accepted/post
237-
*
238-
* @param string $recipientProvider The address of the recipent's provider
239-
* @param string $token The token used for the invitation
240-
* @param string $userID The userID of the recipient at the recipient's provider
241-
* @param string $email The email address of the recipient
242-
* @param string $name The display name of the recipient
243-
*
244-
* @return JSONResponse<Http::STATUS_OK, array{userID: string, email: string, name: string}, array{}>|JSONResponse<Http::STATUS_FORBIDDEN|Http::STATUS_BAD_REQUEST|Http::STATUS_CONFLICT, array{message: string, error: true}, array{}>
245-
*
246-
* Note: Not implementing 404 Invitation token does not exist, instead using 400
247-
* 200: Invitation accepted
248-
* 400: Invalid token
249-
* 403: Invitation token does not exist
250-
* 409: User is already known by the OCM provider
251-
*/
252-
#[PublicPage]
253-
#[NoCSRFRequired]
254-
#[BruteForceProtection(action: 'inviteAccepted')]
255-
public function inviteAccepted(string $recipientProvider, string $token, string $userID, string $email, string $name): JSONResponse {
256-
$this->logger->debug('Processing share invitation for ' . $userID . ' with token ' . $token . ' and email ' . $email . ' and name ' . $name);
257-
258-
$updated = $this->timeFactory->getTime();
259-
260-
if ($token === '') {
261-
$response = new JSONResponse(['message' => 'Invalid or non existing token', 'error' => true], Http::STATUS_BAD_REQUEST);
262-
$response->throttle();
263-
return $response;
264-
}
265-
266-
try {
267-
$invitation = $this->federatedInviteMapper->findByToken($token);
268-
} catch (DoesNotExistException) {
269-
$response = ['message' => 'Invalid or non existing token', 'error' => true];
270-
$status = Http::STATUS_BAD_REQUEST;
271-
$response = new JSONResponse($response, $status);
272-
$response->throttle();
273-
return $response;
274-
}
275-
276-
if ($invitation->isAccepted() === true) {
277-
$response = ['message' => 'Invite already accepted', 'error' => true];
278-
$status = Http::STATUS_CONFLICT;
279-
return new JSONResponse($response, $status);
280-
}
281-
282-
if ($invitation->getExpiredAt() !== null && $updated > $invitation->getExpiredAt()) {
283-
$response = ['message' => 'Invitation expired', 'error' => true];
284-
$status = Http::STATUS_BAD_REQUEST;
285-
return new JSONResponse($response, $status);
286-
}
287-
$localUser = $this->userManager->get($invitation->getUserId());
288-
if ($localUser === null) {
289-
$response = ['message' => 'Invalid or non existing token', 'error' => true];
290-
$status = Http::STATUS_BAD_REQUEST;
291-
$response = new JSONResponse($response, $status);
292-
$response->throttle();
293-
return $response;
294-
}
295-
296-
$sharedFromEmail = $localUser->getEMailAddress();
297-
if ($sharedFromEmail === null) {
298-
$response = ['message' => 'Invalid or non existing token', 'error' => true];
299-
$status = Http::STATUS_BAD_REQUEST;
300-
$response = new JSONResponse($response, $status);
301-
$response->throttle();
302-
return $response;
303-
}
304-
$sharedFromDisplayName = $localUser->getDisplayName();
305-
306-
$response = ['userID' => $localUser->getUID(), 'email' => $sharedFromEmail, 'name' => $sharedFromDisplayName];
307-
$status = Http::STATUS_OK;
308-
309-
$invitation->setAccepted(true);
310-
$invitation->setRecipientEmail($email);
311-
$invitation->setRecipientName($name);
312-
$invitation->setRecipientProvider($recipientProvider);
313-
$invitation->setRecipientUserId($userID);
314-
$invitation->setAcceptedAt($updated);
315-
$invitation = $this->federatedInviteMapper->update($invitation);
316-
317-
$event = new FederatedInviteAcceptedEvent($invitation);
318-
$this->dispatcher->dispatchTyped($event);
319-
320-
return new JSONResponse($response, $status);
321-
}
322-
323222
/**
324223
* Send a notification about an existing share
325224
*

apps/cloud_federation_api/lib/Db/FederatedInvite.php

Lines changed: 0 additions & 62 deletions
This file was deleted.

apps/cloud_federation_api/lib/Db/FederatedInviteMapper.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

apps/cloud_federation_api/lib/Events/FederatedInviteAcceptedEvent.php

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\CloudFederationAPI\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\Attributes\DropTable;
15+
use OCP\Migration\IOutput;
16+
use OCP\Migration\SimpleMigrationStep;
17+
use Override;
18+
19+
#[DropTable(table: 'federated_invites', columns: ['id', 'user_id', 'recipient_provider', 'recipient_user_id', 'recipient_name', 'recipient_email', 'token', 'accepted', 'created_at', 'expired_at', 'accepted_at'], description: 'Table is moved out of this app.')]
20+
class Version1018Date20260202110547 extends SimpleMigrationStep {
21+
/**
22+
* @param IOutput $output
23+
* @param Closure(): ISchemaWrapper $schemaClosure
24+
* @param array $options
25+
* @return null|ISchemaWrapper
26+
*/
27+
#[Override]
28+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
29+
/** @var ISchemaWrapper $schema */
30+
$schema = $schemaClosure();
31+
$table_name = 'federated_invites';
32+
33+
if ($schema->hasTable($table_name)) {
34+
$schema->dropTable($table_name);
35+
return $schema;
36+
}
37+
return null;
38+
}
39+
}

0 commit comments

Comments
 (0)