mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +00:00
Use manipulator.user to delete users
This commit is contained in:
@@ -71,7 +71,7 @@ class GuiContext extends MinkContext
|
|||||||
$this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(array('canadmin'))
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,9 +53,7 @@ class JsFixtures extends Command
|
|||||||
|
|
||||||
private function deleteUser(User $user)
|
private function deleteUser(User $user)
|
||||||
{
|
{
|
||||||
$this->container['model.user-manager']->delete($user ,false);
|
$this->container['manipulator.user']->delete($user);
|
||||||
$this->container['EM']->remove($user);
|
|
||||||
$this->container['EM']->flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function copy(OutputInterface $output, $data)
|
private function copy(OutputInterface $output, $data)
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
|
|||||||
$this->app['acl']->get($user)->revoke_access_from_bases($list);
|
$this->app['acl']->get($user)->revoke_access_from_bases($list);
|
||||||
|
|
||||||
if ($this->app['acl']->get($user)->is_phantom()) {
|
if ($this->app['acl']->get($user)->is_phantom()) {
|
||||||
$this->app['model.user-manager']->delete($user);
|
$this->app['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@@ -47,10 +47,6 @@ class UserManager
|
|||||||
*/
|
*/
|
||||||
public function delete(User $user, $flush = true)
|
public function delete(User $user, $flush = true)
|
||||||
{
|
{
|
||||||
$user->setDeleted(true);
|
|
||||||
$user->setEmail(null);
|
|
||||||
$user->setLogin(sprintf('(#deleted_%s', $user->getLogin()));
|
|
||||||
|
|
||||||
$this->cleanProperties($user);
|
$this->cleanProperties($user);
|
||||||
$this->cleanRights($user);
|
$this->cleanRights($user);
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,22 @@ class UserManipulator implements ManipulatorInterface
|
|||||||
return $user;
|
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.
|
* Creates a template user and returns it.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class AccountCreatorTest extends \PhraseanetTestCase
|
|||||||
|
|
||||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user);
|
$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()
|
public function testCreateWithTemplates()
|
||||||
@@ -74,10 +74,10 @@ class AccountCreatorTest extends \PhraseanetTestCase
|
|||||||
$user = $creator->create(self::$DI['app'], self::$DI['app']['tokens']->generatePassword(), null, $extra);
|
$user = $creator->create(self::$DI['app'], self::$DI['app']['tokens']->generatePassword(), null, $extra);
|
||||||
|
|
||||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user);
|
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user);
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
self::$DI['app']['model.user-manager']->delete($template1);
|
self::$DI['app']['manipulator.user']->delete($template1);
|
||||||
self::$DI['app']['model.user-manager']->delete($template2);
|
self::$DI['app']['manipulator.user']->delete($template2);
|
||||||
self::$DI['app']['model.user-manager']->delete($template3);
|
self::$DI['app']['manipulator.user']->delete($template3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateWithAlreadyExistingLogin()
|
public function testCreateWithAlreadyExistingLogin()
|
||||||
@@ -87,6 +87,6 @@ class AccountCreatorTest extends \PhraseanetTestCase
|
|||||||
|
|
||||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user);
|
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user);
|
||||||
$this->assertNotEquals(self::$DI['user']->getLogin(), $user->getLogin());
|
$this->assertNotEquals(self::$DI['user']->getLogin(), $user->getLogin());
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,6 @@ class AdminDashboardTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
|
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"));
|
$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']['EM']->refresh($user);
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRouteRightsApplyException()
|
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()]);
|
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();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isOK());
|
$this->assertTrue($response->isOK());
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRouteRightTimeApplySbas()
|
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()]);
|
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();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isOK());
|
$this->assertTrue($response->isOK());
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRouteRightTimeApplyWithtoutBasOrSbas()
|
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()]);
|
self::$DI['client']->request('POST', '/admin/users/rights/time/apply/', ['dmin' => $dmin, 'dmax' => $dmax, 'limit' => 1, 'users' => $user->getId()]);
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertEquals(400, $response->getStatusCode());
|
$this->assertEquals(400, $response->getStatusCode());
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRouteRightMask()
|
public function testRouteRightMask()
|
||||||
@@ -201,7 +201,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
]);
|
]);
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isOK());
|
$this->assertTrue($response->isOK());
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRouteSearch()
|
public function testRouteSearch()
|
||||||
@@ -241,8 +241,8 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
|
|
||||||
$response = self::$DI['client']->getResponse();
|
$response = self::$DI['client']->getResponse();
|
||||||
$this->assertTrue($response->isRedirect());
|
$this->assertTrue($response->isRedirect());
|
||||||
self::$DI['app']['model.user-manager']->delete($template);
|
self::$DI['app']['manipulator.user']->delete($template);
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRouteCreateException()
|
public function testRouteCreateException()
|
||||||
@@ -286,7 +286,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$this->assertFalse($datas->error);
|
$this->assertFalse($datas->error);
|
||||||
|
|
||||||
$this->assertNotNull($user = (self::$DI['app']['manipulator.user']->getRepository()->find((int) $datas->data)));
|
$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()
|
public function testRouteCreateUserAndSendCredentials()
|
||||||
@@ -309,7 +309,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$this->assertFalse($datas->error);
|
$this->assertFalse($datas->error);
|
||||||
|
|
||||||
$this->assertNotNull($user = (self::$DI['app']['manipulator.user']->getRepository()->find((int) $datas->data)));
|
$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()
|
public function testRouteExportCsv()
|
||||||
@@ -363,7 +363,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$this->assertTrue(is_object($datas));
|
$this->assertTrue(is_object($datas));
|
||||||
$this->assertFalse($datas->error);
|
$this->assertFalse($datas->error);
|
||||||
$this->assertFalse(self::$DI['app']['acl']->get($user)->has_access_to_base($base_id));
|
$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()
|
public function testRenderDemands()
|
||||||
|
|||||||
@@ -1014,7 +1014,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
|||||||
$this->fail('User not created');
|
$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->assertGreaterThan(0, $emails['Alchemy\Phrasea\Notification\Mail\MailInfoUserRegistered']);
|
||||||
$this->assertEquals(1, $emails['Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation']);
|
$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->assertEquals(1, $emails['Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation']);
|
||||||
$this->assertFlashMessagePopulated(self::$DI['app'], 'info', 1);
|
$this->assertFlashMessagePopulated(self::$DI['app'], 'info', 1);
|
||||||
$this->assertEquals('/login/', self::$DI['client']->getResponse()->headers->get('location'));
|
$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->assertSame('/prod/', self::$DI['client']->getResponse()->headers->get('location'));
|
||||||
|
|
||||||
$this->assertTrue(self::$DI['app']['authentication']->isAuthenticated());
|
$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()
|
public function testAuthenticateProviderCallbackWithRegistrationEnabled()
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ class UserManagerTest extends \PhraseanetTestCase
|
|||||||
self::$DI['app']['manipulator.user']->setUserSetting($user, 'setting', false);
|
self::$DI['app']['manipulator.user']->setUserSetting($user, 'setting', false);
|
||||||
self::$DI['app']['manipulator.user']->setNotificationSetting($user, 'setting', false);
|
self::$DI['app']['manipulator.user']->setNotificationSetting($user, 'setting', false);
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['model.user-manager']->delete($user);
|
||||||
$this->assertTrue($user->isDeleted());
|
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login');
|
||||||
$this->assertNull($user->getEmail());
|
|
||||||
$this->assertEquals('(#deleted_', substr($user->getLogin(), 0, 10));
|
|
||||||
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('(#deleted_login');
|
|
||||||
$this->assertEquals(0, $user->getSettings()->count());
|
$this->assertEquals(0, $user->getSettings()->count());
|
||||||
$this->assertEquals(0, $user->getNotificationSettings()->count());
|
$this->assertEquals(0, $user->getNotificationSettings()->count());
|
||||||
$this->assertEquals(0, $user->getQueries()->count());
|
$this->assertEquals(0, $user->getQueries()->count());
|
||||||
|
|||||||
@@ -14,6 +14,15 @@ class UserManipulatorTest extends \PhraseanetTestCase
|
|||||||
$this->assertInstanceOf('\Alchemy\Phrasea\Model\Entities\User', self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'));
|
$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()
|
public function testCreateAdminUser()
|
||||||
{
|
{
|
||||||
$user = self::$DI['app']['manipulator.user']->createUser('login', 'pass', 'admin@admin.com', true);
|
$user = self::$DI['app']['manipulator.user']->createUser('login', 'pass', 'admin@admin.com', true);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class UserProviderTest extends \PhraseanetTestCase
|
|||||||
|
|
||||||
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
|
$this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $results);
|
||||||
$this->assertTrue($results->count() > 0);
|
$this->assertTrue($results->count() > 0);
|
||||||
self::$DI['app']['model.user-manager']->delete($user);
|
self::$DI['app']['manipulator.user']->delete($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValidate()
|
public function testValidate()
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class userTest extends \PhraseanetTestCase
|
|||||||
self::$DI['app']['EM']->persist($provider);
|
self::$DI['app']['EM']->persist($provider);
|
||||||
self::$DI['app']['EM']->flush();
|
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));
|
$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']->persist($session);
|
||||||
self::$DI['app']['EM']->flush();
|
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');
|
$repo = self::$DI['app']['EM']->getRepository('Phraseanet:Session');
|
||||||
$this->assertCount(0, $repo->findByUser($user));
|
$this->assertCount(0, $repo->findByUser($user));
|
||||||
|
|||||||
Reference in New Issue
Block a user