Merge pull request #26125 from nextcloud/backport/25533/stable20
[stable20] send share notification instead of erroring on duplicate share
This commit is contained in:
commit
f088b942cb
|
@ -468,6 +468,7 @@ return array(
|
|||
'OCP\\Share' => $baseDir . '/lib/public/Share.php',
|
||||
'OCP\\Share\\Events\\ShareCreatedEvent' => $baseDir . '/lib/public/Share/Events/ShareCreatedEvent.php',
|
||||
'OCP\\Share\\Events\\VerifyMountPointEvent' => $baseDir . '/lib/public/Share/Events/VerifyMountPointEvent.php',
|
||||
'OCP\\Share\\Exceptions\\AlreadySharedException' => $baseDir . '/lib/public/Share/Exceptions/AlreadySharedException.php',
|
||||
'OCP\\Share\\Exceptions\\GenericShareException' => $baseDir . '/lib/public/Share/Exceptions/GenericShareException.php',
|
||||
'OCP\\Share\\Exceptions\\IllegalIDChangeException' => $baseDir . '/lib/public/Share/Exceptions/IllegalIDChangeException.php',
|
||||
'OCP\\Share\\Exceptions\\ShareNotFound' => $baseDir . '/lib/public/Share/Exceptions/ShareNotFound.php',
|
||||
|
|
|
@ -497,6 +497,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
|||
'OCP\\Share' => __DIR__ . '/../../..' . '/lib/public/Share.php',
|
||||
'OCP\\Share\\Events\\ShareCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/ShareCreatedEvent.php',
|
||||
'OCP\\Share\\Events\\VerifyMountPointEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/VerifyMountPointEvent.php',
|
||||
'OCP\\Share\\Exceptions\\AlreadySharedException' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/AlreadySharedException.php',
|
||||
'OCP\\Share\\Exceptions\\GenericShareException' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/GenericShareException.php',
|
||||
'OCP\\Share\\Exceptions\\IllegalIDChangeException' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/IllegalIDChangeException.php',
|
||||
'OCP\\Share\\Exceptions\\ShareNotFound' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/ShareNotFound.php',
|
||||
|
|
|
@ -63,6 +63,7 @@ use OCP\Security\Events\ValidatePasswordPolicyEvent;
|
|||
use OCP\Security\IHasher;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use OCP\Share;
|
||||
use OCP\Share\Exceptions\AlreadySharedException;
|
||||
use OCP\Share\Exceptions\GenericShareException;
|
||||
use OCP\Share\Exceptions\ShareNotFound;
|
||||
use OCP\Share\IManager;
|
||||
|
@ -564,7 +565,7 @@ class Manager implements IManager {
|
|||
|
||||
// Identical share already existst
|
||||
if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) {
|
||||
throw new \Exception('Path is already shared with this user');
|
||||
throw new AlreadySharedException('Path is already shared with this user', $existingShare);
|
||||
}
|
||||
|
||||
// The share is already shared with this user via a group share
|
||||
|
@ -574,7 +575,7 @@ class Manager implements IManager {
|
|||
$user = $this->userManager->get($share->getSharedWith());
|
||||
|
||||
if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) {
|
||||
throw new \Exception('Path is already shared with this user');
|
||||
throw new AlreadySharedException('Path is already shared with this user', $existingShare);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -619,7 +620,7 @@ class Manager implements IManager {
|
|||
}
|
||||
|
||||
if ($existingShare->getSharedWith() === $share->getSharedWith() && $existingShare->getShareType() === $share->getShareType()) {
|
||||
throw new \Exception('Path is already shared with this group');
|
||||
throw new AlreadySharedException('Path is already shared with this group', $existingShare);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -733,6 +734,7 @@ class Manager implements IManager {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
//Verify share type
|
||||
if ($share->getShareType() === IShare::TYPE_USER) {
|
||||
$this->userCreateChecks($share);
|
||||
|
@ -805,6 +807,10 @@ class Manager implements IManager {
|
|||
if ($share->getTarget() === '') {
|
||||
$share->setTarget($target);
|
||||
}
|
||||
} catch (AlreadySharedException $e) {
|
||||
// if a share for the same target already exists, dont create a new one, but do trigger the hooks and notifications again
|
||||
$share = $e->getExistingShare();
|
||||
}
|
||||
|
||||
// Post share event
|
||||
$event = new GenericEvent($share);
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCP\Share\Exceptions;
|
||||
|
||||
use OCP\Share\IShare;
|
||||
|
||||
/**
|
||||
* @since 22.0.0
|
||||
*/
|
||||
class AlreadySharedException extends GenericShareException {
|
||||
/** @var IShare */
|
||||
private $existingShare;
|
||||
|
||||
/**
|
||||
* @since 22.0.0
|
||||
*/
|
||||
public function __construct(string $message, IShare $existingShare) {
|
||||
parent::__construct($message);
|
||||
|
||||
$this->existingShare = $existingShare;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 22.0.0
|
||||
*/
|
||||
public function getExistingShare(): IShare {
|
||||
return $this->existingShare;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue