Skip to content

Commit

Permalink
Merge pull request #46099 from nextcloud/fix/properly-add-accept-shar…
Browse files Browse the repository at this point in the history
…e-interface

fix: Add `acceptShare` as an interface
  • Loading branch information
nickvergessen committed Jul 30, 2024
2 parents b5bc4f3 + 3d136e4 commit cef6753
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@
'OCP\\Share\\IShare' => $baseDir . '/lib/public/Share/IShare.php',
'OCP\\Share\\IShareHelper' => $baseDir . '/lib/public/Share/IShareHelper.php',
'OCP\\Share\\IShareProvider' => $baseDir . '/lib/public/Share/IShareProvider.php',
'OCP\\Share\\IShareProviderSupportsAccept' => $baseDir . '/lib/public/Share/IShareProviderSupportsAccept.php',
'OCP\\Share\\IShareProviderWithNotification' => $baseDir . '/lib/public/Share/IShareProviderWithNotification.php',
'OCP\\Share_Backend' => $baseDir . '/lib/public/Share_Backend.php',
'OCP\\Share_Backend_Collection' => $baseDir . '/lib/public/Share_Backend_Collection.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Share\\IShare' => __DIR__ . '/../../..' . '/lib/public/Share/IShare.php',
'OCP\\Share\\IShareHelper' => __DIR__ . '/../../..' . '/lib/public/Share/IShareHelper.php',
'OCP\\Share\\IShareProvider' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProvider.php',
'OCP\\Share\\IShareProviderSupportsAccept' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderSupportsAccept.php',
'OCP\\Share\\IShareProviderWithNotification' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderWithNotification.php',
'OCP\\Share_Backend' => __DIR__ . '/../../..' . '/lib/public/Share_Backend.php',
'OCP\\Share_Backend_Collection' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_Collection.php',
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IAttributes;
use OCP\Share\IShare;
use OCP\Share\IShareProviderSupportsAccept;
use OCP\Share\IShareProviderWithNotification;
use Psr\Log\LoggerInterface;
use function str_starts_with;
Expand All @@ -38,7 +39,7 @@
*
* @package OC\Share20
*/
class DefaultShareProvider implements IShareProviderWithNotification {
class DefaultShareProvider implements IShareProviderWithNotification, IShareProviderSupportsAccept {
// Special share type for user modified group shares
public const SHARE_TYPE_USERGROUP = 2;

Expand Down
7 changes: 4 additions & 3 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
use OCP\Share\IShareProviderSupportsAccept;
use OCP\Share\IShareProviderWithNotification;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -905,17 +906,17 @@ public function updateShare(IShare $share) {
* @param IShare $share
* @param string $recipientId
* @return IShare The share object
* @throws \InvalidArgumentException
* @throws \InvalidArgumentException Thrown if the provider does not implement `IShareProviderSupportsAccept`
* @since 9.0.0
*/
public function acceptShare(IShare $share, string $recipientId): IShare {
[$providerId,] = $this->splitFullId($share->getFullId());
$provider = $this->factory->getProvider($providerId);

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

$event = new ShareAcceptedEvent($share);
Expand Down
10 changes: 0 additions & 10 deletions lib/public/Share/IShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ public function create(\OCP\Share\IShare $share);
*/
public function update(\OCP\Share\IShare $share);

/**
* Accept a share.
*
* @param IShare $share
* @param string $recipient
* @return IShare The share object
* @since 17.0.0
*/
// public function acceptShare(IShare $share, string $recipient): IShare;

/**
* Delete a share
*
Expand Down
27 changes: 27 additions & 0 deletions lib/public/Share/IShareProviderSupportsAccept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Share;

/**
* Interface IShareProviderSupportsAccept
*
* This interface allows to define IShareProvider that can handle the `acceptShare` method,
* which is available since Nextcloud 17.
*
* @since 30.0.0
*/
interface IShareProviderSupportsAccept extends IShareProvider {
/**
* Accept a share.
*
* @param IShare $share
* @param string $recipient
* @return IShare The share object
* @since 30.0.0
*/
public function acceptShare(IShare $share, string $recipient): IShare;
}
5 changes: 2 additions & 3 deletions lib/public/Share/IShareProviderWithNotification.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Share;

Expand Down

0 comments on commit cef6753

Please sign in to comment.