diff --git a/composer.lock b/composer.lock index f16a382685a1915f688121492965ded0bc182d86..5e05bbc3f676f357553c87f62c809d4681e22965 100644 --- a/composer.lock +++ b/composer.lock @@ -348,11 +348,11 @@ }, { "name": "dbp/relay-base-person-bundle", - "version": "v0.2.5", + "version": "v0.2.6", "source": { "type": "git", "url": "https://gitlab.tugraz.at/dbp/relay/dbp-relay-base-person-bundle", - "reference": "94622ef83ce4b60dd0c599813e44c19e218498fc" + "reference": "d0fbe7236914d9f5343366cd50d6903c41446758" }, "require": { "api-platform/core": "^2.6.3", @@ -393,7 +393,7 @@ "license": [ "AGPL-3.0-or-later" ], - "time": "2022-11-16T10:54:26+00:00" + "time": "2022-11-24T08:50:01+00:00" }, { "name": "dbp/relay-core-bundle", @@ -11149,5 +11149,5 @@ "platform-overrides": { "php": "7.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/Event/PersonForExternalServiceEvent.php b/src/Event/PersonForExternalServiceEvent.php deleted file mode 100644 index cca8c7601e5e769efb2b0e197357fa5c29360ec7..0000000000000000000000000000000000000000 --- a/src/Event/PersonForExternalServiceEvent.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\BasePersonConnectorLdapBundle\Event; - -use Dbp\Relay\BasePersonBundle\Entity\Person; -use Symfony\Contracts\EventDispatcher\Event; - -class PersonForExternalServiceEvent extends Event -{ - public const NAME = 'dbp.relay.base_person_connector_ldap_bundle.person_for_external_service'; - - protected $service; - protected $serviceID; - protected $person; - - public function __construct(string $service, string $serviceID) - { - $this->service = $service; - $this->serviceID = $serviceID; - $this->person = null; - } - - public function getService(): string - { - return $this->service; - } - - public function getServiceID(): string - { - return $this->serviceID; - } - - public function setPerson(Person $person): void - { - $this->person = $person; - } - - public function getPerson(): ?Person - { - return $this->person; - } -} diff --git a/src/Event/PersonFromUserItemPostEvent.php b/src/Event/PersonFromUserItemPostEvent.php deleted file mode 100644 index f278c13752f7180026c54633d04488834092c17e..0000000000000000000000000000000000000000 --- a/src/Event/PersonFromUserItemPostEvent.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\BasePersonConnectorLdapBundle\Event; - -use Dbp\Relay\BasePersonBundle\Entity\Person; -use Dbp\Relay\CoreBundle\LocalData\LocalDataAwarePostEvent; - -class PersonFromUserItemPostEvent extends LocalDataAwarePostEvent -{ - public const NAME = 'dbp.relay.base_person_connector_ldap_bundle.person_from_user_item.post'; - - protected $attributes; - protected $person; - protected $full; - - public function __construct(array $attributes, Person $person, bool $full) - { - parent::__construct($person); - - $this->attributes = $attributes; - $this->person = $person; - $this->full = $full; - } - - public function getAttributes(): array - { - return $this->attributes; - } - - public function getPerson(): Person - { - return $this->person; - } - - public function isFull(): bool - { - return $this->full; - } - - public function setPerson(Person $person): void - { - $this->person = $person; - } - - public function getEntity(): Person - { - return $this->person; - } - - public function getSourceData(): array - { - return $this->attributes; - } -} diff --git a/src/Event/PersonFromUserItemPreEvent.php b/src/Event/PersonFromUserItemPreEvent.php deleted file mode 100644 index 1dd504fc0c06d11e645eb411f1e2ef9e45f527ec..0000000000000000000000000000000000000000 --- a/src/Event/PersonFromUserItemPreEvent.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\BasePersonConnectorLdapBundle\Event; - -use Adldap\Models\User; -use Symfony\Contracts\EventDispatcher\Event; - -/** - * Class PersonFromUserItemPreEvent. - * - * This event is currently disabled! - */ -class PersonFromUserItemPreEvent extends Event -{ - public const NAME = 'dbp.relay.base_person_connector_ldap_bundle.person_from_user_item.pre'; - - protected $user; - protected $full; - - public function __construct(User $user, bool $full) - { - $this->user = $user; - $this->full = $full; - } - - public function getUser(): User - { - return $this->user; - } - - public function isFull(): bool - { - return $this->full; - } - - public function setUser(User $user): void - { - $this->user = $user; - } -} diff --git a/src/Service/LDAPApi.php b/src/Service/LDAPApi.php index 050cf760d9066fa8c8b2a7be282b6f09b40c0c01..a1638ce14e0e3510d03bbf1944255b5dbff944f5 100644 --- a/src/Service/LDAPApi.php +++ b/src/Service/LDAPApi.php @@ -16,7 +16,7 @@ use Adldap\Models\User; use Adldap\Query\Builder; use Adldap\Query\Paginator as AdldapPaginator; use Dbp\Relay\BasePersonBundle\Entity\Person; -use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPostEvent; +use Dbp\Relay\BasePersonBundle\Event\PersonProviderPostEvent; use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonPreEvent; use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonUserItemPreEvent; use Dbp\Relay\CoreBundle\API\UserSessionInterface; @@ -282,10 +282,6 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface public function personFromUserItem(User $user, bool $full): Person { -// $preEvent = new PersonFromUserItemPreEvent($user, $full); -// $this->eventDispatcher->dispatch($preEvent, PersonFromUserItemPreEvent::NAME); -// $user = $preEvent->getUser(); - $identifier = $user->getFirstAttribute($this->identifierAttributeName) ?? ''; $person = new Person(); @@ -316,10 +312,10 @@ class LDAPApi implements LoggerAwareInterface, ServiceSubscriberInterface } } - $postEvent = new PersonFromUserItemPostEvent($attributes, $person, $full); - $this->eventDispatcher->dispatch($postEvent, PersonFromUserItemPostEvent::NAME); + $postEvent = new PersonProviderPostEvent($attributes, $person); + $this->eventDispatcher->dispatch($postEvent, PersonProviderPostEvent::NAME); - return $postEvent->getPerson(); + return $postEvent->getEntity(); } /** diff --git a/src/TestUtils/PersonForExternalServiceSubscriber.php b/src/TestUtils/PersonForExternalServiceSubscriber.php deleted file mode 100644 index 7f8992ef431a289ef932c229c2023457f8e65170..0000000000000000000000000000000000000000 --- a/src/TestUtils/PersonForExternalServiceSubscriber.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Dbp\Relay\BasePersonConnectorLdapBundle\TestUtils; - -use Dbp\Relay\BasePersonBundle\Entity\Person; -use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonForExternalServiceEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -class PersonForExternalServiceSubscriber implements EventSubscriberInterface -{ - public static function getSubscribedEvents(): array - { - return [ - PersonForExternalServiceEvent::NAME => 'onEvent', - ]; - } - - public function onEvent(PersonForExternalServiceEvent $event) - { - $service = $event->getService(); - $serviceID = $event->getServiceID(); - - if ($service === 'test-service') { - $person = new Person(); - $person->setExtraData('test-service', 'my-test-service-string-'.$serviceID); - $event->setPerson($person); - } - } -} diff --git a/src/TestUtils/PersonFromUserItemSubscriber.php b/src/TestUtils/PersonFromUserItemSubscriber.php index 5f0b49f906e396ccaf14235d4d6d25746bca1b62..d771d62b13970a3dcb3b23d7a62252ec35f587b3 100644 --- a/src/TestUtils/PersonFromUserItemSubscriber.php +++ b/src/TestUtils/PersonFromUserItemSubscriber.php @@ -4,8 +4,7 @@ declare(strict_types=1); namespace Dbp\Relay\BasePersonConnectorLdapBundle\TestUtils; -use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPostEvent; -use Dbp\Relay\BasePersonConnectorLdapBundle\Event\PersonFromUserItemPreEvent; +use Dbp\Relay\BasePersonBundle\Event\PersonProviderPostEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class PersonFromUserItemSubscriber implements EventSubscriberInterface @@ -13,22 +12,13 @@ class PersonFromUserItemSubscriber implements EventSubscriberInterface public static function getSubscribedEvents(): array { return [ - PersonFromUserItemPreEvent::NAME => 'onPre', - PersonFromUserItemPostEvent::NAME => 'onPost', + PersonProviderPostEvent::NAME => 'onPost', ]; } - public function onPre(PersonFromUserItemPreEvent $event) + public function onPost(PersonProviderPostEvent $event) { - $user = $event->getUser(); - $user->setCompany('TestCompany'); - $event->setUser($user); - } - - public function onPost(PersonFromUserItemPostEvent $event) - { - $person = $event->getPerson(); + $person = $event->getEntity(); $person->setExtraData('test', 'my-test-string'); - $event->setPerson($person); } } diff --git a/tests/PersonTest.php b/tests/PersonTest.php index 08ddca6005134edc520102089e1c30c18bdbba67..62e9c0b8b3a5896d001ce4a5f4e98975e36b66a8 100644 --- a/tests/PersonTest.php +++ b/tests/PersonTest.php @@ -11,7 +11,6 @@ use Adldap\Query\Grammar; use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase; use Dbp\Relay\BasePersonConnectorLdapBundle\Service\LDAPApi; use Dbp\Relay\BasePersonConnectorLdapBundle\Service\LDAPPersonProvider; -use Dbp\Relay\BasePersonConnectorLdapBundle\TestUtils\PersonForExternalServiceSubscriber; use Dbp\Relay\BasePersonConnectorLdapBundle\TestUtils\PersonFromUserItemSubscriber; use Dbp\Relay\BasePersonConnectorLdapBundle\TestUtils\PersonUserItemSubscriber; use Mockery; @@ -33,11 +32,9 @@ class PersonTest extends ApiTestCase { parent::setUp(); $personFromUserItemSubscriber = new PersonFromUserItemSubscriber(); - $personForExternalServiceSubscriber = new PersonForExternalServiceSubscriber(); $personUserItemSubscriber = new PersonUserItemSubscriber(); $eventDispatcher = new EventDispatcher(); $eventDispatcher->addSubscriber($personFromUserItemSubscriber); - $eventDispatcher->addSubscriber($personForExternalServiceSubscriber); $eventDispatcher->addSubscriber($personUserItemSubscriber); $this->api = new LDAPApi(self::createClient()->getContainer(), $eventDispatcher); @@ -97,17 +94,6 @@ class PersonTest extends ApiTestCase } } -// public function testPersonFromUserItemPreEvent() -// { -// $user = new AdldapUser([ -// 'cn' => ['foobar'], -// ], $this->newBuilder()); -// -// $this->api->personFromUserItem($user, false); -// -// $this->assertEquals($user->getCompany(), 'TestCompany'); -// } - public function testPersonFromUserItemPostEvent() { $user = new AdldapUser([ @@ -120,11 +106,4 @@ class PersonTest extends ApiTestCase $this->assertEquals($person->getExtraData('test'), 'my-test-string'); } - -// public function testPersonUserItemEvent() -// { -// $user = $this->api->getPersonUserItem('foobar'); -// -// $this->assertEquals($user->getName(), 'foobar'); -// } }