diff --git a/lib/Alchemy/Phrasea/Account/AccountService.php b/lib/Alchemy/Phrasea/Account/AccountService.php index 4c0e594e64..567a404a94 100644 --- a/lib/Alchemy/Phrasea/Account/AccountService.php +++ b/lib/Alchemy/Phrasea/Account/AccountService.php @@ -167,11 +167,11 @@ class AccountService * @param string $login * @throws AccountException */ - public function deleteAccount($login = null) + public function deleteAccount($login = null, array $grantedBaseIdList = array()) { $user = $this->getUserOrCurrentUser($login); - $this->userManipulator->delete($user); + $this->userManipulator->delete($user, $grantedBaseIdList); } /** diff --git a/lib/Alchemy/Phrasea/Authentication/RegistrationService.php b/lib/Alchemy/Phrasea/Authentication/RegistrationService.php index 7ffdf8c489..2ffe87f0cd 100644 --- a/lib/Alchemy/Phrasea/Authentication/RegistrationService.php +++ b/lib/Alchemy/Phrasea/Authentication/RegistrationService.php @@ -328,11 +328,9 @@ class RegistrationService $autoReg = $acl->get_granted_base(); - $granted = []; foreach ($autoReg as $baseId => $collection) { $granted[$baseId] = $collection->get_label($this->app['locale']); - } - if(count($granted) > 0) { + $this->app['manipulator.webhook-event']->create( WebhookEvent::USER_REGISTRATION_GRANTED, WebhookEvent::USER_REGISTRATION_TYPE, @@ -340,8 +338,11 @@ class RegistrationService 'user_id' => $user->getId(), 'granted' => $granted, 'rejected' => [] - ] + ], + [$baseId] ); + + unset($granted); } diff --git a/lib/Alchemy/Phrasea/Controller/Admin/UserController.php b/lib/Alchemy/Phrasea/Controller/Admin/UserController.php index 35ff646b8c..a1487603d8 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/UserController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/UserController.php @@ -515,9 +515,9 @@ class UserController extends Controller $denyColl[] = $label; $hookData['rejected'][$bas] = $label; } - } - $this->app['manipulator.webhook-event']->create($hookName, $hookType, $hookData); + $this->app['manipulator.webhook-event']->create($hookName, $hookType, $hookData, [$bas]); + } if ($user->hasMailNotificationsActivated() && (0 !== count($acceptColl) || 0 !== count($denyColl))) { $message = ''; diff --git a/lib/Alchemy/Phrasea/Controller/Root/AccountController.php b/lib/Alchemy/Phrasea/Controller/Root/AccountController.php index a6b305fe22..14117f0f01 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/AccountController.php +++ b/lib/Alchemy/Phrasea/Controller/Root/AccountController.php @@ -518,7 +518,9 @@ class AccountController extends Controller $this->getApiApplicationManipulator()->deleteApiApplications($applications); - // revoke access and delete phraseanet user account + // get list of old granted base_id then revoke access and delete phraseanet user account + + $oldGrantedBaseIds = array_keys($this->app->getAclForUser($user)->get_granted_base()); $list = array_keys($this->app['repo.collections-registry']->getBaseIdMap()); @@ -535,7 +537,7 @@ class AccountController extends Controller $mail = MailSuccessAccountDelete::create($this->app, $receiver); - $this->app['manipulator.user']->delete($user); + $this->app['manipulator.user']->delete($user, [$user->getId() => $oldGrantedBaseIds]); $this->deliver($mail); } diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookUserEventSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookUserEventSubscriber.php index a2f935bf89..74c1c6c23a 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookUserEventSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookUserEventSubscriber.php @@ -45,7 +45,7 @@ class WebhookUserEventSubscriber implements EventSubscriberInterface 'user_id' => $event->getUserId(), 'email' => $event->getEmailAddress(), 'login' => $event->getLogin() - ]); + ], $event->getGrantedBaseIds()); } public static function getSubscribedEvents() diff --git a/lib/Alchemy/Phrasea/Core/Event/User/DeletedEvent.php b/lib/Alchemy/Phrasea/Core/Event/User/DeletedEvent.php index b67ba45b24..1528917245 100644 --- a/lib/Alchemy/Phrasea/Core/Event/User/DeletedEvent.php +++ b/lib/Alchemy/Phrasea/Core/Event/User/DeletedEvent.php @@ -36,4 +36,12 @@ class DeletedEvent extends UserEvent { return $this->args['email']; } + + /** + * @return array + */ + public function getGrantedBaseIds() + { + return $this->args['grantedBaseIds']; + } } diff --git a/lib/Alchemy/Phrasea/Core/Version.php b/lib/Alchemy/Phrasea/Core/Version.php index 0e15108724..eef6327696 100644 --- a/lib/Alchemy/Phrasea/Core/Version.php +++ b/lib/Alchemy/Phrasea/Core/Version.php @@ -16,7 +16,7 @@ class Version /** * @var string */ - private $number = '4.1.0-alpha.15a'; + private $number = '4.1.0-alpha.16a'; /** * @var string diff --git a/lib/Alchemy/Phrasea/Helper/User/Edit.php b/lib/Alchemy/Phrasea/Helper/User/Edit.php index 5c760a55de..f89ccbe383 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Edit.php +++ b/lib/Alchemy/Phrasea/Helper/User/Edit.php @@ -73,10 +73,12 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper { $list = array_keys($this->app->getAclForUser($this->app->getAuthenticatedUser())->get_granted_base([\ACL::CANADMIN])); + $oldGrantedBaseIds = array_keys($this->app->getAclForUser($user)->get_granted_base()); + $this->app->getAclForUser($user)->revoke_access_from_bases($list); if ($this->app->getAclForUser($user)->is_phantom()) { - $this->app['manipulator.user']->delete($user); + $this->app['manipulator.user']->delete($user, [$user->getId() => $oldGrantedBaseIds]); } return $this; diff --git a/lib/Alchemy/Phrasea/Model/Entities/WebhookEvent.php b/lib/Alchemy/Phrasea/Model/Entities/WebhookEvent.php index 275650f1b3..a1091f531f 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/WebhookEvent.php +++ b/lib/Alchemy/Phrasea/Model/Entities/WebhookEvent.php @@ -68,6 +68,14 @@ class WebhookEvent */ private $created; + /** + * List of collection base_id concerned + * @var array + * + * @ORM\Column(name="collection_base_ids", type="json_array", nullable=true) + */ + private $collectionBaseIds; + /** * @param \DateTime $created * @@ -175,4 +183,24 @@ class WebhookEvent return $this; } + + /** + * @param array $collectionBaseIds + * + * @return $this + */ + public function setCollectionBaseIds(array $collectionBaseIds) + { + $this->collectionBaseIds = $collectionBaseIds; + + return $this; + } + + /** + * @return array + */ + public function getCollectionBaseIds() + { + return $this->collectionBaseIds; + } } diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php index 8104c04c47..51bb1de9b6 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php @@ -126,8 +126,9 @@ class UserManipulator implements ManipulatorInterface * Deletes a user. * * @param User|User[] $users + * @param array $grantedBaseIdList List of the old granted base_id per userId [user_id => [base_id, ...] ] */ - public function delete($users) + public function delete($users, array $grantedBaseIdList = array()) { /** @var User $user */ foreach ($this->makeTraversable($users) as $user) { @@ -146,9 +147,10 @@ class UserManipulator implements ManipulatorInterface new DeletedEvent( null, array( - 'user_id'=>$old_id, - 'login'=>$old_login, - 'email'=>$old_email + 'user_id' => $old_id, + 'login' => $old_login, + 'email' => $old_email, + 'grantedBaseIds' => isset($grantedBaseIdList[$old_id]) ? $grantedBaseIdList[$old_id] : [] ) ) ); diff --git a/tests/Alchemy/Tests/Phrasea/Functional/UserDeletionTest.php b/tests/Alchemy/Tests/Phrasea/Functional/UserDeletionTest.php index 2db0eefa19..5ac42170c7 100644 --- a/tests/Alchemy/Tests/Phrasea/Functional/UserDeletionTest.php +++ b/tests/Alchemy/Tests/Phrasea/Functional/UserDeletionTest.php @@ -79,7 +79,7 @@ class UserDeletionTest extends \PhraseanetAuthenticatedWebTestCase $apiLog = $apiLogManipulator->create($account, new Request(), new Response()); $apiLogId = $apiLog->getId(); - $this->userManipulator->delete($this->user, true); + $this->userManipulator->delete($this->user); $this->assertTrue($this->user->isDeleted(), 'User was not properly deleted'); $apiLogRepository->clear();