mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Merge pull request #529 from romainneutron/fix-1360
[3.8] Fix #1360 : Registered providers are not removed on user delete
This commit is contained in:
@@ -12,6 +12,20 @@ use Doctrine\ORM\EntityRepository;
|
|||||||
*/
|
*/
|
||||||
class UsrAuthProviderRepository extends EntityRepository
|
class UsrAuthProviderRepository extends EntityRepository
|
||||||
{
|
{
|
||||||
|
public function findByUser(\User_Adapter $user)
|
||||||
|
{
|
||||||
|
$dql = 'SELECT u
|
||||||
|
FROM Entities\UsrAuthProvider u
|
||||||
|
WHERE u.usr_id = :usrId';
|
||||||
|
|
||||||
|
$params = array('usrId' => $user->get_id());
|
||||||
|
|
||||||
|
$query = $this->_em->createQuery($dql);
|
||||||
|
$query->setParameters($params);
|
||||||
|
|
||||||
|
return $query->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
public function findWithProviderAndId($providerId, $distantId)
|
public function findWithProviderAndId($providerId, $distantId)
|
||||||
{
|
{
|
||||||
$dql = 'SELECT u
|
$dql = 'SELECT u
|
||||||
|
@@ -960,6 +960,14 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
|||||||
*/
|
*/
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
|
$repo = $this->app['EM']->getRepository('Entities\UsrAuthProvider');
|
||||||
|
|
||||||
|
foreach ($repo->findByUser($this) as $provider) {
|
||||||
|
$this->app['EM']->remove($provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->app['EM']->flush();
|
||||||
|
|
||||||
$sql = 'UPDATE usr SET usr_login = :usr_login , usr_mail = null
|
$sql = 'UPDATE usr SET usr_login = :usr_login , usr_mail = null
|
||||||
WHERE usr_id = :usr_id';
|
WHERE usr_id = :usr_id';
|
||||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||||
@@ -1577,7 +1585,10 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
|||||||
|
|
||||||
public static function get_sys_admins(Application $app)
|
public static function get_sys_admins(Application $app)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT usr_id, usr_login FROM usr WHERE create_db="1"';
|
$sql = 'SELECT usr_id, usr_login FROM usr
|
||||||
|
WHERE create_db="1"
|
||||||
|
AND model_of="0"
|
||||||
|
AND usr_login NOT LIKE "(#deleted%"';
|
||||||
$conn = connection::getPDOConnection($app);
|
$conn = connection::getPDOConnection($app);
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
class userTest extends PhraseanetPHPUnitAbstract
|
class userTest extends PhraseanetPHPUnitAbstract
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testMail()
|
public function testMail()
|
||||||
{
|
{
|
||||||
$this->assertFalse(User_Adapter::get_usr_id_from_email(self::$DI['app'], null));
|
$this->assertFalse(User_Adapter::get_usr_id_from_email(self::$DI['app'], null));
|
||||||
@@ -26,4 +25,27 @@ class userTest extends PhraseanetPHPUnitAbstract
|
|||||||
}
|
}
|
||||||
$this->assertFalse(User_Adapter::get_usr_id_from_email(self::$DI['app'], null));
|
$this->assertFalse(User_Adapter::get_usr_id_from_email(self::$DI['app'], null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDeleteSetMailToNullAndRemovesProviders()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$usrId = \User_Adapter::get_usr_id_from_login(self::$DI['app'], 'test_phpunit_providers');
|
||||||
|
$user = \User_Adapter::getInstance($usrId, self::$DI['app']);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$user = \User_Adapter::create(self::$DI['app'], 'test_phpunit_providers', 'any', null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$provider = new Entities\UsrAuthProvider();
|
||||||
|
$provider->setDistantId(12345);
|
||||||
|
$provider->setProvider('custom-one');
|
||||||
|
$provider->setUsrId($user->get_id());
|
||||||
|
|
||||||
|
self::$DI['app']['EM']->persist($provider);
|
||||||
|
self::$DI['app']['EM']->flush();
|
||||||
|
|
||||||
|
$user->delete();
|
||||||
|
|
||||||
|
$repo = self::$DI['app']['EM']->getRepository('Entities\UsrAuthProvider');
|
||||||
|
$this->assertNull($repo->findWithProviderAndId('custom-one', 12345));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user