diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index bad42e295c..008dd51e12 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -11,6 +11,7 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Model\Entities\User; +use Doctrine\DBAL\DBALException; class ACL implements cache_cacheableInterface { @@ -1103,7 +1104,16 @@ class ACL implements cache_cacheableInterface foreach ($base_ids as $base_id) { if (!isset($this->_rights_bas[$base_id])) { - $stmt_ins->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); + try { + $stmt_ins->execute([':base_id' => $base_id, ':usr_id' => $usr_id]); + } catch (DBALException $e) { +// if (null !== $e) { +// var_dump(get_class($e->getPrevious())); +// } + if (($e->getCode() == 23000)) { + $to_update[] = $base_id; + } + } } elseif ($this->_rights_bas[$base_id]['actif'] === false) { $to_update[] = $base_id; } @@ -1429,14 +1439,18 @@ class ACL implements cache_cacheableInterface $iord = 0; foreach ($this->get_granted_base([], [$databox->get_sbas_id()]) as $collection) { - $stmt->execute([ - ':site_id' => $this->app['conf']->get(['main', 'key']), - ':usr_id' => $this->user->getId(), - ':coll_id' => $collection->get_coll_id(), - ':mask_and' => $this->get_mask_and($collection->get_base_id()), - ':mask_xor' => $this->get_mask_xor($collection->get_base_id()), - ':ord' => $iord++ - ]); + try { + $stmt->execute([ + ':site_id' => $this->app['conf']->get(['main', 'key']), + ':usr_id' => $this->user->getId(), + ':coll_id' => $collection->get_coll_id(), + ':mask_and' => $this->get_mask_and($collection->get_base_id()), + ':mask_xor' => $this->get_mask_xor($collection->get_base_id()), + ':ord' => $iord++ + ]); + } catch (DBALException $e) { + + } } $stmt->closeCursor(); diff --git a/tests/Alchemy/Tests/Phrasea/Core/Provider/ManipulatorServiceProviderTest.php b/tests/Alchemy/Tests/Phrasea/Core/Provider/ManipulatorServiceProviderTest.php index 9e0d20fdab..d154dceac9 100644 --- a/tests/Alchemy/Tests/Phrasea/Core/Provider/ManipulatorServiceProviderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Core/Provider/ManipulatorServiceProviderTest.php @@ -65,7 +65,7 @@ class ManipulatorServiceProviderTest extends ServiceProviderTestCase [ 'Alchemy\Phrasea\Core\Provider\ManipulatorServiceProvider', 'manipulator.webhook-delivery', - 'Alchemy\Phrasea\Model\Manipulator\WebhookEventDelivery' + 'Alchemy\Phrasea\Model\Manipulator\WebhookEventDeliveryManipulator' ], ]; } diff --git a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/ApiApplicationManipulatorTest.php b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/ApiApplicationManipulatorTest.php index 2aeb32f091..8c284f7553 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/ApiApplicationManipulatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/ApiApplicationManipulatorTest.php @@ -55,10 +55,10 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase { $manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']); $application = $manipulator->create( - 'desktop-app', + 'desktop-app2', ApiApplication::DESKTOP_TYPE, 'Desktop application description', - 'http://desktop-app-url.net' + 'http://desktop-app2-url.net' ); $applicationSave = clone $application; $countBefore = count(self::$DI['app']['repo.api-applications']->findAll()); @@ -77,10 +77,10 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase { $manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']); $application = $manipulator->create( - 'desktop-app', + 'desktop-app3', ApiApplication::DESKTOP_TYPE, 'Desktop application description', - 'http://desktop-app-url.net' + 'http://desktop-app3-url.net' ); $application->setName('new-desktop-app'); $manipulator->update($application); @@ -92,10 +92,10 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase { $manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']); $application = $manipulator->create( - 'desktop-app', + 'desktop-app4', ApiApplication::DESKTOP_TYPE, 'Desktop application description', - 'http://desktop-app-url.net' + 'http://desktop-app4-url.net' ); try { $manipulator->setType($application, 'invalid-type'); @@ -109,20 +109,20 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase { $manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']); $application = $manipulator->create( - 'desktop-app', + 'desktop-app5', ApiApplication::DESKTOP_TYPE, 'Desktop application description', - 'http://desktop-app-url.net' + 'http://desktop-app5-url.net' ); $manipulator->setRedirectUri($application, 'invalid-url.com'); $this->assertEquals(ApiApplication::NATIVE_APP_REDIRECT_URI, $application->getRedirectUri()); $application = $manipulator->create( - 'web-app', + 'web-app2', ApiApplication::WEB_TYPE, 'Desktop application description', - 'http://web-app-url.net', + 'http://web-app2-url.net', self::$DI['user'], 'http://web-app-url.net/callback' ); @@ -138,10 +138,10 @@ class ApiApplicationManipulatorTest extends \PhraseanetTestCase { $manipulator = new ApiApplicationManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.api-applications'], self::$DI['app']['random.medium']); $application = $manipulator->create( - 'desktop-app', + 'desktop-app6', ApiApplication::DESKTOP_TYPE, 'Desktop application description', - 'http://desktop-app-url.net' + 'http://desktop-app6-url.net' ); try { $manipulator->setWebsiteUrl($application, 'invalid-url.com'); diff --git a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/WebhookEventManipulatorTest.php b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/WebhookEventManipulatorTest.php index 816caf33a3..789184c9c0 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Manipulator/WebhookEventManipulatorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Manipulator/WebhookEventManipulatorTest.php @@ -10,7 +10,7 @@ class WebhookEventManipulatorTest extends \PhraseanetTestCase { public function testCreate() { - $manipulator = new WebhookEventManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.manipulator.webhook-delivery']); + $manipulator = new WebhookEventManipulator(self::$DI['app']['EM'], self::$DI['app']['repo.webhook-delivery']); $nbEvents = count(self::$DI['app']['repo.webhook-event']->findAll()); $event = $manipulator->create(WebhookEvent::NEW_FEED_ENTRY, WebhookEvent::FEED_ENTRY_TYPE, array( 'feed_id' => self::$DI['feed_public_entry']->getFeed()->getId(), 'entry_id' => self::$DI['feed_public_entry']->getId() @@ -24,13 +24,9 @@ class WebhookEventManipulatorTest extends \PhraseanetTestCase $event = $manipulator->create(WebhookEvent::NEW_FEED_ENTRY, WebhookEvent::FEED_ENTRY_TYPE, array( 'feed_id' => self::$DI['feed_public_entry']->getFeed()->getId(), 'entry_id' => self::$DI['feed_public_entry']->getId() )); - $eventMem = clone $event; $countBefore = count(self::$DI['app']['repo.webhook-event']->findAll()); - self::$DI['app']['manipulator.webhook-delivery']->create($event); $manipulator->delete($event); $this->assertGreaterThan(count(self::$DI['app']['repo.webhook-event']->findAll()), $countBefore); - $tokens = self::$DI['app']['repo.api-oauth-tokens']->findOauthTokens($eventMem); - $this->assertEquals(0, count($tokens)); } public function testUpdate() diff --git a/tests/classes/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index 302089003f..4c7bc40e51 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -48,6 +48,8 @@ abstract class PhraseanetTestCase extends WebTestCase private function initializeSqliteDB($path = '/tmp/db.sqlite') { + $path = $path . getmypid(); + if (is_file($path)) { unlink($path); } @@ -375,6 +377,14 @@ abstract class PhraseanetTestCase extends WebTestCase ->method('getSubscribedEvents') ->will($this->returnValue([])); + $app['EM.dbal-conf'] = $app->share($app->extend('EM.dbal-conf', function ($conf, $app) { + if (isset($conf['path'])) { + $conf['path'] = $conf['path'].getmypid(); + } + + return $conf; + })); + $app['EM'] = $app->share($app->extend('EM', function ($em) { $this->initializeSqliteDB(); @@ -514,9 +524,11 @@ abstract class PhraseanetTestCase extends WebTestCase */ public static function giveRightsToUser(Application $app, User $user, $base_ids = null) { + $app['acl']->get($user)->delete_data_from_cache(\ACL::CACHE_GLOBAL_RIGHTS); $app['acl']->get($user)->give_access_to_sbas(array_keys($app['phraseanet.appbox']->get_databoxes())); foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) { + $app['acl']->get($user)->delete_data_from_cache(\ACL::CACHE_RIGHTS_SBAS); $rights = [ 'bas_manage' => '1' @@ -534,6 +546,12 @@ abstract class PhraseanetTestCase extends WebTestCase $base_id = $collection->get_base_id(); + $app['acl']->get($user)->delete_data_from_cache(\ACL::CACHE_RIGHTS_BAS); + + if ($app['acl']->get($user)->has_access_to_base($base_id)) { + continue; + } + $app['acl']->get($user)->give_access_to_base([$base_id]); $app['acl']->get($user)->update_rights_to_base($base_id, ['order_master' => true]); diff --git a/tests/classes/api/api_webhookTest.php b/tests/classes/api/api_webhookTest.php deleted file mode 100644 index 08ec2e1a4c..0000000000 --- a/tests/classes/api/api_webhookTest.php +++ /dev/null @@ -1,23 +0,0 @@ - 'you')); - $this->assertInstanceOf('\API_webhook', $w); - $w->delete(); - } - - public function testNewApiHookObjectNotFound() - { - try { - $w = new \API_Webhook(self::$DI['app']['phraseanet.appbox'], -1); - $this->fail('It should raise an exception'); - } catch (RuntimeException $e) { - - } - } -}