Skip to content

Commit d1237d6

Browse files
committed
fix: Add acceptShare as an interface
It was commented out because at that time no other share provider supported the `acceptShare` method. Today it is the same no other provider supports it, but we should make it discoverable by adding it to the public API as an additional interface. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 21f558b commit d1237d6

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

lib/private/Share20/DefaultShareProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCP\Share\Exceptions\ShareNotFound;
3030
use OCP\Share\IAttributes;
3131
use OCP\Share\IShare;
32+
use OCP\Share\IShareProviderSupportsAccept;
3233
use OCP\Share\IShareProviderWithNotification;
3334
use Psr\Log\LoggerInterface;
3435
use function str_starts_with;
@@ -38,7 +39,7 @@
3839
*
3940
* @package OC\Share20
4041
*/
41-
class DefaultShareProvider implements IShareProviderWithNotification {
42+
class DefaultShareProvider implements IShareProviderWithNotification, IShareProviderSupportsAccept {
4243
// Special share type for user modified group shares
4344
public const SHARE_TYPE_USERGROUP = 2;
4445

lib/private/Share20/Manager.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OCP\Share\IProviderFactory;
4545
use OCP\Share\IShare;
4646
use OCP\Share\IShareProvider;
47+
use OCP\Share\IShareProviderSupportsAccept;
4748
use OCP\Share\IShareProviderWithNotification;
4849
use Psr\Log\LoggerInterface;
4950

@@ -905,17 +906,17 @@ public function updateShare(IShare $share) {
905906
* @param IShare $share
906907
* @param string $recipientId
907908
* @return IShare The share object
908-
* @throws \InvalidArgumentException
909+
* @throws \InvalidArgumentException Thrown if the provider does not implement `IShareProviderSupportsAccept`
909910
* @since 9.0.0
910911
*/
911912
public function acceptShare(IShare $share, string $recipientId): IShare {
912913
[$providerId,] = $this->splitFullId($share->getFullId());
913914
$provider = $this->factory->getProvider($providerId);
914915

915-
if (!method_exists($provider, 'acceptShare')) {
916-
// TODO FIX ME
916+
if (!($provider instanceof IShareProviderSupportsAccept)) {
917917
throw new \InvalidArgumentException('Share provider does not support accepting');
918918
}
919+
/** @var IShareProvider&IShareProviderSupportsAccept $provider */
919920
$provider->acceptShare($share, $recipientId);
920921

921922
$event = new ShareAcceptedEvent($share);

lib/public/Share/IShareProvider.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ public function create(\OCP\Share\IShare $share);
4444
*/
4545
public function update(\OCP\Share\IShare $share);
4646

47-
/**
48-
* Accept a share.
49-
*
50-
* @param IShare $share
51-
* @param string $recipient
52-
* @return IShare The share object
53-
* @since 17.0.0
54-
*/
55-
// public function acceptShare(IShare $share, string $recipient): IShare;
56-
5747
/**
5848
* Delete a share
5949
*
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
namespace OCP\Share;
8+
9+
/**
10+
* Interface IShareProviderSupportsAccept
11+
*
12+
* This interface allows to define IShareProvider that can handle the `acceptShare` method,
13+
* which is available since Nextcloud 17.
14+
*
15+
* @since 30.0.0
16+
*/
17+
interface IShareProviderSupportsAccept extends IShareProvider {
18+
/**
19+
* Accept a share.
20+
*
21+
* @param IShare $share
22+
* @param string $recipient
23+
* @return IShare The share object
24+
* @since 30.0.0
25+
*/
26+
public function acceptShare(IShare $share, string $recipient): IShare;
27+
}

lib/public/Share/IShareProviderWithNotification.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22

33
/**
4-
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
5-
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
6-
* SPDX-License-Identifier: AGPL-3.0-only
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
76
*/
87
namespace OCP\Share;
98

0 commit comments

Comments
 (0)