Skip to content

Commit 06a8c6b

Browse files
committed
Remove related OAuth authorization data upon user deletion
Fixes #12
1 parent f0b6af4 commit 06a8c6b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Classes/Package.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flownative\Canto;
5+
6+
/*
7+
* This file is part of the Flownative.Canto package.
8+
*
9+
* (c) Karsten Dambekalns, Flownative GmbH - www.flownative.com
10+
*
11+
* This package is Open Source Software. For the full copyright and license
12+
* information, please view the LICENSE file which was distributed with this
13+
* source code.
14+
*/
15+
16+
use Doctrine\ORM\EntityManagerInterface;
17+
use Flownative\Canto\Domain\Repository\AccountAuthorizationRepository;
18+
use Flownative\OAuth2\Client\Authorization;
19+
use Neos\Flow\Core\Bootstrap;
20+
use Neos\Flow\Package\Package as BasePackage;
21+
use Neos\Neos\Domain\Model\User;
22+
use Neos\Neos\Domain\Service\UserService;
23+
24+
class Package extends BasePackage
25+
{
26+
/**
27+
* @param Bootstrap $bootstrap The current bootstrap
28+
* @return void
29+
*/
30+
public function boot(Bootstrap $bootstrap)
31+
{
32+
$dispatcher = $bootstrap->getSignalSlotDispatcher();
33+
$dispatcher->connect(
34+
UserService::class,
35+
'userDeleted',
36+
function (User $user) use ($bootstrap) {
37+
$accountAuthorizationRepository = $bootstrap->getObjectManager()->get(AccountAuthorizationRepository::class);
38+
$entityManager = $bootstrap->getObjectManager()->get(EntityManagerInterface::class);
39+
40+
foreach ($user->getAccounts() as $account) {
41+
$accountAuthorization = $accountAuthorizationRepository->findOneByFlowAccountIdentifier($account->getAccountIdentifier());
42+
if ($accountAuthorization !== null) {
43+
$authorizationId = $accountAuthorization->getAuthorizationId();
44+
$authorization = $entityManager->find(Authorization::class, ['authorizationId' => $authorizationId]);
45+
if ($authorization instanceof Authorization) {
46+
$entityManager->remove($authorization);
47+
}
48+
49+
$accountAuthorizationRepository->remove($accountAuthorization);
50+
}
51+
}
52+
},
53+
'',
54+
false
55+
);
56+
}
57+
}

0 commit comments

Comments
 (0)