diff --git a/features/bootstrap/GuiContext.php b/features/bootstrap/GuiContext.php index 755c5ca09f..b97da5e5de 100644 --- a/features/bootstrap/GuiContext.php +++ b/features/bootstrap/GuiContext.php @@ -71,7 +71,7 @@ class GuiContext extends MinkContext $this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(array('canadmin')) )); - $this->app['model.user-manager']->delete($user); + $this->app['manipulator.user']->delete($user); } } diff --git a/lib/Alchemy/Phrasea/Command/Developer/JsFixtures.php b/lib/Alchemy/Phrasea/Command/Developer/JsFixtures.php index 29b4a9fa11..ade173d278 100644 --- a/lib/Alchemy/Phrasea/Command/Developer/JsFixtures.php +++ b/lib/Alchemy/Phrasea/Command/Developer/JsFixtures.php @@ -53,9 +53,7 @@ class JsFixtures extends Command private function deleteUser(User $user) { - $this->container['model.user-manager']->delete($user ,false); - $this->container['EM']->remove($user); - $this->container['EM']->flush(); + $this->container['manipulator.user']->delete($user); } private function copy(OutputInterface $output, $data) diff --git a/lib/Alchemy/Phrasea/Helper/User/Edit.php b/lib/Alchemy/Phrasea/Helper/User/Edit.php index 29d0f8443d..877f517cd9 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Edit.php +++ b/lib/Alchemy/Phrasea/Helper/User/Edit.php @@ -78,7 +78,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper $this->app['acl']->get($user)->revoke_access_from_bases($list); if ($this->app['acl']->get($user)->is_phantom()) { - $this->app['model.user-manager']->delete($user); + $this->app['manipulator.user']->delete($user); } return $this; diff --git a/lib/Alchemy/Phrasea/Model/Manager/UserManager.php b/lib/Alchemy/Phrasea/Model/Manager/UserManager.php index 5b24de6463..cf5f6aa41d 100644 --- a/lib/Alchemy/Phrasea/Model/Manager/UserManager.php +++ b/lib/Alchemy/Phrasea/Model/Manager/UserManager.php @@ -47,10 +47,6 @@ class UserManager */ public function delete(User $user, $flush = true) { - $user->setDeleted(true); - $user->setEmail(null); - $user->setLogin(sprintf('(#deleted_%s', $user->getLogin())); - $this->cleanProperties($user); $this->cleanRights($user); diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php index f2553bbf0e..281516501c 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php @@ -74,6 +74,22 @@ class UserManipulator implements ManipulatorInterface return $user; } + /** + * Deletes a user. + * + * @param User|User[] $users + */ + public function delete($users) + { + foreach ($this->makeTraversable($users) as $user) { + $user->setDeleted(true); + $user->setEmail(null); + $user->setLogin(sprintf('(#deleted_%s', $user->getLogin())); + + $this->manager->delete($user); + } + } + /** * Creates a template user and returns it. * diff --git a/tests/Alchemy/Tests/Phrasea/Authentication/AccountCreatorTest.php b/tests/Alchemy/Tests/Phrasea/Authentication/AccountCreatorTest.php index 5620ccd855..edd74e4146 100644 --- a/tests/Alchemy/Tests/Phrasea/Authentication/AccountCreatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Authentication/AccountCreatorTest.php @@ -58,7 +58,7 @@ class AccountCreatorTest extends \PhraseanetTestCase $this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testCreateWithTemplates() @@ -74,10 +74,10 @@ class AccountCreatorTest extends \PhraseanetTestCase $user = $creator->create(self::$DI['app'], self::$DI['app']['tokens']->generatePassword(), null, $extra); $this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user); - self::$DI['app']['model.user-manager']->delete($user); - self::$DI['app']['model.user-manager']->delete($template1); - self::$DI['app']['model.user-manager']->delete($template2); - self::$DI['app']['model.user-manager']->delete($template3); + self::$DI['app']['manipulator.user']->delete($user); + self::$DI['app']['manipulator.user']->delete($template1); + self::$DI['app']['manipulator.user']->delete($template2); + self::$DI['app']['manipulator.user']->delete($template3); } public function testCreateWithAlreadyExistingLogin() @@ -87,6 +87,6 @@ class AccountCreatorTest extends \PhraseanetTestCase $this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user); $this->assertNotEquals(self::$DI['user']->getLogin(), $user->getLogin()); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php index 25767a3cf8..3e92088f34 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminDashboardTest.php @@ -123,6 +123,6 @@ class AdminDashboardTest extends \PhraseanetAuthenticatedWebTestCase ]); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php index 18b6b36dc3..3f589ea567 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php @@ -67,7 +67,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase $this->assertTrue(self::$DI['app']['acl']->get($user)->has_right_on_base(self::$DI['collection']->get_base_id(), "canreport")); self::$DI['app']['EM']->refresh($user); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testRouteRightsApplyException() @@ -148,7 +148,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase self::$DI['client']->request('POST', '/admin/users/rights/time/apply/', ['base_id' => $base_id, 'dmin' => $dmin, 'dmax' => $dmax, 'limit' => 1, 'users' => $user->getId()]); $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOK()); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testRouteRightTimeApplySbas() @@ -163,7 +163,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase self::$DI['client']->request('POST', '/admin/users/rights/time/apply/', ['sbas_id' => $sbas_id, 'dmin' => $dmin, 'dmax' => $dmax, 'limit' => 1, 'users' => $user->getId()]); $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOK()); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testRouteRightTimeApplyWithtoutBasOrSbas() @@ -177,7 +177,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase self::$DI['client']->request('POST', '/admin/users/rights/time/apply/', ['dmin' => $dmin, 'dmax' => $dmax, 'limit' => 1, 'users' => $user->getId()]); $response = self::$DI['client']->getResponse(); $this->assertEquals(400, $response->getStatusCode()); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testRouteRightMask() @@ -201,7 +201,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase ]); $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOK()); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testRouteSearch() @@ -241,8 +241,8 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isRedirect()); - self::$DI['app']['model.user-manager']->delete($template); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($template); + self::$DI['app']['manipulator.user']->delete($user); } public function testRouteCreateException() @@ -286,7 +286,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase $this->assertFalse($datas->error); $this->assertNotNull($user = (self::$DI['app']['manipulator.user']->getRepository()->find((int) $datas->data))); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testRouteCreateUserAndSendCredentials() @@ -309,7 +309,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase $this->assertFalse($datas->error); $this->assertNotNull($user = (self::$DI['app']['manipulator.user']->getRepository()->find((int) $datas->data))); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testRouteExportCsv() @@ -363,7 +363,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase $this->assertTrue(is_object($datas)); $this->assertFalse($datas->error); $this->assertFalse(self::$DI['app']['acl']->get($user)->has_access_to_base($base_id)); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testRenderDemands() diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php index a68554127e..aa9dcda634 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php @@ -1014,7 +1014,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase $this->fail('User not created'); } - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); $this->assertGreaterThan(0, $emails['Alchemy\Phrasea\Notification\Mail\MailInfoUserRegistered']); $this->assertEquals(1, $emails['Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation']); @@ -1082,7 +1082,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase $this->assertEquals(1, $emails['Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation']); $this->assertFlashMessagePopulated(self::$DI['app'], 'info', 1); $this->assertEquals('/login/', self::$DI['client']->getResponse()->headers->get('location')); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } /** @@ -1591,7 +1591,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase $this->assertSame('/prod/', self::$DI['client']->getResponse()->headers->get('location')); $this->assertTrue(self::$DI['app']['authentication']->isAuthenticated()); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testAuthenticateProviderCallbackWithRegistrationEnabled() diff --git a/tests/Alchemy/Tests/Phrasea/Model/Manager/UserManagerTest.php b/tests/Alchemy/Tests/Phrasea/Model/Manager/UserManagerTest.php index 3ee7b23f2f..80677196ff 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Manager/UserManagerTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Manager/UserManagerTest.php @@ -17,10 +17,7 @@ class UserManagerTest extends \PhraseanetTestCase self::$DI['app']['manipulator.user']->setUserSetting($user, 'setting', false); self::$DI['app']['manipulator.user']->setNotificationSetting($user, 'setting', false); self::$DI['app']['model.user-manager']->delete($user); - $this->assertTrue($user->isDeleted()); - $this->assertNull($user->getEmail()); - $this->assertEquals('(#deleted_', substr($user->getLogin(), 0, 10)); - $user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('(#deleted_login'); + $user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'); $this->assertEquals(0, $user->getSettings()->count()); $this->assertEquals(0, $user->getNotificationSettings()->count()); $this->assertEquals(0, $user->getQueries()->count()); diff --git a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/UserManipulatorTest.php b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/UserManipulatorTest.php index 73522104e7..c040964937 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/UserManipulatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/UserManipulatorTest.php @@ -14,6 +14,15 @@ class UserManipulatorTest extends \PhraseanetTestCase $this->assertInstanceOf('\Alchemy\Phrasea\Model\Entities\User', self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login')); } + public function testDeleteUser() + { + $user = self::$DI['app']['manipulator.user']->createUser(uniqid('login'), 'password'); + self::$DI['app']['manipulator.user']->delete($user); + $this->assertTrue($user->isDeleted()); + $this->assertNull($user->getEmail()); + $this->assertEquals('(#deleted_', substr($user->getLogin(), 0, 10)); + } + public function testCreateAdminUser() { $user = self::$DI['app']['manipulator.user']->createUser('login', 'pass', 'admin@admin.com', true); diff --git a/tests/Alchemy/Tests/Phrasea/Vocabulary/ControlProvider/UserProviderTest.php b/tests/Alchemy/Tests/Phrasea/Vocabulary/ControlProvider/UserProviderTest.php index 02d925dc04..2c8496d95b 100644 --- a/tests/Alchemy/Tests/Phrasea/Vocabulary/ControlProvider/UserProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Vocabulary/ControlProvider/UserProviderTest.php @@ -68,7 +68,7 @@ class UserProviderTest extends \PhraseanetTestCase $this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results); $this->assertTrue($results->count() > 0); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); } public function testValidate() diff --git a/tests/classes/userTest.php b/tests/classes/userTest.php index b14077ce3f..370944be47 100644 --- a/tests/classes/userTest.php +++ b/tests/classes/userTest.php @@ -31,7 +31,7 @@ class userTest extends \PhraseanetTestCase self::$DI['app']['EM']->persist($provider); self::$DI['app']['EM']->flush(); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); $this->assertNull(self::$DI['app']['EM']->getRepository('Phraseanet:UsrAuthProvider')->findWithProviderAndId('custom-one', 12345)); } @@ -48,7 +48,7 @@ class userTest extends \PhraseanetTestCase self::$DI['app']['EM']->persist($session); self::$DI['app']['EM']->flush(); - self::$DI['app']['model.user-manager']->delete($user); + self::$DI['app']['manipulator.user']->delete($user); $repo = self::$DI['app']['EM']->getRepository('Phraseanet:Session'); $this->assertCount(0, $repo->findByUser($user));