mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Fix latest merge
This commit is contained in:
@@ -32,9 +32,7 @@ class Permalink extends AbstractDelivery
|
||||
$that = $this;
|
||||
|
||||
$retrieveRecord = function ($app, $databox, $token, $record_id, $subdef) {
|
||||
if (\databox_subdef::CLASS_THUMBNAIL === $subdef) {
|
||||
$record = $databox->get_record($record_id);
|
||||
} elseif (\databox_subdef::CLASS_PREVIEW === $subdef && $app['EM']->getRepository('Entities\FeedItem')->isRecordInPublicFeed($app, $databox->get_sbas_id(), $record_id)) {
|
||||
if (in_array($subdef, array(\databox_subdef::CLASS_PREVIEW, \databox_subdef::CLASS_THUMBNAIL)) && $app['EM']->getRepository('Entities\FeedItem')->isRecordInPublicFeed($app, $databox->get_sbas_id(), $record_id)) {
|
||||
$record = $databox->get_record($record_id);
|
||||
} else {
|
||||
$record = \media_Permalink_Adapter::challenge_token($app, $databox, $token, $record_id, $subdef);
|
||||
@@ -119,7 +117,7 @@ class Permalink extends AbstractDelivery
|
||||
$token = $request->query->get('token');
|
||||
|
||||
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
||||
$record = $retrieveRecord($app, $databox, $token, $record_id, 'caption');
|
||||
$record = $retrieveRecord($app, $databox, $token, $record_id, \databox_subdef::CLASS_THUMBNAIL);
|
||||
$caption = $record->get_caption();
|
||||
|
||||
return new Response($caption->serialize(\caption_record::SERIALIZE_JSON), 200, array("Content-Type" => 'application/json'));
|
||||
|
@@ -52,7 +52,7 @@ class Login implements ControllerProviderInterface
|
||||
$items = array();
|
||||
|
||||
foreach($app['EM']->getRepository('Entities\FeedItem')->loadLatest($app, 20) as $item) {
|
||||
$record = $item->get_record();
|
||||
$record = $item->getRecord($app);
|
||||
$preview = $record->get_subdef('preview');
|
||||
$permalink = $preview->get_permalink();
|
||||
|
||||
|
@@ -34,7 +34,6 @@ class FeedItemRepository extends EntityRepository
|
||||
|
||||
$query = $this->_em->createQuery($dql);
|
||||
$query->setParameters(array('sbas_id' => $sbas_id, 'record_id' => $record_id));
|
||||
$query->useResultCache(false);
|
||||
|
||||
return count($query->getResult()) > 0;
|
||||
}
|
||||
|
@@ -119,6 +119,11 @@ class ACL implements cache_cacheableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_app(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a hd grant has been received for a record
|
||||
*
|
||||
|
@@ -327,6 +327,8 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
self::$_instance[$id] = new self($id, $app);
|
||||
$app['phraseanet.appbox']->set_data_to_cache(self::$_instance[$id], '_user_' . $id);
|
||||
}
|
||||
} else {
|
||||
self::$_instance[$id]->set_app($app);
|
||||
}
|
||||
|
||||
return array_key_exists($id, self::$_instance) ? self::$_instance[$id] : false;
|
||||
@@ -349,6 +351,9 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
protected function set_app(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
if (null !== $this->ACL) {
|
||||
$this->ACL->set_app($app);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1092,21 +1097,17 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->notification_preferences_loaded = true;
|
||||
}
|
||||
protected $notifications_preferences_loaded = false;
|
||||
|
||||
public function get_notifications_preference(Application $app, $notification_id)
|
||||
{
|
||||
if (!$this->notifications_preferences_loaded)
|
||||
$this->load_preferences($app);
|
||||
|
||||
return $this->_prefs['notification_' . $notification_id];
|
||||
return isset($this->_prefs['notification_' . $notification_id]) ? $this->_prefs['notification_' . $notification_id] : null;
|
||||
}
|
||||
|
||||
public function set_notification_preference(Application $app, $notification_id, $value)
|
||||
{
|
||||
if (!$this->notifications_preferences_loaded)
|
||||
$this->load_preferences($app);
|
||||
|
||||
return $this->_prefs['notification_' . $notification_id] = $value ? '1' : '0';
|
||||
|
@@ -285,6 +285,7 @@ class databox_field implements cache_cacheableInterface
|
||||
$databox->set_data_to_cache(self::$_instance[$instance_id], $cache_key);
|
||||
}
|
||||
}
|
||||
self::$_instance[$instance_id]->app = $app;
|
||||
|
||||
return self::$_instance[$instance_id];
|
||||
}
|
||||
|
@@ -47,9 +47,7 @@ class LoadOneFeed extends AbstractFixture implements FixtureInterface
|
||||
$feed->setTitle("test");
|
||||
}
|
||||
|
||||
if (isset($this->public) && $this->public !== null) {
|
||||
$feed->setIsPublic($this->public);
|
||||
}
|
||||
$feed->setIsPublic((Boolean) $this->public);
|
||||
|
||||
$feed->setSubtitle("description");
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Application;
|
||||
|
||||
class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
class LightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
{
|
||||
|
||||
protected $client;
|
||||
@@ -311,21 +311,24 @@ class ApplicationLightboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
|
||||
$this->assertObjectHasAttribute('error', $datas);
|
||||
}
|
||||
|
||||
public function testAjaxSetRelease()
|
||||
public function testAjaxSetReleaseWithRegularBasket()
|
||||
{
|
||||
$basket = $this->insertOneBasket();
|
||||
|
||||
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoValidationDone');
|
||||
|
||||
$crawler = self::$DI['client']->request('POST', '/lightbox/ajax/SET_RELEASE/' . $basket->getId() . '/');
|
||||
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
|
||||
$this->assertEquals('application/json', self::$DI['client']->getResponse()->headers->get('Content-type'));
|
||||
$datas = json_decode(self::$DI['client']->getResponse()->getContent());
|
||||
$this->assertTrue(is_object($datas), 'asserting good json datas');
|
||||
$this->assertTrue($datas->error);
|
||||
}
|
||||
|
||||
public function testAjaxSetReleaseWithRegularBasketWithValidation()
|
||||
{
|
||||
$validationBasket = $this->insertOneValidationBasket();
|
||||
|
||||
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailInfoValidationDone');
|
||||
|
||||
foreach ($validationBasket->getElements() as $element) {
|
||||
$element->getUserValidationDatas(self::$DI['app']['authentication']->getUser(), self::$DI['app'])->setAgreement(true);
|
||||
break;
|
||||
|
@@ -5,7 +5,7 @@ namespace Alchemy\Tests\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Border\File;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
class OverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
{
|
||||
public function testDatafilesRouteAuthenticated()
|
||||
{
|
||||
@@ -61,58 +61,7 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
|
||||
$this->assertForbiddenResponse(self::$DI['client']->getResponse());
|
||||
}
|
||||
|
||||
public function testIs_record_in_public_feed()
|
||||
{
|
||||
$feed = $this->createFeed();
|
||||
$this->setFeedIsPublic($feed, true);
|
||||
$entry = $this->createEntry($feed);
|
||||
|
||||
$this->addItem($entry, self::$DI['record_1']);
|
||||
|
||||
$this->assertTrue(self::$DI['app']['EM']->getRepository('Entities\FeedItem')->isRecordInPublicFeed(self::$DI['app'], self::$DI['record_1']->get_sbas_id(), self::$DI['record_1']->get_record_id()));
|
||||
$this->setFeedIsPublic($feed, false);
|
||||
$this->assertFalse(self::$DI['app']['EM']->getRepository('Entities\FeedItem')->isRecordInPublicFeed(self::$DI['app'], self::$DI['record_1']->get_sbas_id(), self::$DI['record_1']->get_record_id()));
|
||||
}
|
||||
|
||||
public function testLoadLatestItems()
|
||||
{
|
||||
$feed = $this->createFeed();
|
||||
$this->setFeedIsPublic($feed, true);
|
||||
$entry = $this->createEntry($feed);
|
||||
|
||||
foreach(range(1, 2) as $i) {
|
||||
$this->addItem($entry, self::$DI['record_'.$i]);
|
||||
}
|
||||
|
||||
$this->assertCount(2, self::$DI['app']['EM']->getRepository('Entities\FeedItem')->loadLatest(self::$DI['app'], 20));
|
||||
}
|
||||
|
||||
public function testLoadLatestItemsLessItems()
|
||||
{
|
||||
$feed = $this->createFeed();
|
||||
$this->setFeedIsPublic($feed, true);
|
||||
$entry = $this->createEntry($feed);
|
||||
|
||||
foreach(range(1, 2) as $i) {
|
||||
$this->addItem($entry, self::$DI['record_'.$i]);
|
||||
}
|
||||
|
||||
$this->assertCount(1, self::$DI['app']['EM']->getRepository('Entities\FeedItem')->loadLatest(self::$DI['app'], 1));
|
||||
}
|
||||
|
||||
public function testLoadLatestItemsNoPublic()
|
||||
{
|
||||
$feed = $this->createFeed();
|
||||
$entry = $this->createEntry($feed);
|
||||
|
||||
foreach(range(1, 2) as $i) {
|
||||
$this->addItem($entry, self::$DI['record_'.$i]);
|
||||
}
|
||||
|
||||
$this->assertCount(0, self::$DI['app']['EM']->getRepository('Entities\FeedItem')->loadLatest(self::$DI['app'], 20));
|
||||
}
|
||||
|
||||
public function testDatafilesRouteNotAuthenticatedIsOkInPublicFeed()
|
||||
public function testDatafilesRouteOnUnaccessibleRecordIsOkInPublicFeed()
|
||||
{
|
||||
$tmp = tempnam(sys_get_temp_dir(), 'testEtag');
|
||||
copy(__DIR__ . '/../../../../files/cestlafete.jpg', $tmp);
|
||||
@@ -121,20 +70,12 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
|
||||
|
||||
$file = new File(self::$DI['app'], $media, self::$DI['collection_no_access']);
|
||||
$record = \record_adapter::createFromFile($file, self::$DI['app']);
|
||||
|
||||
$record->generate_subdefs($record->get_databox(), self::$DI['app']);
|
||||
|
||||
$feed = $this->createFeed();
|
||||
$this->setFeedIsPublic($feed, true);
|
||||
$entry = $this->createEntry($feed);
|
||||
$this->addItem($entry, $record);
|
||||
|
||||
self::$DI['record_1']->move_to_collection(self::$DI['collection_no_access'], self::$DI['app']['phraseanet.appbox']);
|
||||
$item = $this->insertOneFeedItem(self::$DI['user'], true, 1, $record);
|
||||
|
||||
self::$DI['client']->request('GET', '/datafiles/' . $record->get_sbas_id() . '/' . $record->get_record_id() . '/preview/');
|
||||
|
||||
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
|
||||
self::$DI['record_1']->move_to_collection(self::$DI['collection'], self::$DI['app']['phraseanet.appbox']);
|
||||
|
||||
unlink($tmp);
|
||||
}
|
||||
@@ -269,13 +210,10 @@ class ApplicationOverviewTest extends \PhraseanetWebTestCaseAuthenticatedAbstrac
|
||||
|
||||
public function testPermalinkRouteNotAuthenticatedIsOkInPublicFeed()
|
||||
{
|
||||
$feed = $this->createFeed();
|
||||
$this->setFeedIsPublic($feed, true);
|
||||
$entry = $this->createEntry($feed);
|
||||
$this->addItem($entry, self::$DI['record_1']);
|
||||
$record = $this->insertOneFeedItem(self::$DI['user'], true)->getRecord(self::$DI['app']);
|
||||
|
||||
self::$DI['app']['authentication']->closeAccount();
|
||||
self::$DI['client']->request('GET', '/permalink/v1/' . self::$DI['record_1']->get_sbas_id() . '/' . self::$DI['record_1']->get_record_id() . '/preview/');
|
||||
self::$DI['client']->request('GET', '/permalink/v1/' . $record->get_sbas_id() . '/' . $record->get_record_id() . '/preview/');
|
||||
|
||||
$this->assertEquals(200, self::$DI['client']->getResponse()->getStatusCode());
|
||||
}
|
||||
|
@@ -24,7 +24,6 @@ class FeedTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$feed = $this->insertOneFeed(self::$DI['user']);
|
||||
|
||||
$crawler = self::$DI['client']->request('POST', '/prod/feeds/requestavailable/');
|
||||
// print(self::$DI['client']->getResponse());exit;
|
||||
$this->assertTrue(self::$DI['client']->getResponse()->isOk());
|
||||
$feeds = self::$DI['app']['EM']->getRepository('Entities\Feed')->getAllForUser(self::$DI['user']);
|
||||
foreach ($feeds as $one_feed) {
|
||||
|
@@ -363,10 +363,10 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
*
|
||||
* @return \Entities\FeedEntry
|
||||
*/
|
||||
protected function insertOneFeedEntry(\User_Adapter $user)
|
||||
protected function insertOneFeedEntry(\User_Adapter $user, $public = false)
|
||||
{
|
||||
try {
|
||||
$feed = $this->insertOneFeed($user);
|
||||
$feed = $this->insertOneFeed($user, '', $public);
|
||||
|
||||
$em = self::$DI['app']['EM'];
|
||||
|
||||
@@ -436,22 +436,31 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
*
|
||||
* @return \Entities\FeedItem
|
||||
*/
|
||||
protected function insertOneFeedItem(\User_Adapter $user)
|
||||
protected function insertOneFeedItem(\User_Adapter $user, $public = false, $qty = 1, \record_adapter $record = null)
|
||||
{
|
||||
try {
|
||||
$entry = $this->insertOneFeedEntry($user);
|
||||
$em = self::$DI['app']['EM'];
|
||||
$entry = $this->insertOneFeedEntry($user, $public);
|
||||
|
||||
for ($i = 0; $i < $qty; $i++) {
|
||||
$item = new \Entities\FeedItem();
|
||||
$item->setEntry($entry);
|
||||
$item->setRecordId(self::$DI['record_1']->get_record_id());
|
||||
$item->setSbasId(self::$DI['record_1']->get_sbas_id());
|
||||
|
||||
if (null === $record) {
|
||||
$actual = self::$DI['record_'.($i+1)];
|
||||
} else {
|
||||
$actual = $record;
|
||||
}
|
||||
|
||||
$item->setRecordId($actual->get_record_id());
|
||||
$item->setSbasId($actual->get_sbas_id());
|
||||
$item->setEntry($entry);
|
||||
|
||||
$entry->addItem($item);
|
||||
|
||||
$em = self::$DI['app']['EM'];
|
||||
$em->persist($item);
|
||||
}
|
||||
|
||||
$em->persist($entry);
|
||||
$em->persist($item);
|
||||
|
||||
$em->flush();
|
||||
} catch (\Exception $e) {
|
||||
@@ -1144,70 +1153,6 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
protected function createFeed()
|
||||
{
|
||||
$feed = new Feed();
|
||||
$feed->setTitle('Feed')
|
||||
->setSubtitle('subtitle');
|
||||
|
||||
self::$DI['app']['EM']->persist($feed);
|
||||
self::$DI['app']['EM']->flush();
|
||||
|
||||
return $feed;
|
||||
}
|
||||
|
||||
protected function createEntry(Feed $feed)
|
||||
{
|
||||
$publisher = new FeedPublisher();
|
||||
$publisher->setFeed($feed)
|
||||
->setIsOwner(true)
|
||||
->setUsrId(self::$DI['user']->get_id());
|
||||
|
||||
$feed->addPublisher($publisher);
|
||||
|
||||
$entry = new FeedEntry();
|
||||
$entry->setTitle('entry')
|
||||
->setSubtitle('subtitle')
|
||||
->setAuthorEmail('email')
|
||||
->setAuthorName('name')
|
||||
->setFeed($feed)
|
||||
->setPublisher($publisher);
|
||||
|
||||
$feed->addEntry($entry);
|
||||
|
||||
self::$DI['app']['EM']->persist($publisher);
|
||||
self::$DI['app']['EM']->persist($feed);
|
||||
self::$DI['app']['EM']->persist($entry);
|
||||
self::$DI['app']['EM']->flush();
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
protected function addItem(FeedEntry $entry, \record_adapter $record)
|
||||
{
|
||||
$item = new FeedItem();
|
||||
$item->setEntry($entry)
|
||||
->setRecordId($record->get_record_id())
|
||||
->setSbasId($record->get_sbas_id());
|
||||
|
||||
$entry->addItem($item);
|
||||
|
||||
self::$DI['app']['EM']->persist($item);
|
||||
self::$DI['app']['EM']->persist($entry);
|
||||
self::$DI['app']['EM']->flush();
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
protected function setFeedIsPublic(Feed $feed, $public)
|
||||
{
|
||||
$feed->setIsPublic($public);
|
||||
self::$DI['app']['EM']->persist($feed);
|
||||
self::$DI['app']['EM']->flush();
|
||||
|
||||
return $feed;
|
||||
}
|
||||
}
|
||||
|
||||
class CsrfTestProvider implements CsrfProviderInterface
|
||||
|
Reference in New Issue
Block a user