mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
PHRAS-1239 Add webhook for user deleted events
This commit is contained in:
@@ -26,6 +26,7 @@ use Alchemy\Phrasea\Core\Event\Subscriber\LazaretSubscriber;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaInstallSubscriber;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\RegistrationSubscriber;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\ValidationSubscriber;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\WebhookUserEventSubscriber;
|
||||
use Alchemy\Phrasea\Core\MetaProvider\DatabaseMetaProvider;
|
||||
use Alchemy\Phrasea\Core\MetaProvider\HttpStackMetaProvider;
|
||||
use Alchemy\Phrasea\Core\MetaProvider\MediaUtilitiesMetaServiceProvider;
|
||||
@@ -717,6 +718,7 @@ class Application extends SilexApplication
|
||||
$dispatcher->addSubscriber(new BasketSubscriber($app));
|
||||
$dispatcher->addSubscriber(new LazaretSubscriber($app));
|
||||
$dispatcher->addSubscriber(new ValidationSubscriber($app));
|
||||
$dispatcher->addSubscriber(new WebhookUserEventSubscriber($app));
|
||||
|
||||
return $dispatcher;
|
||||
})
|
||||
|
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of phrasea-4.0.
|
||||
*
|
||||
* (c) Alchemy <info@alchemy.fr>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Event\Subscriber;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Core\Event\User\DeletedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\User\UserEvents;
|
||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||
use Alchemy\Phrasea\Model\Manipulator\WebhookEventManipulator;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class WebhookUserEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* @param Application $application
|
||||
*/
|
||||
public function __construct(Application $application)
|
||||
{
|
||||
$this->app = $application;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DeletedEvent $event
|
||||
*/
|
||||
public function onUserDeleted(DeletedEvent $event)
|
||||
{
|
||||
/** @var WebhookEventManipulator $manipulator */
|
||||
$manipulator = $this->app['manipulator.webhook-event'];
|
||||
|
||||
$manipulator->create(WebhookEvent::USER_DELETED, WebhookEvent::USER_DELETED_TYPE, [
|
||||
'user_id' => $event->getUserId(),
|
||||
'email' => $event->getEmailAddress(),
|
||||
'login' => $event->getLogin()
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
UserEvents::DELETED => 'onUserDeleted'
|
||||
];
|
||||
}
|
||||
}
|
@@ -10,6 +10,7 @@ use Alchemy\Phrasea\Webhook\Processor\FeedEntryProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\OrderNotificationProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\ProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\ProcessorInterface;
|
||||
use Alchemy\Phrasea\Webhook\Processor\UserDeletedProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\UserRegistrationProcessorFactory;
|
||||
|
||||
class EventProcessorFactory
|
||||
@@ -28,6 +29,7 @@ class EventProcessorFactory
|
||||
$this->registerFactory(WebhookEvent::FEED_ENTRY_TYPE, new FeedEntryProcessorFactory($app));
|
||||
$this->registerFactory(WebhookEvent::USER_REGISTRATION_TYPE, new UserRegistrationProcessorFactory($app));
|
||||
$this->registerFactory(WebhookEvent::ORDER_TYPE, new OrderNotificationProcessorFactory($app));
|
||||
$this->registerFactory(WebhookEvent::USER_DELETED_TYPE, new UserDeletedProcessorFactory($app));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of phrasea-4.0.
|
||||
*
|
||||
* (c) Alchemy <info@alchemy.fr>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Webhook\Processor;
|
||||
|
||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||
|
||||
class UserDeletedProcessor implements ProcessorInterface
|
||||
{
|
||||
|
||||
public function process(WebhookEvent $event)
|
||||
{
|
||||
$data = $event->getData();
|
||||
|
||||
if (! isset($data['user_id'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array(
|
||||
'event' => $event->getName(),
|
||||
'user' => array(
|
||||
'id' => $data['user_id'],
|
||||
'email' => $data['email'],
|
||||
'login' => $data['login']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of phrasea-4.0.
|
||||
*
|
||||
* (c) Alchemy <info@alchemy.fr>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Webhook\Processor;
|
||||
|
||||
class UserDeletedProcessorFactory implements ProcessorFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* @return ProcessorInterface
|
||||
*/
|
||||
public function createProcessor()
|
||||
{
|
||||
return new UserDeletedProcessor();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user