From 98fce83de5f772482382bfabdbcd94c25ecdbb1a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 7 Jun 2010 22:23:46 -0700 Subject: Add a "convert_ids" parameter to Item_Model::as_restful_array(), which we can turn on with a query parameter. --- modules/gallery/models/item.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 409ed3cc..dfcbdd70 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -924,17 +924,21 @@ class Item_Model extends ORM_MPTT { /** * Same as ORM::as_array() but convert id fields into their RESTful form. */ - public function as_restful_array() { + public function as_restful_array($convert_ids=true) { // Convert item ids to rest URLs for consistency $data = $this->as_array(); - if ($tmp = $this->parent()) { - $data["parent"] = rest::url("item", $tmp); - } - unset($data["parent_id"]); - if ($tmp = $this->album_cover()) { - $data["album_cover"] = rest::url("item", $tmp); + + if ($convert_ids) { + if ($tmp = $this->parent()) { + $data["parent"] = rest::url("item", $tmp); + } + unset($data["parent_id"]); + + if ($tmp = $this->album_cover()) { + $data["album_cover"] = rest::url("item", $tmp); + } + unset($data["album_cover_item_id"]); } - unset($data["album_cover_item_id"]); if (access::can("view_full", $this) && $this->is_photo()) { $data["file_url"] = $this->file_url(true); -- cgit v1.2.3 From 6425d41eddd44091b2d83ba3c3734cc6990ca581 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 7 Jun 2010 23:12:52 -0700 Subject: Add a "preserve_ids" global query parameter for REST requests that indicates that we shouldn't opportunistically convert ids into REST urls. --- modules/gallery/helpers/item_rest.php | 3 +- modules/gallery/helpers/items_rest.php | 14 ++++++---- modules/gallery/models/item.php | 7 +++-- modules/gallery/tests/Item_Model_Test.php | 4 +-- modules/gallery/tests/Item_Rest_Helper_Test.php | 21 ++++++++++---- modules/gallery/tests/Items_Rest_Helper_Test.php | 35 ++++++++++++++++-------- 6 files changed, 57 insertions(+), 27 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index c88f92d9..1d19d9f1 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -78,9 +78,10 @@ class item_rest_Core { } $orm->order_by($order_by); + $preserve_ids = isset($p->preserve_ids) ? (bool)$p->preserve_ids : false; $result = array( "url" => $request->url, - "entity" => $item->as_restful_array(), + "entity" => $item->as_restful_array($preserve_ids), "relationships" => rest::relationships("item", $item)); if ($item->is_album()) { $result["members"] = array(); diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index 9cca9a54..e9773745 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -36,6 +36,8 @@ class items_rest_Core { */ static function get($request) { $items = array(); + $preserve_ids = isset($request->params->preserve_ids) ? + (bool)$request->params->preserve_ids : false; if (isset($request->params->urls)) { foreach (json_decode($request->params->urls) as $url) { if (isset($request->params->type)) { @@ -45,10 +47,10 @@ class items_rest_Core { if (access::can("view", $item)) { if (isset($types)) { if (in_array($item->type, $types)) { - $items[] = items_rest::_format_restful_item($item); + $items[] = items_rest::_format_restful_item($item, $preserve_ids); } } else { - $items[] = items_rest::_format_restful_item($item); + $items[] = items_rest::_format_restful_item($item, $preserve_ids); } } } @@ -57,9 +59,9 @@ class items_rest_Core { if (!access::can("view", $item)) { throw new Kohana_404_Exception(); } - $items[] = items_rest::_format_restful_item($item); + $items[] = items_rest::_format_restful_item($item, $preserve_ids); while (($item = $item->parent()) != null) { - array_unshift($items, items_rest::_format_restful_item($item)); + array_unshift($items, items_rest::_format_restful_item($item, $preserve_ids)); }; } @@ -74,9 +76,9 @@ class items_rest_Core { return $item; } - private static function _format_restful_item($item) { + private static function _format_restful_item($item, $preserve_ids) { $item_rest = array("url" => rest::url("item", $item), - "entity" => $item->as_restful_array(), + "entity" => $item->as_restful_array($preserve_ids), "relationships" => rest::relationships("item", $item)); if ($item->type == "album") { $members = array(); diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index dfcbdd70..f59caa65 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -923,12 +923,15 @@ class Item_Model extends ORM_MPTT { /** * Same as ORM::as_array() but convert id fields into their RESTful form. + * Convert any item ids into REST urls + * + * @param bool preserve_ids true if we should preserve ids */ - public function as_restful_array($convert_ids=true) { + public function as_restful_array($preserve_ids) { // Convert item ids to rest URLs for consistency $data = $this->as_array(); - if ($convert_ids) { + if (!$preserve_ids) { if ($tmp = $this->parent()) { $data["parent"] = rest::url("item", $tmp); } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 9d3f54f2..6c5882c4 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -357,7 +357,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(); + $result = $album->as_restful_array(false); $this->assert_same(rest::url("item", item::root()), $result["parent"]); $this->assert_same(rest::url("item", $photo), $result["album_cover"]); $this->assert_true(!array_key_exists("parent_id", $result)); @@ -369,7 +369,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(false); + $result = $album->as_restful_array(true); $this->assert_same(item::root()->id, $result["parent_id"]); $this->assert_same($photo->id, $result["album_cover_item_id"]); $this->assert_true(!array_key_exists("parent", $result)); diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 0b5e0471..5a80d66b 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -28,6 +28,17 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal($album->id, $resolved->id); } + public function get_with_ids_test() { + $photo1 = test::random_photo(item::root()); + $request = new stdClass(); + $request->url = rest::url("item", $photo1); + $request->params = new stdClass(); + $request->params->preserve_ids = 1; + + $response = item_rest::get($request); + $this->assert_equal(item::root()->id, $response["entity"]["parent_id"]); // Spot check + } + public function get_scope_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); @@ -41,7 +52,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params = new stdClass(); $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -56,7 +67,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "direct"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -71,7 +82,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "all"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -98,7 +109,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->name = "foo"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -121,7 +132,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->type = "album"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php index 94bf912a..3efd677d 100644 --- a/modules/gallery/tests/Items_Rest_Helper_Test.php +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -34,13 +34,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(), + "entity" => $photo1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -67,7 +67,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -94,7 +94,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(), + "entity" => $photo1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), @@ -119,13 +119,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(), + "entity" => $photo1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -146,7 +146,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $root = ORM::factory("item", 1); $restful_root = array( "url" => rest::url("item", $root), - "entity" => $root->as_restful_array(), + "entity" => $root->as_restful_array(false), "relationships" => rest::relationships("item", $root)); $restful_root["members"] = array(); foreach ($root->children() as $child) { @@ -155,12 +155,12 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->params = new stdClass(); - $request->params->ancestor_for = rest::url("item", $photo2); + $request->params->ancestors_for = rest::url("item", $photo2); $this->assert_equal_array( array( $restful_root, array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -170,7 +170,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { rest::url("item", $album2)), ), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -178,11 +178,24 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { "members" => array( rest::url("item", $photo2))), array("url" => rest::url("item", $photo2), - "entity" => $photo2->as_restful_array(), + "entity" => $photo2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo2), "members" => array())))), items_rest::get($request)); } + + public function get_ancestor_with_ids_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->ancestors_for = rest::url("item", $photo1); + $request->params->preserve_ids = 1; + + $response = items_rest::get($request); + $this->assert_same(item::root()->id, $response[1]["entity"]["parent_id"]); // Spot check + } } -- cgit v1.2.3 From b40057283e1dfbb3bbb41a6dfc8ccc8e2111d810 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 8 Jun 2010 20:59:24 -0700 Subject: Add a "can_edit" field to the Item_Model's REST output. It's applicable to the current user. --- modules/gallery/models/item.php | 1 + modules/gallery/tests/Item_Model_Test.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index f59caa65..a0866934 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -951,6 +951,7 @@ class Item_Model extends ORM_MPTT { $data["resize_url"] = $tmp; } $data["thumb_url"] = $this->thumb_url(true); + $data["can_edit"] = access::can("edit", $this); // Elide some internal-only data that is going to cause confusion in the client. foreach (array("relative_path_cache", "relative_url_cache", "left_ptr", "right_ptr", diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 6c5882c4..3df6197d 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Item_Model_Test extends Gallery_Unit_Test_Case { + public function teardown() { + identity::set_active_user(identity::admin_user()); + } + public function saving_sets_created_and_updated_dates_test() { $item = test::random_photo(); $this->assert_true(!empty($item->created)); @@ -376,6 +380,15 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $this->assert_true(!array_key_exists("album_cover_item", $result)); } + public function as_restful_array_with_edit_bit_test() { + $response = item::root()->as_restful_array(true); + $this->assert_true($response["can_edit"]); + + identity::set_active_user(identity::guest()); + $response = item::root()->as_restful_array(true); + $this->assert_false($response["can_edit"]); + } + public function first_photo_becomes_album_cover() { $album = test::random_album(); $photo = test::random_photo($album); -- cgit v1.2.3 From 3dacafb7182dd915c4c6d4e7d75722976e231465 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 9 Jun 2010 20:49:32 -0700 Subject: Revert the "preserve_ids" global query parameter. We decided that it was a bad idea. This reverts commit 6425d41eddd44091b2d83ba3c3734cc6990ca581. --- modules/gallery/helpers/item_rest.php | 3 +- modules/gallery/helpers/items_rest.php | 14 ++++------ modules/gallery/models/item.php | 7 ++--- modules/gallery/tests/Item_Model_Test.php | 4 +-- modules/gallery/tests/Item_Rest_Helper_Test.php | 21 ++++---------- modules/gallery/tests/Items_Rest_Helper_Test.php | 35 ++++++++---------------- 6 files changed, 27 insertions(+), 57 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 1d19d9f1..c88f92d9 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -78,10 +78,9 @@ class item_rest_Core { } $orm->order_by($order_by); - $preserve_ids = isset($p->preserve_ids) ? (bool)$p->preserve_ids : false; $result = array( "url" => $request->url, - "entity" => $item->as_restful_array($preserve_ids), + "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item)); if ($item->is_album()) { $result["members"] = array(); diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index e9773745..9cca9a54 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -36,8 +36,6 @@ class items_rest_Core { */ static function get($request) { $items = array(); - $preserve_ids = isset($request->params->preserve_ids) ? - (bool)$request->params->preserve_ids : false; if (isset($request->params->urls)) { foreach (json_decode($request->params->urls) as $url) { if (isset($request->params->type)) { @@ -47,10 +45,10 @@ class items_rest_Core { if (access::can("view", $item)) { if (isset($types)) { if (in_array($item->type, $types)) { - $items[] = items_rest::_format_restful_item($item, $preserve_ids); + $items[] = items_rest::_format_restful_item($item); } } else { - $items[] = items_rest::_format_restful_item($item, $preserve_ids); + $items[] = items_rest::_format_restful_item($item); } } } @@ -59,9 +57,9 @@ class items_rest_Core { if (!access::can("view", $item)) { throw new Kohana_404_Exception(); } - $items[] = items_rest::_format_restful_item($item, $preserve_ids); + $items[] = items_rest::_format_restful_item($item); while (($item = $item->parent()) != null) { - array_unshift($items, items_rest::_format_restful_item($item, $preserve_ids)); + array_unshift($items, items_rest::_format_restful_item($item)); }; } @@ -76,9 +74,9 @@ class items_rest_Core { return $item; } - private static function _format_restful_item($item, $preserve_ids) { + private static function _format_restful_item($item) { $item_rest = array("url" => rest::url("item", $item), - "entity" => $item->as_restful_array($preserve_ids), + "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item)); if ($item->type == "album") { $members = array(); diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index a0866934..009457c1 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -923,15 +923,12 @@ class Item_Model extends ORM_MPTT { /** * Same as ORM::as_array() but convert id fields into their RESTful form. - * Convert any item ids into REST urls - * - * @param bool preserve_ids true if we should preserve ids */ - public function as_restful_array($preserve_ids) { + public function as_restful_array($convert_ids=true) { // Convert item ids to rest URLs for consistency $data = $this->as_array(); - if (!$preserve_ids) { + if ($convert_ids) { if ($tmp = $this->parent()) { $data["parent"] = rest::url("item", $tmp); } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 3df6197d..f9e6a4e3 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -361,7 +361,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(false); + $result = $album->as_restful_array(); $this->assert_same(rest::url("item", item::root()), $result["parent"]); $this->assert_same(rest::url("item", $photo), $result["album_cover"]); $this->assert_true(!array_key_exists("parent_id", $result)); @@ -373,7 +373,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(true); + $result = $album->as_restful_array(false); $this->assert_same(item::root()->id, $result["parent_id"]); $this->assert_same($photo->id, $result["album_cover_item_id"]); $this->assert_true(!array_key_exists("parent", $result)); diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 5a80d66b..0b5e0471 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -28,17 +28,6 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal($album->id, $resolved->id); } - public function get_with_ids_test() { - $photo1 = test::random_photo(item::root()); - $request = new stdClass(); - $request->url = rest::url("item", $photo1); - $request->params = new stdClass(); - $request->params->preserve_ids = 1; - - $response = item_rest::get($request); - $this->assert_equal(item::root()->id, $response["entity"]["parent_id"]); // Spot check - } - public function get_scope_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); @@ -52,7 +41,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params = new stdClass(); $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -67,7 +56,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "direct"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -82,7 +71,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "all"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -109,7 +98,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->name = "foo"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -132,7 +121,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->type = "album"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php index 3efd677d..94bf912a 100644 --- a/modules/gallery/tests/Items_Rest_Helper_Test.php +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -34,13 +34,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(false), + "entity" => $photo1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(false), + "entity" => $album2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -67,7 +67,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(false), + "entity" => $album2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -94,7 +94,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(false), + "entity" => $photo1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), @@ -119,13 +119,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(false), + "entity" => $photo1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(false), + "entity" => $album2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -146,7 +146,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $root = ORM::factory("item", 1); $restful_root = array( "url" => rest::url("item", $root), - "entity" => $root->as_restful_array(false), + "entity" => $root->as_restful_array(), "relationships" => rest::relationships("item", $root)); $restful_root["members"] = array(); foreach ($root->children() as $child) { @@ -155,12 +155,12 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->params = new stdClass(); - $request->params->ancestors_for = rest::url("item", $photo2); + $request->params->ancestor_for = rest::url("item", $photo2); $this->assert_equal_array( array( $restful_root, array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -170,7 +170,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { rest::url("item", $album2)), ), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(false), + "entity" => $album2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -178,24 +178,11 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { "members" => array( rest::url("item", $photo2))), array("url" => rest::url("item", $photo2), - "entity" => $photo2->as_restful_array(false), + "entity" => $photo2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo2), "members" => array())))), items_rest::get($request)); } - - public function get_ancestor_with_ids_test() { - $album1 = test::random_album(); - $photo1 = test::random_photo($album1); - - $request = new stdClass(); - $request->params = new stdClass(); - $request->params->ancestors_for = rest::url("item", $photo1); - $request->params->preserve_ids = 1; - - $response = items_rest::get($request); - $this->assert_same(item::root()->id, $response[1]["entity"]["parent_id"]); // Spot check - } } -- cgit v1.2.3 From cb01f4017d70a7d73273052b424e8b78b794bc1c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 11 Jun 2010 16:37:45 -0700 Subject: Fix for ticket #1118. The item validation was flagging duplicate slugs as errors. There was already code in the item save to insure that any duplicates were made unique, so this patch removes the validation as unnecessary. --- modules/gallery/models/item.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 009457c1..a4f264bb 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -767,13 +767,6 @@ class Item_Model extends ORM_MPTT { public function valid_slug(Validation $v, $field) { if (preg_match("/[^A-Za-z0-9-_]/", $this->slug)) { $v->add_error("slug", "not_url_safe"); - } else if (db::build() - ->from("items") - ->where("parent_id", "=", $this->parent_id) - ->where("id", "<>", $this->id) - ->where("slug", "=", $this->slug) - ->count_records()) { - $v->add_error("slug", "conflict"); } } -- cgit v1.2.3 From a4586bc0c01fac6e86163fd119aaa64d95fb5e8e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 12 Jun 2010 13:05:40 -0700 Subject: Revert "Fix for ticket #1118. The item validation was flagging duplicate slugs as errors. There was already code in the item save to insure that any" This introduces a bug where you can create two items with the same slug. This reverts commit cb01f4017d70a7d73273052b424e8b78b794bc1c. --- modules/gallery/models/item.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index a4f264bb..009457c1 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -767,6 +767,13 @@ class Item_Model extends ORM_MPTT { public function valid_slug(Validation $v, $field) { if (preg_match("/[^A-Za-z0-9-_]/", $this->slug)) { $v->add_error("slug", "not_url_safe"); + } else if (db::build() + ->from("items") + ->where("parent_id", "=", $this->parent_id) + ->where("id", "<>", $this->id) + ->where("slug", "=", $this->slug) + ->count_records()) { + $v->add_error("slug", "conflict"); } } -- cgit v1.2.3