Skip to content
Snippets Groups Projects
Unverified Commit ae233e20 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Remove PersonForExternalServiceEvent

parent 15a95410
No related branches found
No related tags found
No related merge requests found
Pipeline #92541 failed
......@@ -93,62 +93,6 @@ class PersonUserItemSubscriber implements EventSubscriberInterface
}
```
### PersonForExternalServiceEvent
Some integration services may need to fetch a person from an external API with a
`\Dbp\Relay\BasePersonBundle\API\PersonProviderInterface`, for example:
```php
$person = $this->personProvider->getPersonForExternalService('SOME_SERVICE', $userId);
```
To implement such a fetch process from an external API this event can be used.
An event subscriber receives a `\Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonForExternalServiceEvent` instance
in a service for example in `src/EventSubscriber/PersonForExternalServiceSubscriber.php`:
```php
<?php
namespace App\EventSubscriber;
use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonForExternalServiceEvent;
use Dbp\Relay\BasePersonConnectorLdapBundle\Service\LDAPApi;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Service\ExternalApi;
class PersonForExternalServiceSubscriber implements EventSubscriberInterface
{
private $ldap;
private $externalApi;
public function __construct(LDAPApi $ldap, ExternalApi $externalApi)
{
$this->ldap = $ldap;
$this->externalApi = $externalApi;
}
public static function getSubscribedEvents(): array
{
return [
PersonForExternalServiceEvent::NAME => 'onEvent',
];
}
public function onEvent(PersonForExternalServiceEvent $event)
{
$service = $event->getService();
$serviceID = $event->getServiceID();
if ($service === 'SOME_SERVICE') {
$user = $this->externalApi->getPersonUserItemByExternalUserId($serviceID);
$person = $this->ldap->personFromUserItem($user, true);
$event->setPerson($person);
}
}
}
```
### PersonFromUserItemPostEvent
This event allows to modify the person after it is converted from an LDAP User.
......
......@@ -15,7 +15,6 @@ use Adldap\Connections\ProviderInterface;
use Adldap\Models\User;
use Adldap\Query\Builder;
use Dbp\Relay\BasePersonBundle\Entity\Person;
use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonForExternalServiceEvent;
use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPostEvent;
use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPreEvent;
use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonUserItemPreEvent;
......@@ -29,7 +28,6 @@ use Psr\Log\LoggerAwareTrait;
use Symfony\Component\Cache\Psr16Cache;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
......@@ -285,19 +283,6 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface
return $person;
}
public function getPersonForExternalService(string $service, string $serviceID): Person
{
$event = new PersonForExternalServiceEvent($service, $serviceID);
$this->dispatcher->dispatch($event, PersonForExternalServiceEvent::NAME);
$person = $event->getPerson();
if (!$person) {
throw new BadRequestHttpException("Unknown service: $service");
}
return $person;
}
private function getUserSession(): UserSessionInterface
{
return $this->locator->get(UserSessionInterface::class);
......
......@@ -26,11 +26,6 @@ class LDAPPersonProvider implements PersonProviderInterface
return $this->ldapApi->getPerson($id);
}
public function getPersonForExternalService(string $service, string $serviceID): Person
{
return $this->ldapApi->getPersonForExternalService($service, $serviceID);
}
public function getCurrentPerson(): ?Person
{
return $this->ldapApi->getCurrentPerson();
......
......@@ -121,17 +121,6 @@ class PersonTest extends ApiTestCase
$this->assertEquals($person->getExtraData('test'), 'my-test-string');
}
public function testPersonForExternalServiceEvent()
{
$user = new AdldapUser([
'cn' => ['foobar'],
], $this->newBuilder());
$person = $this->api->getPersonForExternalService('test-service', '17');
$this->assertEquals($person->getExtraData('test-service'), 'my-test-service-string-17');
}
// public function testPersonUserItemEvent()
// {
// $user = $this->api->getPersonUserItem('foobar');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment