mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
add user.created webhook, merge user type
This commit is contained in:
@@ -356,8 +356,9 @@ class DeveloperController extends Controller
|
||||
WebhookEvent::RECORD_SUBDEF_CREATED => $this->app->trans('developers:: subdef created for a record'),
|
||||
WebhookEvent::RECORD_SUBDEF_FAILED => $this->app->trans('developers:: subdef creation failed for a record'),
|
||||
],
|
||||
WebhookEvent::USER_DELETED_TYPE => [
|
||||
WebhookEvent::USER_DELETED => $this->app->trans('developers:: user deleted on phraseanet')
|
||||
WebhookEvent::USER_TYPE => [
|
||||
WebhookEvent::USER_CREATED => $this->app->trans('developers:: new user created'),
|
||||
WebhookEvent::USER_DELETED => $this->app->trans('developers:: user deleted on phraseanet')
|
||||
],
|
||||
WebhookEvent::USER_REGISTRATION_TYPE => [
|
||||
WebhookEvent::USER_REGISTRATION_GRANTED => $this->app->trans('developers:: user registration granted on phraseanet'),
|
||||
|
@@ -12,6 +12,7 @@
|
||||
namespace Alchemy\Phrasea\Core\Event\Subscriber;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Core\Event\User\CreatedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\User\DeletedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\User\UserEvents;
|
||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||
@@ -41,17 +42,31 @@ class WebhookUserEventSubscriber implements EventSubscriberInterface
|
||||
/** @var WebhookEventManipulator $manipulator */
|
||||
$manipulator = $this->app['manipulator.webhook-event'];
|
||||
|
||||
$manipulator->create(WebhookEvent::USER_DELETED, WebhookEvent::USER_DELETED_TYPE, [
|
||||
$manipulator->create(WebhookEvent::USER_DELETED, WebhookEvent::USER_TYPE, [
|
||||
'user_id' => $event->getUserId(),
|
||||
'email' => $event->getEmailAddress(),
|
||||
'login' => $event->getLogin()
|
||||
], $event->getGrantedBaseIds());
|
||||
}
|
||||
|
||||
public function onUserCreated(CreatedEvent $event)
|
||||
{
|
||||
/** @var WebhookEventManipulator $manipulator */
|
||||
$manipulator = $this->app['manipulator.webhook-event'];
|
||||
|
||||
$user = $event->getUser();
|
||||
$manipulator->create(WebhookEvent::USER_CREATED, WebhookEvent::USER_TYPE, [
|
||||
'user_id' => $user->getId(),
|
||||
'email' => $user->getEmail(),
|
||||
'login' => $user->getLogin()
|
||||
], []);
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
UserEvents::DELETED => 'onUserDeleted'
|
||||
UserEvents::DELETED => 'onUserDeleted',
|
||||
UserEvents::CREATED => 'onUserCreated'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -18,9 +18,6 @@ class WebhookEvent
|
||||
const USER_REGISTRATION_REJECTED = 'user.registration.rejected';
|
||||
const USER_REGISTRATION_TYPE = 'user.registration';
|
||||
|
||||
const USER_DELETED = 'user.deleted';
|
||||
const USER_DELETED_TYPE = 'user.deleted';
|
||||
|
||||
const RECORD_SUBDEF_CREATED = 'record.subdef.created';
|
||||
const RECORD_SUBDEF_FAILED = 'record.subdef.creation_failed';
|
||||
const RECORD_SUBDEFS_CREATED = 'record.subdefs.created';
|
||||
@@ -31,6 +28,10 @@ class WebhookEvent
|
||||
const ORDER_DELIVERED = 'order.delivered';
|
||||
const ORDER_DENIED = 'order.denied';
|
||||
|
||||
const USER_TYPE = 'user';
|
||||
const USER_CREATED = 'user.created';
|
||||
const USER_DELETED = 'user.deleted';
|
||||
|
||||
// const use only as name and type of a webhook
|
||||
const RECORD_TYPE = 'record';
|
||||
const RECORD_CREATED = 'record.created';
|
||||
|
@@ -12,6 +12,7 @@ use Alchemy\Phrasea\Webhook\Processor\ProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\ProcessorInterface;
|
||||
use Alchemy\Phrasea\Webhook\Processor\RecordEventProcessor;
|
||||
use Alchemy\Phrasea\Webhook\Processor\UserDeletedProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\UserProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\UserRegistrationProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\SubdefEventProcessor;
|
||||
|
||||
@@ -31,7 +32,8 @@ 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());
|
||||
|
||||
$this->registerFactory(WebhookEvent::USER_TYPE, new UserProcessorFactory());
|
||||
$this->registerCallableFactory(WebhookEvent::RECORD_SUBDEF_TYPE, function () {
|
||||
return new SubdefEventProcessor();
|
||||
});
|
||||
|
@@ -1,24 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
28
lib/Alchemy/Phrasea/Webhook/Processor/UserProcessor.php
Normal file
28
lib/Alchemy/Phrasea/Webhook/Processor/UserProcessor.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Webhook\Processor;
|
||||
|
||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||
|
||||
class UserProcessor implements ProcessorInterface
|
||||
{
|
||||
|
||||
public function process(WebhookEvent $event)
|
||||
{
|
||||
$data = $event->getData();
|
||||
|
||||
if (! isset($data['user_id'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array(
|
||||
'event' => $event->getName(),
|
||||
'user' => [
|
||||
'id' => $data['user_id'],
|
||||
'email' => $data['email'],
|
||||
'login' => $data['login'],
|
||||
],
|
||||
'time' => $data['time']
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Webhook\Processor;
|
||||
|
||||
class UserProcessorFactory implements ProcessorFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* @return ProcessorInterface|UserProcessor
|
||||
*/
|
||||
public function createProcessor()
|
||||
{
|
||||
return new UserProcessor();
|
||||
}
|
||||
}
|
@@ -12,6 +12,6 @@ class WebhookEventRepositoryTest extends \PhraseanetTestCase
|
||||
{
|
||||
$events = self::$DI['app']['orm.em']->getRepository('Phraseanet:WebhookEvent')->findUnprocessedEvents();
|
||||
// I have no clue as to why this magic number is here, probably best to discard test
|
||||
$this->assertCount(48, $events);
|
||||
$this->assertCount(55, $events);
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,10 @@ class EventProcessorFactoryTest extends \PhraseanetTestCase
|
||||
{
|
||||
return [
|
||||
[WebhookEvent::FEED_ENTRY_TYPE, 'Alchemy\Phrasea\Webhook\Processor\FeedEntryProcessor'],
|
||||
[WebhookEvent::RECORD_TYPE, 'Alchemy\Phrasea\Webhook\Processor\RecordEventProcessor'],
|
||||
[WebhookEvent::RECORD_SUBDEF_TYPE, 'Alchemy\Phrasea\Webhook\Processor\SubdefEventProcessor'],
|
||||
[WebhookEvent::ORDER_TYPE, 'Alchemy\Phrasea\Webhook\Processor\OrderNotificationProcessor'],
|
||||
[WebhookEvent::USER_TYPE, 'Alchemy\Phrasea\Webhook\Processor\UserProcessor']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user