mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
fix: Move Sharing events to IEventDispatcher
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
44a0a62107
commit
c67c067ee7
4 changed files with 35 additions and 29 deletions
|
|
@ -26,34 +26,46 @@
|
|||
*/
|
||||
namespace OC\Share20;
|
||||
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\File;
|
||||
use OCP\Share;
|
||||
use OCP\Share\IShare;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
class LegacyHooks {
|
||||
/** @var EventDispatcherInterface */
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
|
||||
/**
|
||||
* LegacyHooks constructor.
|
||||
*
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
*/
|
||||
public function __construct(EventDispatcherInterface $eventDispatcher) {
|
||||
public function __construct(IEventDispatcher $eventDispatcher) {
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
|
||||
$this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']);
|
||||
$this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']);
|
||||
$this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']);
|
||||
$this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']);
|
||||
$this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']);
|
||||
$this->eventDispatcher->addListener('OCP\Share::preUnshare', function ($event) {
|
||||
if ($event instanceof GenericEvent) {
|
||||
$this->preUnshare($event);
|
||||
}
|
||||
});
|
||||
$this->eventDispatcher->addListener('OCP\Share::postUnshare', function ($event) {
|
||||
if ($event instanceof GenericEvent) {
|
||||
$this->postUnshare($event);
|
||||
}
|
||||
});
|
||||
$this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', function ($event) {
|
||||
if ($event instanceof GenericEvent) {
|
||||
$this->postUnshareFromSelf($event);
|
||||
}
|
||||
});
|
||||
$this->eventDispatcher->addListener('OCP\Share::preShare', function ($event) {
|
||||
if ($event instanceof GenericEvent) {
|
||||
$this->preShare($event);
|
||||
}
|
||||
});
|
||||
$this->eventDispatcher->addListener('OCP\Share::postShare', function ($event) {
|
||||
if ($event instanceof GenericEvent) {
|
||||
$this->postShare($event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GenericEvent $e
|
||||
*/
|
||||
public function preUnshare(GenericEvent $e) {
|
||||
/** @var IShare $share */
|
||||
$share = $e->getSubject();
|
||||
|
|
@ -62,9 +74,6 @@ class LegacyHooks {
|
|||
\OC_Hook::emit(Share::class, 'pre_unshare', $formatted);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GenericEvent $e
|
||||
*/
|
||||
public function postUnshare(GenericEvent $e) {
|
||||
/** @var IShare $share */
|
||||
$share = $e->getSubject();
|
||||
|
|
@ -83,9 +92,6 @@ class LegacyHooks {
|
|||
\OC_Hook::emit(Share::class, 'post_unshare', $formatted);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GenericEvent $e
|
||||
*/
|
||||
public function postUnshareFromSelf(GenericEvent $e) {
|
||||
/** @var IShare $share */
|
||||
$share = $e->getSubject();
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ class Manager implements IManager {
|
|||
$this->sharingDisabledForUsersCache = new CappedMemoryCache();
|
||||
// The constructor of LegacyHooks registers the listeners of share events
|
||||
// do not remove if those are not properly migrated
|
||||
$this->legacyHooks = new LegacyHooks($this->legacyDispatcher);
|
||||
$this->legacyHooks = new LegacyHooks($dispatcher);
|
||||
$this->mailer = $mailer;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->defaults = $defaults;
|
||||
|
|
@ -194,7 +194,7 @@ class Manager implements IManager {
|
|||
|
||||
// Let others verify the password
|
||||
try {
|
||||
$this->legacyDispatcher->dispatch(new ValidatePasswordPolicyEvent($password));
|
||||
$this->dispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
|
||||
} catch (HintException $e) {
|
||||
throw new \Exception($e->getHint());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ use OC\EventDispatcher\SymfonyAdapter;
|
|||
use OC\Share20\LegacyHooks;
|
||||
use OC\Share20\Manager;
|
||||
use OCP\Constants;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\Cache\ICacheEntry;
|
||||
use OCP\Files\File;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\Share\IShare;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
use Test\TestCase;
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ class LegacyHooksTest extends TestCase {
|
|||
/** @var LegacyHooks */
|
||||
private $hooks;
|
||||
|
||||
/** @var EventDispatcher */
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
|
||||
/** @var Manager */
|
||||
|
|
@ -53,7 +53,7 @@ class LegacyHooksTest extends TestCase {
|
|||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$eventDispatcher = new \OC\EventDispatcher\EventDispatcher($symfonyDispatcher, \OC::$server->get(IServerContainer::class), $logger);
|
||||
$this->eventDispatcher = new SymfonyAdapter($eventDispatcher, $logger);
|
||||
$this->hooks = new LegacyHooks($this->eventDispatcher);
|
||||
$this->hooks = new LegacyHooks($eventDispatcher);
|
||||
$this->manager = \OC::$server->getShareManager();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -545,7 +545,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
['core', 'shareapi_enforce_links_password', 'no', 'no'],
|
||||
]);
|
||||
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')
|
||||
$this->dispatcher->expects($this->once())->method('dispatchTyped')
|
||||
->willReturnCallback(function (Event $event) {
|
||||
$this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
|
||||
/** @var ValidatePasswordPolicyEvent $event */
|
||||
|
|
@ -567,7 +567,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
['core', 'shareapi_enforce_links_password', 'no', 'no'],
|
||||
]);
|
||||
|
||||
$this->eventDispatcher->expects($this->once())->method('dispatch')
|
||||
$this->dispatcher->expects($this->once())->method('dispatchTyped')
|
||||
->willReturnCallback(function (Event $event) {
|
||||
$this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
|
||||
/** @var ValidatePasswordPolicyEvent $event */
|
||||
|
|
|
|||
Loading…
Reference in a new issue