summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-12-09 16:04:08 -0800
committerTim Almdal <tnalmdal@shaw.ca>2009-12-09 16:04:08 -0800
commitd521faf63d6fcca13445a3bd89387b3a6dc591d4 (patch)
tree4401496b9deea6155d847a4d920b981abf1d46fb
parentdfc556e8a6e2c0636a93d87bc0cdb0f85f588fd4 (diff)
Add the REST delete processing for albums/photos/movies
-rw-r--r--modules/gallery/helpers/gallery_rest.php34
-rw-r--r--modules/gallery/tests/Gallery_Rest_Helper_Test.php22
2 files changed, 56 insertions, 0 deletions
diff --git a/modules/gallery/helpers/gallery_rest.php b/modules/gallery/helpers/gallery_rest.php
index 82d1bb5b..8b209bae 100644
--- a/modules/gallery/helpers/gallery_rest.php
+++ b/modules/gallery/helpers/gallery_rest.php
@@ -97,6 +97,40 @@ class gallery_rest_Core {
return rest::success();
}
+ static function delete($request) {
+ if (empty($request->path)) {
+ return rest::invalid_request();
+ }
+
+ $item = ORM::factory("item")
+ ->where("relative_url_cache", $request->path)
+ ->viewable()
+ ->find();
+
+ if (!$item->loaded) {
+ return rest::success();
+ }
+
+ if (!access::can("edit", $item)) {
+ return rest::not_found("Resource: {$request->path} permission denied.");
+ }
+
+ if ($item->id == 1) {
+ return rest::invalid_request("Attempt to delete the root album");
+ }
+
+ $item->delete();
+
+ if ($item->is_album()) {
+ $msg = t("Deleted album <b>%title</b>", array("title" => html::purify($item->title)));
+ } else {
+ $msg = t("Deleted photo <b>%title</b>", array("title" => html::purify($item->title)));
+ }
+ log::success("content", $msg);
+
+ return rest::success();
+ }
+
private static function _get_children($item, $request) {
$children = array();
$limit = empty($request->limit) ? null : $request->limit;
diff --git a/modules/gallery/tests/Gallery_Rest_Helper_Test.php b/modules/gallery/tests/Gallery_Rest_Helper_Test.php
index 9c960409..dae55952 100644
--- a/modules/gallery/tests/Gallery_Rest_Helper_Test.php
+++ b/modules/gallery/tests/Gallery_Rest_Helper_Test.php
@@ -181,4 +181,26 @@ class Gallery_Rest_Helper_Test extends Unit_Test_Case {
$this->assert_equal("Updated Title", $this->_photo->title);
$this->assert_equal("new name", $this->_photo->name);
}
+
+ public function gallery_rest_delete_album_test() {
+ access::allow(identity::registered_users(), "edit", $this->_album);
+
+ identity::set_active_user($this->_user);
+ $request = (object)array("path" => $this->_child->relative_url());
+
+ $this->assert_equal(json_encode(array("status" => "OK")), gallery_rest::delete($request));
+ $this->_child->reload();
+ $this->assert_false($this->_child->loaded);
+ }
+
+ public function gallery_rest_delete_photo_test() {
+ access::allow(identity::registered_users(), "edit", $this->_album);
+
+ identity::set_active_user($this->_user);
+ $request = (object)array("path" => $this->_sibling->relative_url());
+
+ $this->assert_equal(json_encode(array("status" => "OK")), gallery_rest::delete($request));
+ $this->_sibling->reload();
+ $this->assert_false($this->_sibling->loaded);
+ }
}