-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from flownative/task/remove-authorization-on-u…
…ser-deletion Remove related OAuth authorization data upon user deletion
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Flownative\Canto; | ||
|
||
/* | ||
* This file is part of the Flownative.Canto package. | ||
* | ||
* (c) Karsten Dambekalns, Flownative GmbH - www.flownative.com | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Flownative\Canto\Domain\Repository\AccountAuthorizationRepository; | ||
use Flownative\OAuth2\Client\Authorization; | ||
use Neos\Flow\Core\Bootstrap; | ||
use Neos\Flow\Package\Package as BasePackage; | ||
use Neos\Neos\Domain\Model\User; | ||
use Neos\Neos\Domain\Service\UserService; | ||
|
||
class Package extends BasePackage | ||
{ | ||
/** | ||
* @param Bootstrap $bootstrap The current bootstrap | ||
* @return void | ||
*/ | ||
public function boot(Bootstrap $bootstrap) | ||
{ | ||
$dispatcher = $bootstrap->getSignalSlotDispatcher(); | ||
$dispatcher->connect( | ||
UserService::class, | ||
'userDeleted', | ||
function (User $user) use ($bootstrap) { | ||
$accountAuthorizationRepository = $bootstrap->getObjectManager()->get(AccountAuthorizationRepository::class); | ||
$entityManager = $bootstrap->getObjectManager()->get(EntityManagerInterface::class); | ||
|
||
foreach ($user->getAccounts() as $account) { | ||
$accountAuthorization = $accountAuthorizationRepository->findOneByFlowAccountIdentifier($account->getAccountIdentifier()); | ||
if ($accountAuthorization !== null) { | ||
$authorizationId = $accountAuthorization->getAuthorizationId(); | ||
$authorization = $entityManager->find(Authorization::class, ['authorizationId' => $authorizationId]); | ||
if ($authorization instanceof Authorization) { | ||
$entityManager->remove($authorization); | ||
} | ||
|
||
$accountAuthorizationRepository->remove($accountAuthorization); | ||
} | ||
} | ||
}, | ||
'', | ||
false | ||
); | ||
} | ||
} |