PHRAS-3555 add more webhook events

This commit is contained in:
aynsix
2021-11-16 17:15:49 +03:00
parent 3a5452bae7
commit 074920353a
30 changed files with 896 additions and 153 deletions

View File

@@ -9,10 +9,12 @@
*/
namespace Alchemy\Phrasea\Controller\Root;
use Alchemy\Phrasea\Application\Helper\EntityManagerAware;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\ControllerProvider\Api\V2;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Entities\ApiApplication;
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
use Alchemy\Phrasea\Model\Manipulator\ApiAccountManipulator;
use Alchemy\Phrasea\Model\Manipulator\ApiApplicationManipulator;
use Alchemy\Phrasea\Model\Manipulator\ApiOauthTokenManipulator;
@@ -29,6 +31,8 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
class DeveloperController extends Controller
{
use EntityManagerAware;
/**
* Delete application.
*
@@ -253,9 +257,34 @@ class DeveloperController extends Controller
"deliveries" => $deliveries,
"user" => $user,
"token" => $token,
"webhook_event_list" => $this->getWebhookEventsList()
]);
}
/**
* Update listenedEvents in application
*
* @param Request $request
* @param ApiApplication $application
* @return JsonResponse
*/
public function updateListenedEvent(Request $request, ApiApplication $application)
{
$manager = $this->getEntityManager();
$eventName = $request->query->get('event_name');
if ($request->request->get('action') == 'add') {
$application->addListenedEvent($eventName);
} elseif ($request->request->get('action') == 'remove') {
$application->removeListenedEvent($eventName);
}
$manager->persist($application);
$manager->flush();
return $this->app->json(['success' => true]);
}
/**
* @return ApiAccountRepository
*/
@@ -311,4 +340,37 @@ class DeveloperController extends Controller
{
return $this->app['webhook.delivery_repository'];
}
private function getWebhookEventsList()
{
return [
WebhookEvent::RECORD_TYPE => [
WebhookEvent::RECORD_CREATED => $this->app->trans("developers:: record or story created"),
WebhookEvent::RECORD_EDITED => $this->app->trans('developers:: record or story edited'),
WebhookEvent::RECORD_DELETED => $this->app->trans('developers:: record or story deleted'),
WebhookEvent::RECORD_MEDIA_SUBSTITUTED => $this->app->trans('developers:: media substituted for record'),
WebhookEvent::RECORD_COLLECTION_CHANGED => $this->app->trans('developers:: collection changed for record'),
WebhookEvent::RECORD_STATUS_CHANGED => $this->app->trans('developers:: status changed for record')
],
WebhookEvent::RECORD_SUBDEF_TYPE => [
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_REGISTRATION_TYPE => [
WebhookEvent::USER_REGISTRATION_GRANTED => $this->app->trans('developers:: user registration granted on phraseanet'),
WebhookEvent::USER_REGISTRATION_REJECTED => $this->app->trans('developers:: user registration rejected on phraseanet')
],
WebhookEvent::FEED_ENTRY_TYPE => [
WebhookEvent::NEW_FEED_ENTRY => $this->app->trans('developers:: new feed entry on phraseanet')
],
WebhookEvent::ORDER_TYPE => [
WebhookEvent::ORDER_CREATED => $this->app->trans('developers:: new order created'),
WebhookEvent::ORDER_DELIVERED => $this->app->trans('developers:: a order delivered'),
WebhookEvent::ORDER_DENIED => $this->app->trans('developers:: a order denied')
]
];
}
}