From 393f44f1f6b28aa5c19faae48d0eccc17da0835f Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 25 Jun 2024 12:40:27 +0200 Subject: [PATCH] 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 --- lib/private/Share20/DefaultShareProvider.php | 3 ++- lib/private/Share20/Manager.php | 7 ++--- lib/public/Share/IShareProvider.php | 10 ------- .../Share/IShareProviderSupportsAccept.php | 27 +++++++++++++++++++ .../Share/IShareProviderWithNotification.php | 5 ++-- 5 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 lib/public/Share/IShareProviderSupportsAccept.php diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 658353b9a26d5..366b9cad976b1 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -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; @@ -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; diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index db129709cdab8..e76f4586dfded 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -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; @@ -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); diff --git a/lib/public/Share/IShareProvider.php b/lib/public/Share/IShareProvider.php index c51bad8f9ef80..9d7c8013a36ec 100644 --- a/lib/public/Share/IShareProvider.php +++ b/lib/public/Share/IShareProvider.php @@ -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 * diff --git a/lib/public/Share/IShareProviderSupportsAccept.php b/lib/public/Share/IShareProviderSupportsAccept.php new file mode 100644 index 0000000000000..0ba6a9d7fed06 --- /dev/null +++ b/lib/public/Share/IShareProviderSupportsAccept.php @@ -0,0 +1,27 @@ +