mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Add ebaility to change the feed for a feed entry
This commit is contained in:
@@ -123,6 +123,22 @@ class Feed implements ControllerProviderInterface
|
||||
->set_author_name($author_name)
|
||||
->set_title($title)
|
||||
->set_subtitle($subtitle);
|
||||
|
||||
$current_feed_id = $entry->get_feed()->get_id();
|
||||
$new_feed_id = $request->get('feed_id',$current_feed_id);
|
||||
if($current_feed_id != $new_feed_id) {
|
||||
try {
|
||||
$new_feed = \Feed_Adapter::load_with_user($appbox, $user, $new_feed_id);
|
||||
} catch(\Exception_NotFound $e) {
|
||||
throw new \Exception_Forbidden('You have no access to this feed');
|
||||
}
|
||||
|
||||
if ( ! $new_feed->is_publisher($user)) {
|
||||
throw new \Exception_Forbidden('You are not publisher of this feed');
|
||||
}
|
||||
|
||||
$entry->set_feed($new_feed);
|
||||
}
|
||||
|
||||
$items = explode(';', $request->get('sorted_lst'));
|
||||
|
||||
@@ -144,6 +160,12 @@ class Feed implements ControllerProviderInterface
|
||||
} catch (\Exception_Feed_EntryNotFound $e) {
|
||||
$appbox->get_connection()->rollBack();
|
||||
$datas['message'] = _('Feed entry not found');
|
||||
} catch (\Exception_NotFound $e) {
|
||||
$appbox->get_connection()->rollBack();
|
||||
$datas['message'] = _('Feed not found');
|
||||
} catch (\Exception_Forbidden $e) {
|
||||
$appbox->get_connection()->rollBack();
|
||||
$datas['message'] = _('You are not authorized to access this feed');
|
||||
} catch (\Exception $e) {
|
||||
$appbox->get_connection()->rollBack();
|
||||
$datas['message'] = $e->getMessage();
|
||||
|
@@ -95,10 +95,10 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__ . '/../../../../../lib/Alchemy/Phrasea/Application/Prod.php';
|
||||
|
||||
|
||||
$app['debug'] = true;
|
||||
unset($app['exception_handler']);
|
||||
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
@@ -195,11 +195,10 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
$crawler = $this->client->request('GET', '/feeds/entry/' . $entry->get_id() . '/edit/');
|
||||
$this->fail('Should raise an exception');
|
||||
} catch(Exception_UnauthorizedAction $e) {
|
||||
} catch (Exception_UnauthorizedAction $e) {
|
||||
|
||||
}
|
||||
|
||||
@@ -211,12 +210,11 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$params = array(
|
||||
"feed_id" => $this->feed->get_id()
|
||||
, "title" => "dog"
|
||||
, "subtitle" => "cat"
|
||||
, "author_name" => "bird"
|
||||
, "author_email" => "mouse"
|
||||
, 'lst' => static::$records['record_1']->get_serialize_key()
|
||||
"title" => "dog",
|
||||
"subtitle" => "cat",
|
||||
"author_name" => "bird",
|
||||
"author_email" => "mouse",
|
||||
'lst' => static::$records['record_1']->get_serialize_key(),
|
||||
);
|
||||
|
||||
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
|
||||
@@ -230,6 +228,88 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
$this->assertRegExp("/entry_" . $this->entry->get_id() . "/", $pageContent->datas);
|
||||
}
|
||||
|
||||
public function testEntryUpdateChangeFeed()
|
||||
{
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$newfeed = Feed_Adapter::create(
|
||||
$appbox, self::$user, $this->feed_title, $this->feed_subtitle
|
||||
);
|
||||
|
||||
$params = array(
|
||||
"feed_id" => $newfeed->get_id(),
|
||||
"title" => "dog",
|
||||
"subtitle" => "cat",
|
||||
"author_name" => "bird",
|
||||
"author_email" => "mouse",
|
||||
'lst' => static::$records['record_1']->get_serialize_key(),
|
||||
);
|
||||
|
||||
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
|
||||
$pageContent = json_decode($this->client->getResponse()->getContent());
|
||||
$this->assertTrue(is_object($pageContent));
|
||||
$this->assertFalse($pageContent->error);
|
||||
$this->assertTrue(is_string($pageContent->message));
|
||||
$this->assertTrue(is_string($pageContent->datas));
|
||||
$this->assertRegExp("/entry_" . $this->entry->get_id() . "/", $pageContent->datas);
|
||||
|
||||
$retrievedentry = Feed_Entry_Adapter::load_from_id($appbox, $this->entry->get_id());
|
||||
$this->assertEquals($newfeed->get_id(), $retrievedentry->get_feed()->get_id());
|
||||
|
||||
$newfeed->delete();
|
||||
}
|
||||
|
||||
public function testEntryUpdateChangeFeedNoAccess()
|
||||
{
|
||||
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||
$newfeed = Feed_Adapter::create(
|
||||
$appbox, self::$user, $this->feed_title, $this->feed_subtitle
|
||||
);
|
||||
$newfeed->set_collection(self::$collection_no_access);
|
||||
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
|
||||
$params = array(
|
||||
"feed_id" => $newfeed->get_id(),
|
||||
"title" => "dog",
|
||||
"subtitle" => "cat",
|
||||
"author_name" => "bird",
|
||||
"author_email" => "mouse",
|
||||
'lst' => static::$records['record_1']->get_serialize_key(),
|
||||
);
|
||||
|
||||
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
|
||||
$pageContent = json_decode($this->client->getResponse()->getContent());
|
||||
$this->assertTrue(is_object($pageContent));
|
||||
$this->assertTrue($pageContent->error);
|
||||
$this->assertTrue(is_string($pageContent->message));
|
||||
|
||||
$newfeed->delete();
|
||||
}
|
||||
|
||||
public function testEntryUpdateChangeFeedInvalidFeed()
|
||||
{
|
||||
$params = array(
|
||||
"feed_id" => 0,
|
||||
"title" => "dog",
|
||||
"subtitle" => "cat",
|
||||
"author_name" => "bird",
|
||||
"author_email" => "mouse",
|
||||
'lst' => static::$records['record_1']->get_serialize_key(),
|
||||
);
|
||||
|
||||
$crawler = $this->client->request('POST', '/feeds/entry/' . $this->entry->get_id() . '/update/', $params);
|
||||
$this->assertTrue($this->client->getResponse()->isOk());
|
||||
$this->assertEquals("application/json", $this->client->getResponse()->headers->get("content-type"));
|
||||
$pageContent = json_decode($this->client->getResponse()->getContent());
|
||||
$this->assertTrue(is_object($pageContent));
|
||||
$this->assertTrue($pageContent->error);
|
||||
$this->assertTrue(is_string($pageContent->message));
|
||||
}
|
||||
|
||||
public function testEntryUpdateNotFound()
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
@@ -336,7 +416,7 @@ class ControllerFeedApp extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
||||
Feed_Entry_Adapter::load_from_id($appbox, $this->entry->get_id());
|
||||
$this->fail("Failed to delete entry");
|
||||
} catch (Exception $e) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user